您好我正在尝试与 boost 链接以使用线程库,但似乎无法构建它。
我用 HomeBrew(mac 包安装程序)安装了 boost,它在/usr/local/Cellar/boost/1.50.0
目录中。
我的主文件现在很简单......
#include <iostream>
#include <boost/thread.hpp>
我的make文件是这样的:
CC = g++
BASE_FLAGS = -m32 -wAll
# INCLUDE BASE DIRECTORY AND BOOST DIRECTORY FOR HEADERS
LDFLAGS = -I/usr/local/Cellar/boost/1.50.0/include -I/opt/local/include
# INCLUDE BASE DIRECTORY AND BOOST DIRECTORY FOR LIB FILES
LLIBFLAGS = -L/usr/local/Cellar/boost/1.50.0/
# SPECIFIY LINK OPTIONS
LINKFLAGS = -l boost_thread-mt -lboost_system
# FINAL FLAGS -- TO BE USED THROUGHOUT
FLAGS = $(BASE_FLAGS) $(LLIBFLAGS) $(LDFLAGS) $(LINKFLAGS)
# NOTE FOR BOOST -- YOU ONLY NEED TO INCLUDE THE PATH BECAUSE IT ONLY INSTALLS HEADER FILES
main: main.cpp
$(CC) $(FLAGS) -o main.out main.cpp
当我运行它时,我得到了一个找不到 boost_system 的库。如果我取出 boost_system,则会收到如下所示的错误:
ld: warning: ignoring file /usr/local/lib/libboost_thread-mt.dylib, file was built for unsupported file format ( 0xcf 0xfa 0xed 0xfe 0x 7 0x 0 0x 0 0x 1 0x 3 0x 0 0x 0 0x 0 0x 6 0x 0 0x 0 0x 0 ) which is not the architecture being linked (i386): /usr/local/lib/libboost_thread-mt.dylib
Undefined symbols for architecture i386:
"boost::system::system_category()", referenced from:
__static_initialization_and_destruction_0(int, int)in ccKwJWzr.o
"boost::system::generic_category()", referenced from:
__static_initialization_and_destruction_0(int, int)in ccKwJWzr.o
ld: symbol(s) not found for architecture i386
collect2: ld returned 1 exit status
make: *** [main] Error 1