【问题标题】:boost makefile on Mac OS X在 Mac OS X 上提升 makefile
【发布时间】:2013-08-26 18:58:23
【问题描述】:

我想使用 boost regex 库并创建了一个非常短的程序来测试我的 makefile

#include <iostream>
#include <boost/regex.hpp>

using namespace std;
using namespace boost;

int main() {

    regex exp("test");

    cout << "Hello World" << endl;
}

这是我的 makefile(我已经从这个线程 Including boost libraries in make files 得到了提升)

EXEC = main
SOURCES = $(wildcard *.cpp)
HEADERS = $(wildcard *.h*)
OBJECTS = $(SOURCES:.cpp=.o)

all: $(EXEC)

main: $(OBJECTS)
    g++ -L/usr/local/Cellar/boost/1.54.0/lib -lboost_filesystem-mt -lboost_thread-mt $(OBJECTS) -o $(EXEC)

%.o: %.cpp $(HEADERS)
    g++ -I/usr/local/Cellar/boost/1.54.0/include -c $< -o $@

clean:
    rm -f $(EXEC) $(OBJECTS)

当我编译我的程序时,会收到以下错误消息:

g++ -I/usr/local/Cellar/boost/1.54.0/include -c main.cpp -o main.o
g++ -L/usr/local/Cellar/boost/1.54.0/lib -lboost_filesystem-mt -lboost_thread-mt main.o -o main
Undefined symbols for architecture x86_64:
  "boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::do_assign(char const*, char const*, unsigned int)", referenced from:
      boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::assign(char const*, char const*, unsigned int)in main.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make: *** [main] Error 1

缺少什么? 我已经在 Mac OS X 10.8 下使用 homebrew 安装了 boost。

【问题讨论】:

标签: c++ macos boost makefile


【解决方案1】:

您缺少指向 boost_regex_mt 库的链接

-lboost_filesystem-mt -lboost_thread-mt

在你的makefile中...

main: $(OBJECTS)
    g++ -L/usr/local/Cellar/boost/1.54.0/lib -lboost_regex-mt -lboost_filesystem-mt -lboost_thread-mt     $(OBJECTS) -o $(EXEC)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-09-14
    • 2012-10-19
    • 1970-01-01
    • 2012-09-23
    • 2012-01-07
    • 1970-01-01
    • 2015-04-02
    • 1970-01-01
    相关资源
    最近更新 更多