簡體   English   中英

鏈接以增強gcc中的正則表達式

[英]linking to boost regex in gcc

我正在嘗試編譯我在linux上使用正則表達式的程序。 我通過輸入make -fgcc.mak在libs / regex / build中構建了boost庫,它創建了一個目錄gcc,其中包含以下四個文件

boost_regex-gcc-1_35
boost_regex-gcc-d-1_35
libboost_regex-gcc-1_35.a
libboost_regex-gcc-d-1_35.a

現在我想使用我的程序中的正則表達式,它位於某個任意目錄中。 我#include boost / regex.hpp

我收到的錯誤表明找不到regex.hpp。 然后我在g ++編譯器中給出了-I選項。 我沒有得到那個錯誤。 但是我收到以下錯誤

undefined reference to `boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::construct_init(boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, boost::regex_constants::_match_flags)'

我用谷歌搜索,發現我需要以某種方式將上述4個庫中的一個鏈接到我的程序。 我該怎么做。 我應該鏈接哪一個?為什么?

libboost_regex-gcc-1_35.a添加到鏈接步驟中的目標文件列表中,或者將-static -lboost_regex-gcc-1_35到相同的目標文件中。 還要確保在編譯步驟中有一個指向boost包含目錄的-I開關。 如果庫不在典型的搜索路徑(* nr上的/usr/lib )之外,請將該目錄添加到鏈接命令中,使用-Wl,-L/path/to/boost/libs for g++或者只需-L/path/to/boost/libs ld上的-L/path/to/boost/libs

使用boost文件系統時我也遇到了類似的問題。 這是我需要做的事情才能讓它靜態鏈接。

摘自My Original(有問題)Makefile:LIBS = -static -lboost_filesystem

解決方案:LIBS = -Wl,-Bstatic -lboost_filesystem -lboost_system -Wl,-Bdynamic

您可以從http://code.google.com/p/neptuner/source/browse/codebase/trunk/stratego/uboat/Makefile查看完整的Makefile

需要添加boost_system以使其正確鏈接。 直接添加/指定libboost * .a會產生更多問題。 請注意,-Bdynamic用於防止標准庫的靜態鏈接。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM