简体   繁体   English

C ++ CMake构建错误:对`boost :: throw_exception(std :: exception const&)的未定义引用

[英]C++ CMake build error: undefined reference to `boost::throw_exception(std::exception const&)

I have been trying to integrate boost.Log into my project, but when building I am receiving the error message: 我一直在尝试将boost.Log集成到我的项目中,但是在构建时收到错误消息:

/usr/lib/cross/boost/lib/libboost_date_time.so: undefined reference to `boost::throw_exception(std::exception const&)'

I have checked the ensure I do not have BOOST_NO_EXCEPTIONS defined anywhere, but am still stumped as to why I am getting this error. 我检查了一下,确保没有在任何地方定义BOOST_NO_EXCEPTIONS,但对于为什么会收到此错误,我仍然感到困惑。 My CMAKE file is as follows: 我的CMAKE文件如下:

set(Boost_INCLUDE_DIR /usr/lib/cross/boost/include)
set(Boost_LIBRARY_DIR /usr/lib/cross/boost/lib)
find_package(Boost 1.63.0 COMPONENTS system filesystem log REQUIRED)

message(status "** Boost Include: ${Boost_INCLUDE_DIR}")
message(status "** Boost Libraries: ${Boost_LIBRARY_DIRS}")
message(status "** Boost Libraries: ${Boost_LIBRARIES}")

set (PROJECT_LINK_LIBS thrift crypto ssl sqlcipher)

link_directories( $ENV{LD_LIBRARY_PATH}
                ${Boost_LIBRARY_DIRS}
)

include_directories( $ENV{LD_INCLUDE_PATH}
$ENV{LD_INCLUDE_PATH}/sqlcipher
${Boost_INCLUDE_DIR}
)

add_executable(databaseManager ${MY_SRC})

target_link_libraries(databaseManager ${Boost_LIBRARIES} ${PROJECT_LINK_LIBS} )

The output from the FIND for the libraries seem to be ok: FIND对于库的输出似乎正常:

-- Boost version: 1.63.0
1> -- Found the following Boost libraries:
1> --   system
1> --   filesystem
1> --   log
1> --   date_time
1> --   log_setup
1> --   thread
1> --   regex
1> --   chrono
1> --   atomic
1> status** Boost Include: /usr/lib/cross/boost/include
1> status** Boost Libraries: /usr/lib/cross/boost/lib
1> status** Boost Libraries:
/usr/lib/cross/boost/lib/libboost_system.so;/usr/lib/cross/boost/lib/libboost_filesystem.so;/usr/lib/cross/boost/lib/libboost_log.so;/usr/lib/cross/boost/lib/libboost_date_time.so;/usr/lib/cross/boost/lib/libboost_log_setup.so;/usr/lib/cross/boost/lib/libboost_thread.so;/usr/lib/cross/boost/lib/libboost_regex.so;/usr/lib/cross/boost/lib/libboost_chrono.so;/usr/lib/cross/boost/lib/libboost_atomic.so

Finally, the verbose output of the linking step where it fails: 最后,失败的链接步骤的详细输出:

/home/imx7/build/imx7-firmware-dev-package/src/maketools/obj.iMX7/bin/arm-devolo-linux-g++  -fexceptions -frtti -pthread -O3 -DNDEBUG  -rdynamic CMakeFiles/databaseManager.dir/DatabaseManagerEventHandler.cpp.o CMakeFiles/databaseManager.dir/DatabaseManagerHandler.cpp.o CMakeFiles/databaseManager.dir/DatabaseManagerServer.cpp.o CMakeFiles/databaseManager.dir/DatabaseManagerService.cpp.o CMakeFiles/databaseManager.dir/Logger.cpp.o CMakeFiles/databaseManager.dir/dbConnection.cpp.o CMakeFiles/databaseManager.dir/thrift_common/base_constants.cpp.o CMakeFiles/databaseManager.dir/thrift_common/base_types.cpp.o CMakeFiles/databaseManager.dir/thrift_dbManager/DatabaseManager.cpp.o CMakeFiles/databaseManager.dir/thrift_dbManager/dbManager_constants.cpp.o CMakeFiles/databaseManager.dir/thrift_dbManager/dbManager_types.cpp.o CMakeFiles/databaseManager.dir/thrift_supervisor/Info.cpp.o CMakeFiles/databaseManager.dir/thrift_supervisor/Supervision.cpp.o CMakeFiles/databaseManager.dir/thrift_supervisor/supervision_constants.cpp.o CMakeFiles/databaseManager.dir/thrift_supervisor/supervision_types.cpp.o  -o databaseManager  -L/usr/lib/cross/official_libs  -L/usr/lib/cross/boost/lib -Wl,-rpath,/usr/lib/cross/official_libs:/usr/lib/cross/boost/lib: /usr/lib/cross/boost/lib/libboost_system.so /usr/lib/cross/boost/lib/libboost_filesystem.so /usr/lib/cross/boost/lib/libboost_chrono.so /usr/lib/cross/boost/lib/libboost_log.so /usr/lib/cross/boost/lib/libboost_date_time.so /usr/lib/cross/boost/lib/libboost_log_setup.so /usr/lib/cross/boost/lib/libboost_thread.so /usr/lib/cross/boost/lib/libboost_regex.so /usr/lib/cross/boost/lib/libboost_atomic.so -lthrift -lcrypto -lssl -lsqlcipher 
/home/imx7/build/imx7-firmware-dev-package/src/maketools/binaries.iMX7/tools/bin/../lib/gcc/arm-devolo-linux-gnueabihf/4.9.4/../../../../arm-devolo-linux-gnueabihf/bin/ld: warning: libz.so.1, needed by /usr/lib/cross/official_libs/libsqlcipher.so, not found (try using -rpath or -rpath-link)
/usr/lib/cross/boost/lib/libboost_date_time.so: undefined reference to `boost::throw_exception(std::exception const&)'
collect2: error: ld returned 1 exit status
src/CMakeFiles/databaseManager.dir/build.make:470: recipe for target 'src/databaseManager' failed
make[2]: Leaving directory '/var/cppbuild/DatabaseManager/build/Linux-Release'
CMakeFiles/Makefile2:88: recipe for target 'src/CMakeFiles/databaseManager.dir/all' failed
make[1]: Leaving directory '/var/cppbuild/DatabaseManager/build/Linux-Release'
make[2]: *** [src/databaseManager] Error 1
make[1]: *** [src/CMakeFiles/databaseManager.dir/all] Error 2
Makefile:132: recipe for target 'all' failed
make: *** [all] Error 2

Does anyone have any idea what else I can check or do to get past this error? 有谁知道我还能检查或做什么以克服此错误?

Cheers! 干杯!

******* EDIT ********* *******编辑*********

There have been a few suggestions about adding exception to the COMPONENTS list. 关于将异常添加到COMPONENTS列表中,有一些建议。 I have tried and tested this and unfortunately receive the same error. 我已经尝试并测试了这一点,但不幸的是收到了同样的错误。

The only thing of note is all the main libraries are linked dynamically (.so versions pulled in) and boost_exception is pulled in statically (.a version). 唯一需要注意的是,所有主库都是动态链接的(引入.so版本),而boost_exception则是静态引入的(.a版本)。

New version of find_package command: 新版本的find_package命令:

find_package(Boost 1.63.0 COMPONENTS system atomic filesystem log exception REQUIRED)

Build error with above change: 通过上述更改生成错误:

/home/imx7/build/imx7-firmware-dev-package/src/maketools/obj.iMX7/bin/arm-devolo-linux-g++  -fexceptions -frtti -pthread -g  -rdynamic CMakeFiles/databaseManager.dir/DatabaseManagerEventHandler.cpp.o CMakeFiles/databaseManager.dir/DatabaseManagerHandler.cpp.o CMakeFiles/databaseManager.dir/DatabaseManagerServer.cpp.o CMakeFiles/databaseManager.dir/DatabaseManagerService.cpp.o CMakeFiles/databaseManager.dir/Logger.cpp.o CMakeFiles/databaseManager.dir/dbConnection.cpp.o CMakeFiles/databaseManager.dir/thrift_common/base_constants.cpp.o CMakeFiles/databaseManager.dir/thrift_common/base_types.cpp.o CMakeFiles/databaseManager.dir/thrift_dbManager/DatabaseManager.cpp.o CMakeFiles/databaseManager.dir/thrift_dbManager/dbManager_constants.cpp.o CMakeFiles/databaseManager.dir/thrift_dbManager/dbManager_types.cpp.o CMakeFiles/databaseManager.dir/thrift_supervisor/Info.cpp.o CMakeFiles/databaseManager.dir/thrift_supervisor/Supervision.cpp.o CMakeFiles/databaseManager.dir/thrift_supervisor/supervision_constants.cpp.o CMakeFiles/databaseManager.dir/thrift_supervisor/supervision_types.cpp.o  -o databaseManager  -L/usr/lib/cross/official_libs  -L/usr/lib/cross/boost/lib -Wl,-rpath,/usr/lib/cross/official_libs:/usr/lib/cross/boost/lib: /usr/lib/cross/boost/lib/libboost_system.so /usr/lib/cross/boost/lib/libboost_atomic.so /usr/lib/cross/boost/lib/libboost_filesystem.so /usr/lib/cross/boost/lib/libboost_log.so /usr/lib/cross/boost/lib/libboost_exception.a /usr/lib/cross/boost/lib/libboost_date_time.so /usr/lib/cross/boost/lib/libboost_log_setup.so /usr/lib/cross/boost/lib/libboost_thread.so /usr/lib/cross/boost/lib/libboost_regex.so /usr/lib/cross/boost/lib/libboost_chrono.so -lthrift -lcrypto -lssl -lsqlcipher 
/home/imx7/build/imx7-firmware-dev-package/src/maketools/binaries.iMX7/tools/bin/../lib/gcc/arm-devolo-linux-gnueabihf/4.9.4/../../../../arm-devolo-linux-gnueabihf/bin/ld: warning: libz.so.1, needed by /usr/lib/cross/official_libs/libsqlcipher.so, not found (try using -rpath or -rpath-link)
/usr/lib/cross/boost/lib/libboost_date_time.so: undefined reference to `boost::throw_exception(std::exception const&)'
collect2: error: ld returned 1 exit status
src/CMakeFiles/databaseManager.dir/build.make:471: recipe for target 'src/databaseManager' failed
make[2]: Leaving directory '/var/cppbuild/DatabaseManager/build/Linux-Debug'
CMakeFiles/Makefile2:88: recipe for target 'src/CMakeFiles/databaseManager.dir/all' failed
make[1]: Leaving directory '/var/cppbuild/DatabaseManager/build/Linux-Debug'
make[2]: *** [src/databaseManager] Error 1
make[1]: *** [src/CMakeFiles/databaseManager.dir/all] Error 2
Makefile:132: recipe for target 'all' failed
make: *** [all] Error 2

An update if anyone else ever comes across this. 如果有人遇到此更新。

The only way I was able to get it to work was with having the following snippet of code: 我能够使其正常工作的唯一方法是使用以下代码段:

#define BOOST_NO_EXCEPTIONS
#include <boost/throw_exception.hpp>
void boost::throw_exception(std::exception const & e){
//do nothing
}

I played with the ordering of the libraries, with including them all explicitly, with using findBoost.cmake and all to no avail. 我使用了findBoost.cmake来处理这些库的排序,并显式地包括了所有库,但都无济于事。 Just a random quirk I guess! 我猜只是一个随机的怪癖!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 PCL建立与boost :: throw_exception有关的问题 - PCL build with issue with boost::throw_exception “对&#39;std::operator&lt;&lt;(std::ostream&amp;, std::LinkedList const&amp;)的未定义引用”C++ - "Undefined reference to 'std::operator<<(std::ostream&, std::LinkedList const&)" C++ 由于boost :: throw_exception,boost :: process无法编译 - boost::process cannot compile because of boost::throw_exception 错误:“对运算符&lt;&lt;(std :: ostream&,Dogs const&)的未定义引用” - Error: “Undefined reference to operator<<(std::ostream&, Dogs const&)” 错误未定义对BP :: Device :: Create(std :: string const&)的引用 - Error undefined reference to `BP::Device::Create(std::string const&)' 错误:对`cv::imread(std::string const&amp;, int)&#39;的未定义引用 - error: undefined reference to `cv::imread(std::string const&, int)' [链接器错误]未定义引用`Set <std::string> :: contains(std :: string const&)const&#39; - [Linker error] undefined reference to `Set<std::string>::contains(std::string const&) const' 未定义引用`cv :: error(int,std :: string const&,char const *,char const *,int)&#39; - undefined reference to `cv::error(int, std::string const&, char const*, char const*, int)' ndk-build 给我“错误:未定义的引用”到 cv::CascadeClassifier::load(std::string const&amp;) 即使在我链接库之后 - ndk-build giving me "error: undefined reference" to cv::CascadeClassifier::load(std::string const&) even after I link the libraries 抛出异常为const& - Throwing an exception as const&
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM