我有一个项目已经编译和链接几个月没有问题。最近将ubuntu升级到15.10将升级版本从1.55升级到1.58。现在突然间我得到了未定义的引用错误。无论我是否使用静态链接或动态链接,我都会收到错误:
动态:
> g++ -L"/home/peter/workspace/icflib/Debug" -pthread -o "icfapp"
> ./src/AdminModule.o ./src/CaptureModule.o ./src/FFTModule.o
> ./src/GPSModule.o ./src/ReportModule.o ./src/icfapp.o -licflib
> -lboost_program_options -lboost_date_time -lboost_filesystem -lboost_system -lfftw3 -lmysqlcppconn -lmysqlclient ./src/FFTModule.o: In function
> `boost::filesystem::path::path<boost::filesystem::directory_entry>(boost::filesystem::directory_entry
> const&,
> boost::enable_if<boost::filesystem::path_traits::is_pathable<boost::decay<boost::filesystem::directory_entry>::type>,
> void>::type*)': /usr/include/boost/filesystem/path.hpp:140: undefined
> reference to
> `boost::filesystem::path_traits::dispatch(boost::filesystem::directory_entry
> const&, std::string&)' ./src/icfapp.o: In function
> `processCommandLine(int, char**)':
> /home/peter/workspace/icfapp/Debug/../src/icfapp.cpp:85: undefined
> reference to
> `boost::program_options::options_description::options_description(std::string
> const&, unsigned int, unsigned int)' ./src/icfapp.o: In function
> `boost::program_options::validation_error::validation_error(boost::program_options::validation_error::kind_t,
> std::string const&, std::string const&, int)':
> /usr/include/boost/program_options/errors.hpp:373: undefined
> reference to
> `boost::program_options::validation_error::get_template(boost::program_options::validation_error::kind_t)'
> /usr/include/boost/program_options/errors.hpp:373: undefined
> reference to
> `boost::program_options::error_with_option_name::error_with_option_name(std::string
> const&, std::string const&, std::string const&, int)' ./src/icfapp.o:
> In function
> `boost::program_options::variables_map::operator[](std::string const&)
> const': /usr/include/boost/program_options/variables_map.hpp:155:
> undefined reference to
> `boost::program_options::abstract_variables_map::operator[](std::string
> const&) const' ./src/icfapp.o: In function
> `boost::program_options::basic_command_line_parser<char>::basic_command_line_parser(int,
> char const* const*)':
> /usr/include/boost/program_options/detail/parsers.hpp:43: undefined
> reference to
> `boost::program_options::detail::cmdline::cmdline(std::vector<std::string,
> std::allocator<std::string> > const&)' ./src/icfapp.o: In function
> `boost::program_options::basic_command_line_parser<char>::extra_parser(boost::function1<std::pair<std::string,
> std::string>, std::string const&>)':
> /usr/include/boost/program_options/detail/parsers.hpp:77: undefined
> reference to
> `boost::program_options::detail::cmdline::set_additional_parser(boost::function1<std::pair<std::string,
> std::string>, std::string const&>)' ./src/icfapp.o: In function
> `std::vector<std::string, std::allocator<std::string> >
> boost::program_options::to_internal<std::string>(std::vector<std::string,
> std::allocator<std::string> > const&)':
> /usr/include/boost/program_options/detail/convert.hpp:79: undefined
> reference to `boost::program_options::to_internal(std::string const&)'
> ./src/icfapp.o:(.rodata._ZTVN5boost15program_options11typed_valueIlcEE[_ZTVN5boost15program_options11typed_valueIlcEE]+0x38):
> undefined reference to
> `boost::program_options::value_semantic_codecvt_helper<char>::parse(boost::any&,
> std::vector<std::string, std::allocator<std::string> > const&, bool)
> const'
> ./src/icfapp.o:(.rodata._ZTVN5boost15program_options11typed_valueIjcEE[_ZTVN5boost15program_options11typed_valueIjcEE]+0x38):
> undefined reference to
> `boost::program_options::value_semantic_codecvt_helper<char>::parse(boost::any&,
> std::vector<std::string, std::allocator<std::string> > const&, bool)
> const'
> ./src/icfapp.o:(.rodata._ZTVN5boost15program_options11typed_valueISscEE[_ZTVN5boost15program_options11typed_valueISscEE]+0x38):
> undefined reference to
> `boost::program_options::value_semantic_codecvt_helper<char>::parse(boost::any&,
> std::vector<std::string, std::allocator<std::string> > const&, bool)
> const'
> ./src/icfapp.o:(.rodata._ZTVN5boost15program_options20invalid_option_valueE[_ZTVN5boost15program_options20invalid_option_valueE]+0x30):
> undefined reference to
> `boost::program_options::error_with_option_name::substitute_placeholders(std::string
> const&) const'
> ./src/icfapp.o:(.rodata._ZTVN5boost15program_options16validation_errorE[_ZTVN5boost15program_options16validation_errorE]+0x30):
> undefined reference to
> `boost::program_options::error_with_option_name::substitute_placeholders(std::string
> const&) const' ./src/icfapp.o: In function
> `boost::program_options::typed_value<long, char>::name() const':
> /usr/include/boost/program_options/detail/value_semantic.hpp:19:
> undefined reference to `boost::program_options::arg' ./src/icfapp.o:
> In function `boost::program_options::typed_value<unsigned int,
> char>::name() const':
> /usr/include/boost/program_options/detail/value_semantic.hpp:19:
> undefined reference to `boost::program_options::arg' ./src/icfapp.o:
> In function `boost::program_options::typed_value<std::string,
> char>::name() const':
> /usr/include/boost/program_options/detail/value_semantic.hpp:19:
> undefined reference to `boost::program_options::arg' ./src/icfapp.o:
> In function `boost::program_options::typed_value<std::string,
> char>::xparse(boost::any&, std::vector<std::string,
> std::allocator<std::string> > const&) const':
> /usr/include/boost/program_options/detail/value_semantic.hpp:167:
> undefined reference to `boost::program_options::validate(boost::any&,
> std::vector<std::string, std::allocator<std::string> > const&,
> std::string*, int)' ./src/icfapp.o: In function `void
> boost::program_options::validate<long, char>(boost::any&,
> std::vector<std::basic_string<char, std::char_traits<char>,
> std::allocator<char> >, std::allocator<std::basic_string<char,
> std::char_traits<char>, std::allocator<char> > > > const&, long*,
> long)':
> /usr/include/boost/program_options/detail/value_semantic.hpp:92:
> undefined reference to
> `boost::program_options::invalid_option_value::invalid_option_value(std::string
> const&)' ./src/icfapp.o: In function `void
> boost::program_options::validate<unsigned int, char>(boost::any&,
> std::vector<std::basic_string<char, std::char_traits<char>,
> std::allocator<char> >, std::allocator<std::basic_string<char,
> std::char_traits<char>, std::allocator<char> > > > const&, unsigned
> int*, long)':
> /usr/include/boost/program_options/detail/value_semantic.hpp:92:
> undefined reference to
> `boost::program_options::invalid_option_value::invalid_option_value(std::string
> const&)'
> ./src/icfapp.o:(.rodata._ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_15program_options16validation_errorEEEEE[_ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_15program_options16validation_errorEEEEE]+0x38):
> undefined reference to
> `boost::program_options::error_with_option_name::substitute_placeholders(std::string
> const&) const'
> ./src/icfapp.o:(.rodata._ZTVN5boost16exception_detail19error_info_injectorINS_15program_options16validation_errorEEE[_ZTVN5boost16exception_detail19error_info_injectorINS_15program_options16validation_errorEEE]+0x30):
> undefined reference to
> `boost::program_options::error_with_option_name::substitute_placeholders(std::string
> const&) const'
> ./src/icfapp.o:(.rodata._ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_15program_options20invalid_option_valueEEEEE[_ZTVN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_15program_options20invalid_option_valueEEEEE]+0x38): undefined reference to
> `boost::program_options::error_with_option_name::substitute_placeholders(std::string
> const&) const'
> ./src/icfapp.o:(.rodata._ZTVN5boost16exception_detail19error_info_injectorINS_15program_options20invalid_option_valueEEE[_ZTVN5boost16exception_detail19error_info_injectorINS_15program_options20invalid_option_valueEEE]+0x30):
> undefined reference to
> `boost::program_options::error_with_option_name::substitute_placeholders(std::string
> const&) const' /home/peter/workspace/icflib/Debug/libicflib.a(DBO.o):
> In function `unsigned short
> boost::date_time::month_str_to_ushort<boost::gregorian::greg_month>(std::string
> const&)': /usr/include/boost/date_time/date_parsing.hpp:67: undefined
> reference to `boost::gregorian::greg_month::get_month_map_ptr()'
> collect2: error: ld returned 1 exit status
静态:
g++ -L"/home/peter/workspace/icflib/Release" -pthread -Wl,--no-as-needed -o "icfapp" ./src/AdminModule.o ./src/CaptureModule.o ./src/FFTModule.o ./src/GPSModule.o ./src/ReportModule.o ./src/icfapp.o /home/peter/workspace/icflib/Release/libicflib.a /usr/lib/x86_64-linux-gnu/libboost_program_options.a /usr/lib/x86_64-linux-gnu/libboost_date_time.a /usr/lib/x86_64-linux-gnu/libboost_filesystem.a /usr/lib/x86_64-linux-gnu/libboost_system.a -lfftw3 -lmysqlcppconn -lmysqlclient
./src/FFTModule.o: In function `getLTETxtFiles(dboFlightConfig&)':
FFTModule.cpp:(.text+0x1146): undefined reference to `boost::filesystem::path_traits::dispatch(boost::filesystem::directory_entry const&, std::string&)'
./src/FFTModule.o: In function `FFTModule::scanDir(ICFSocket*)':
FFTModule.cpp:(.text+0xe95c): undefined reference to `boost::filesystem::path_traits::dispatch(boost::filesystem::directory_entry const&, std::string&)'
./src/icfapp.o: In function `processCommandLine(int, char**)':
SNIPPED...
boost 1.58中有什么不同之处我需要设置不同的编译标志吗?
答案 0 :(得分:3)
确保使用相同的编译器&amp;编译所有。标志。
这意味着您需要清理构建并使用用于构建boost的打包版本的相同编译器(请注意,gcc也将作为dist-upgrade的一部分进行更新)。
对ABI或(隐式)预处理程序指令的任何更改都可能导致头文件发出不同(有效)声明,并违反ODR。
比获取链接器错误更糟糕的是,您可能实际上已经默默地获得了未定义的行为。