我首先要说明我今晚感觉自己像个白痴。我试图通过Boost Serialization最低限度地重现我在RHEL5.6,gcc 4.1.2,boost 1.44.0下的工作问题。
我遇到此问题的环境是Ubuntu Server(安装了dev软件包),gcc 4.7.2,以及boost 1.44.0的构建(针对系统编译器,软件包,等)。
我的代码编写得很干净,但我收到了与各种boost::archive
类型相关的无数未定义符号。在我的make上运行strace,我看到它拿起了预期的boost_serialization库:
668 43569 stat("/usr/local/boost/1.44.0/lib/libboost_serialization.so", {st_mode=S_IFREG|0755, st_size=700481, ...}) = 0
669 43569 open("/usr/local/boost/1.44.0/lib/libboost_serialization.so", O_RDONLY) = 8
我的makefile是:
default: test-app
all: test-app
BOOST := /usr/local/boost/1.44.0
CPPFLAGS := -fPIC -Wall -Wextra -Werror
INCDIRS := -isystem$(BOOST)/include
.LIBDIRS. := $(BOOST)/lib
.LIBS. :=boost_serialization
LIBS := $(foreach lib,$(.LIBS.),-l$(lib))
LIBDIRS := $(foreach dir,$(.LIBDIRS.),-L$(dir))
CPPFLAGS += $(INCDIRS)
base.o : base.cpp base.hpp
g++ $(CPPFLAGS) --compile $< -o $@ -g
derived.o : derived.cpp base.hpp derived.hpp
g++ $(CPPFLAGS) --compile $< -o $@ -g
main.o: main.cpp derived.hpp
g++ $(CPPFLAGS) --compile $< -o $@ -g
test-app: main.o derived.o base.o
g++ -o $@ $(LIBDIRS) $(LIBS) $^
clean:
rm -f *.o test
我得到的一个(非常)小的链接器错误样本是:
base.o:在函数
void boost::archive::basic_text_oprimitive<std::ostream>::save<boost::archive::class_id_reference_type>(boost::archive::class_id_reference_type const&)': /usr/local/boost/1.44.0/include/boost/archive/basic_text_oprimitive.hpp:91: undefined reference to
boost :: archive :: archive_exception :: archive_exception(boost :: archive :: archive_exception :: exception_code, char const *,char const *)' /usr/local/boost/1.44.0/include/boost/archive/basic_text_oprimitive.hpp:91: 未定义的引用boost::archive::archive_exception::~archive_exception()' /usr/local/boost/1.44.0/include/boost/archive/basic_text_oprimitive.hpp:91: undefined reference to
boost :: archive :: archive_exception :: ~archive_exception()'base.o:In functionvoid boost::archive::basic_text_oprimitive<std::ostream>::save<boost::archive::tracking_type>(boost::archive::tracking_type const&)': /usr/local/boost/1.44.0/include/boost/archive/basic_text_oprimitive.hpp:91: undefined reference to
boost :: archive :: archive_exception :: archive_exception(boost :: archive :: archive_exception :: exception_code, char const *,char const *)' /usr/local/boost/1.44.0/include/boost/archive/basic_text_oprimitive.hpp:91: 未定义的引用boost::archive::archive_exception::~archive_exception()' /usr/local/boost/1.44.0/include/boost/archive/basic_text_oprimitive.hpp:91: undefined reference to
boost :: archive :: archive_exception :: ~archive_exception()'base.o:In functionvoid boost::archive::basic_text_oprimitive<std::ostream>::save<unsigned int>(unsigned int const&)': /usr/local/boost/1.44.0/include/boost/archive/basic_text_oprimitive.hpp:91: undefined reference to
boost :: archive :: archive_exception :: archive_exception(boost :: archive :: archive_exception :: exception_code, char const *,char const *)' /usr/local/boost/1.44.0/include/boost/archive/basic_text_oprimitive.hpp:91: 未定义的引用boost::archive::archive_exception::~archive_exception()' /usr/local/boost/1.44.0/include/boost/archive/basic_text_oprimitive.hpp:91: undefined reference to
的boost ::存档:: archive_exception ::〜archive_exception()'
同样,如果我在引用的.so上进行符号转储,我会看到所需的符号:
objdump -t /usr/local/boost/1.44.0/lib/libboost_serialization.so | c ++ filt | grep的 “推动::档案:: archive_exception ::〜archive_exception()” 000000000004e670 g F .text 0000000000000065
提高::档案:: archive_exception ::〜archive_exception() 000000000004e6e0 g F .text 0000000000000009 virtual thunk to boost :: archive :: archive_exception :: ~archive_exception() 000000000004e6f0 g F .text 0000000000000012
提高::档案:: archive_exception ::〜archive_exception() 000000000004ed60 g F .text 000000000000005c
提高::档案:: archive_exception ::〜archive_exception() 000000000004e710 g F .text 0000000000000009 virtual thunk to boost :: archive :: archive_exception :: ~archive_exception()
我一直在敲桌子一会儿......希望有人可以提供帮助。我不认为具体的来源很重要,但如果要求,我可以发布。
其他环境细节:
g ++ --version g ++(Ubuntu / Linaro 4.7.2-2ubuntu1)4.7.2版权所有(C) 2012 Free Software Foundation,Inc。这是免费软件;看到了 复制条件的来源。没有保修;甚至没有 适销性或适用于特定目的。
ld --version GNU ld (GNU Binutils for Ubuntu) 2.22.90.20120924 Copyright 2012 Free Software Foundation, Inc. This program is free software; you may redistribute it under the terms of the GNU General Public License version 3 or (at your option) a later version. This program has absolutely no warranty.
此外,这是在Windows 8上运行在Hyper-V下的VM上,但我认为这不重要。
完整链接线 g ++ -L / usr / local / boost / 1.44.0 / lib -lboost_serialization -o test-app main.o derived.o base.o
答案 0 :(得分:8)
我遇到了同样的问题,最后把-lboost_serialization放在了
g ++ -L / usr / local / boost / 1.44.0 / lib -o test-app main.o derived.o base.o -lboost_serialization
应该解决它
答案 1 :(得分:-1)
二进制对象.o没有与libs链接
首先验证在 /usr/local/boost/1.44.0/lib 中有文件的lib
boost_serialization。
然后,该lib被注册:
sudo ldconfig -v | grep boost_serialization
如果没有,请使用root用户在 /etc/ld.so.conf.d 中创建文件 boost1.44.0.conf 。用这个ligne
USR /本地/升压/ 1.44.0 / lib目录
然后启动此命令
sudo ldconfig -v | grep boost_serialization