首先,我使用命令构建boost: sudo ./bjam variant = release link = static threading = multi runtime-link = static -j4 install
我将Makefile复制到目录日志示例 /家庭/ fof606 /工作/ boost_1_57_0 /库/日志/示例/琐碎
Makefile的内容是
DEFS = '-DMSG="Hello world!\n"'
INCS =
LIBS = -lboost_log_setup \
-lboost_log \
-lboost_date_time \
-lboost_filesystem \
-lboost_system \
-lboost_thread
CFLAGS = $(DEFS) $(INCS) -O2 -Wall
CXXFLAGS = $(DEFS) $(INCS) -O2 -Wall
LDFLAGS = $(LIBS) -s
CFLAGS_DEBUG = $(DEFS) $(INCS) -g -Wall
CXXFLAGS_DEBUG = $(DEFS) $(INCS) -g -Wall
LDFLAGS_DEBUG = $(LIBS)
SRCS = $(wildcard *.c *.cc *.cpp *.cxx)
EXT = $(firstword $(suffix $(SRCS)))
OBJS = $(SRCS:$(EXT)=.o)
DEPS = $(SRCS:$(EXT)=.d)
BIN = main
PREFIX=/usr/local
ifeq ($(EXT), .c)
LANG = C
else
LANG = CXX
endif
.PHONY: all debug strip install uninstall clean
all: $(BIN)
debug: CFLAGS = $(CFLAGS_DEBUG)
debug: CXXFLAGS = $(CXXFLAGS_DEBUG)
debug: LDFLAGS = $(LDFLAGS_DEBUG)
debug: all
strip: all
strip $(BIN)
$(BIN): $(OBJS)
ifeq ($(LANG), C)
$(CC) $(LDFLAGS) -o $@ $^
else
$(CXX) $(LDFLAGS) -o $@ $^
endif
%.d: %$(EXT)
ifeq ($(LANG), C)
$(CC) -MM -MP -MT $(patsubst %.d,%.o,$@) -MT $@ $< >$@
else
$(CXX) -MM -MP -MT $(patsubst %.d,%.o,$@) -MT $@ $< >$@
endif
install: all
install $(BIN) $(DESTDIR)$(PREFIX)/bin
uninstall:
rm -f $(DESTDIR)$(PREFIX)/bin/$(BIN)
clean:
rm -f $(BIN) *.o *.d
-include $(DEPS)
然后我运行make。链接错误显示(所有错误信息的一部分):
main.cpp:(.text.startup+0x11ff): undefined reference to `boost::log::v2s_mt_posix::aux::stream_provider<char>::allocate_compound(boost::log::v2s_mt_posix::record&)'
main.cpp:(.text.startup+0x1206): undefined reference to `boost::log::v2s_mt_posix::aux::unhandled_exception_count()'
main.cpp:(.text.startup+0x124e): undefined reference to `boost::log::v2s_mt_posix::aux::unhandled_exception_count()'
main.cpp:(.text.startup+0x1294): undefined reference to `boost::log::v2s_mt_posix::core::push_record_move(boost::log::v2s_mt_posix::record&)'
main.cpp:(.text.startup+0x129c): undefined reference to `boost::log::v2s_mt_posix::aux::stream_provider<char>::release_compound(boost::log::v2s_mt_posix::aux::stream_provider<char>::stream_compound*)'
main.cpp:(.text.startup+0x12ca): undefined reference to `boost::log::v2s_mt_posix::trivial::logger::get()'
main.cpp:(.text.startup+0x130f): undefined reference to `boost::log::v2s_mt_posix::trivial::logger::get()'
main.cpp:(.text.startup+0x131f): undefined reference to `boost::log::v2s_mt_posix::aux::stream_provider<char>::allocate_compound(boost::log::v2s_mt_posix::record&)'
main.cpp:(.text.startup+0x1326): undefined reference to `boost::log::v2s_mt_posix::aux::unhandled_exception_count()'
main.cpp:(.text.startup+0x136e): undefined reference to `boost::log::v2s_mt_posix::aux::unhandled_exception_count()'
main.cpp:(.text.startup+0x13b4): undefined reference to `boost::log::v2s_mt_posix::core::push_record_move(boost::log::v2s_mt_posix::record&)'
main.cpp:(.text.startup+0x13bc): undefined reference to `boost::log::v2s_mt_posix::aux::stream_provider<char>::release_compound(boost::log::v2s_mt_posix::aux::stream_provider<char>::stream_compound*)'
main.cpp:(.text.startup+0x13ea): undefined reference to `boost::log::v2s_mt_posix::trivial::logger::get()'
main.cpp:(.text.startup+0x142f): undefined reference to `boost::log::v2s_mt_posix::trivial::logger::get()'
main.cpp:(.text.startup+0x143f): undefined reference to `boost::log::v2s_mt_posix::aux::stream_provider<char>::allocate_compound(boost::log::v2s_mt_posix::record&)'
main.cpp:(.text.startup+0x1446): undefined reference to `boost::log::v2s_mt_posix::aux::unhandled_exception_count()'
main.cpp:(.text.startup+0x148e): undefined reference to `boost::log::v2s_mt_posix::aux::unhandled_exception_count()'
main.cpp:(.text.startup+0x14d4): undefined reference to `boost::log::v2s_mt_posix::core::push_record_move(boost::log::v2s_mt_posix::record&)'
main.cpp:(.text.startup+0x14dc): undefined reference to `boost::log::v2s_mt_posix::aux::stream_provider<char>::release_compound(boost::log::v2s_mt_posix::aux::stream_provider<char>::stream_compound*)'
main.cpp:(.text.startup+0x1dae): undefined reference to `boost::log::v2s_mt_posix::aux::stream_provider<char>::release_compound(boost::log::v2s_mt_posix::aux::stream_provider<char>::stream_compound*)'
main.cpp:(.text.startup+0x1de5): undefined reference to `boost::log::v2s_mt_posix::aux::stream_provider<char>::release_compound(boost::log::v2s_mt_posix::aux::stream_provider<char>::stream_compound*)'
main.cpp:(.text.startup+0x1e5a): undefined reference to `boost::log::v2s_mt_posix::aux::stream_provider<char>::release_compound(boost::log::v2s_mt_posix::aux::stream_provider<char>::stream_compound*)'
main.cpp:(.text.startup+0x1ec5): undefined reference to `boost::log::v2s_mt_posix::aux::stream_provider<char>::release_compound(boost::log::v2s_mt_posix::aux::stream_provider<char>::stream_compound*)'
main.o:main.cpp:(.text.startup+0x1f0d): more undefined references to `boost::log::v2s_mt_posix::aux::stream_provider<char>::release_compound(boost::log::v2s_mt_posix::aux::stream_provider<char>::stream_compound*)' follow
非常感谢!
答案 0 :(得分:0)
检查/usr/local/lib
中构建库的名称,因为boost构建框架adds name suffixes用于不同的构建配置。您必须相应地更新makefile(-lboost_log
和其他)中的库引用。