在Mac OS X上提升makefile

时间:2013-08-26 18:58:24

标签: c++ macos boost makefile

我想使用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下用自制软件安装了boost。

1 个答案:

答案 0 :(得分:3)

您缺少指向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)