简体   繁体   中英

boost makefile on Mac OS X

I'd like to use boost regex library and created a very short program to test my makefile

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

using namespace std;
using namespace boost;

int main() {

    regex exp("test");

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

Here is my makefile (I've got the boost includes from this thread 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)

When I compile my program a get the following error message:

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

What is missing? I've installed boost with homebrew under Mac OS X 10.8.

You are missing a link to the boost_regex_mt library

-lboost_filesystem-mt -lboost_thread-mt

In your 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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM