• <legend id='J59sk'><style id='J59sk'><dir id='J59sk'><q id='J59sk'></q></dir></style></legend>
  • <tfoot id='J59sk'></tfoot>

      <i id='J59sk'><tr id='J59sk'><dt id='J59sk'><q id='J59sk'><span id='J59sk'><b id='J59sk'><form id='J59sk'><ins id='J59sk'></ins><ul id='J59sk'></ul><sub id='J59sk'></sub></form><legend id='J59sk'></legend><bdo id='J59sk'><pre id='J59sk'><center id='J59sk'></center></pre></bdo></b><th id='J59sk'></th></span></q></dt></tr></i><div id='J59sk'><tfoot id='J59sk'></tfoot><dl id='J59sk'><fieldset id='J59sk'></fieldset></dl></div>
        • <bdo id='J59sk'></bdo><ul id='J59sk'></ul>

        <small id='J59sk'></small><noframes id='J59sk'>

        Boost.Log 与 CMake 导致未定义的参考错误

        Boost.Log with CMake causing undefined reference error(Boost.Log 与 CMake 导致未定义的参考错误)
      1. <tfoot id='8BYrX'></tfoot>
          <bdo id='8BYrX'></bdo><ul id='8BYrX'></ul>

              1. <legend id='8BYrX'><style id='8BYrX'><dir id='8BYrX'><q id='8BYrX'></q></dir></style></legend>
              2. <small id='8BYrX'></small><noframes id='8BYrX'>

                  <tbody id='8BYrX'></tbody>
                <i id='8BYrX'><tr id='8BYrX'><dt id='8BYrX'><q id='8BYrX'><span id='8BYrX'><b id='8BYrX'><form id='8BYrX'><ins id='8BYrX'></ins><ul id='8BYrX'></ul><sub id='8BYrX'></sub></form><legend id='8BYrX'></legend><bdo id='8BYrX'><pre id='8BYrX'><center id='8BYrX'></center></pre></bdo></b><th id='8BYrX'></th></span></q></dt></tr></i><div id='8BYrX'><tfoot id='8BYrX'></tfoot><dl id='8BYrX'><fieldset id='8BYrX'></fieldset></dl></div>

                  本文介绍了Boost.Log 与 CMake 导致未定义的参考错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试在我正在处理的项目中使用新的 Boost.Log 库.该项目是使用 CMake 构建的.我收到链接错误,声称链接器遇到了对 Boost.Log 的未定义引用

                  I am trying to use the new Boost.Log library in a project I am working on. The project is built with CMake. I am receiving link errors claiming that the linker has come across undefined references to Boost.Log

                  Linking CXX executable main
                  CMakeFiles/main.dir/main.cpp.o: In function `main':
                  main.cpp:(.text+0x30): undefined reference to `boost::log::v2s_mt_posix::trivial::logger::get()'
                  

                  我有一个简单的 hello world 测试,但由于这些错误而失败.如果我链接到 Boost.Log 库,什么会导致它生成未定义的引用错误?

                  I have a simple hello world test that fails with these errors. If I am linking against the Boost.Log libraries what would cause it to generate an undefined reference error?

                  main.cpp:

                  #include <boost/log/trivial.hpp>
                  int main(int argc, char* const argv[]) {
                    BOOST_LOG_TRIVIAL(info) << "Hello World";
                  }
                  

                  CMakeLists.txt:

                  CMakeLists.txt:

                  CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
                  FIND_PACKAGE(Boost 1.54 COMPONENTS log REQUIRED)
                  FIND_PACKAGE(Threads)
                  INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIR})
                  ADD_EXECUTABLE(main main.cpp)
                  TARGET_LINK_LIBRARIES(main ${Boost_LOG_LIBRARY} ${CMAKE_THREAD_LIBS_INIT})
                  

                  cmake 和 make 的详细输出

                  cmake:

                  -- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:476 ] _boost_TEST_VERSIONS = 1.56.0;1.56;1.55.0;1.55;1.54.0;1.54
                  -- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:478 ] Boost_USE_MULTITHREADED = TRUE
                  -- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:480 ] Boost_USE_STATIC_LIBS = 
                  -- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:482 ] Boost_USE_STATIC_RUNTIME = 
                  -- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:484 ] Boost_ADDITIONAL_VERSIONS = 
                  -- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:486 ] Boost_NO_SYSTEM_PATHS = 
                  -- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:538 ] Declared as CMake or Environmental Variables:
                  -- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:540 ]   BOOST_ROOT = 
                  -- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:542 ]   BOOST_INCLUDEDIR = 
                  -- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:544 ]   BOOST_LIBRARYDIR = 
                  -- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:546 ] _boost_TEST_VERSIONS = 1.56.0;1.56;1.55.0;1.55;1.54.0;1.54
                  -- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:639 ] location of version.hpp: /usr/include/boost/version.hpp
                  -- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:663 ] version.hpp reveals boost 1.54.0
                  -- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:739 ] guessed _boost_COMPILER = -gcc48
                  -- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:749 ] _boost_MULTITHREADED = -mt
                  -- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:792 ] _boost_RELEASE_ABI_TAG = -
                  -- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:794 ] _boost_DEBUG_ABI_TAG = -d
                  -- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:842 ] _boost_LIBRARY_SEARCH_DIRS = /usr/lib64;NO_DEFAULT_PATH
                  -- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:930 ] Searching for LOG_LIBRARY_RELEASE: boost_log-gcc48-mt-1_54;boost_log-gcc48-mt;boost_log-mt-1_54;boost_log-mt;boost_log
                  -- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:966 ] Searching for LOG_LIBRARY_DEBUG: boost_log-gcc48-mt-d-1_54;boost_log-gcc48-mt-d;boost_log-mt-d-1_54;boost_log-mt-d;boost_log-mt;boost_log
                  -- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:1017 ] Boost_FOUND = 1
                  -- Boost version: 1.54.0
                  -- Found the following Boost libraries:
                  --   log
                  -- Configuring done
                  -- Generating done
                  -- Build files have been written to: /home/durrw/boost-log-test/build
                  

                  制作:

                  /usr/bin/cmake -H/home/durrw/boost-log-test -B/home/durrw/boost-log-test/build --check-build-system CMakeFiles/Makefile.cmake 0
                  /usr/bin/cmake -E cmake_progress_start /home/durrw/boost-log-test/build/CMakeFiles /home/durrw/boost-log-test/build/CMakeFiles/progress.marks
                  make -f CMakeFiles/Makefile2 all
                  make[1]: Entering directory `/home/durrw/boost-log-test/build'
                  make -f CMakeFiles/main.dir/build.make CMakeFiles/main.dir/depend
                  make[2]: Entering directory `/home/durrw/boost-log-test/build'
                  cd /home/durrw/boost-log-test/build && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/durrw/boost-log-test /home/durrw/boost-log-test /home/durrw/boost-log-test/build /home/durrw/boost-log-test/build /home/durrw/boost-log-test/build/CMakeFiles/main.dir/DependInfo.cmake --color=
                  make[2]: Leaving directory `/home/durrw/boost-log-test/build'
                  make -f CMakeFiles/main.dir/build.make CMakeFiles/main.dir/build
                  make[2]: Entering directory `/home/durrw/boost-log-test/build'
                  Linking CXX executable main
                  /usr/bin/cmake -E cmake_link_script CMakeFiles/main.dir/link.txt --verbose=1
                  /usr/bin/c++       CMakeFiles/main.dir/main.cpp.o  -o main -rdynamic -lboost_log -lpthread 
                  CMakeFiles/main.dir/main.cpp.o: In function `main':
                  main.cpp:(.text+0x39): undefined reference to `boost::log::v2s_mt_posix::trivial::logger::get()'
                  

                  推荐答案

                  看起来可以归结为链接到 Boost.Log 的共享版本.

                  It looks like it boils down to linking to the shared version of Boost.Log.

                  docs for Boost.Log 您的错误消息提到了命名空间 boost::log::v2s_mt_posix 并且从文档中,这意味着链接器期望链接到Boost.Log 的静态版本.

                  There is a bit of detail on the issue in the docs for Boost.Log Your error message mentions the namespace boost::log::v2s_mt_posix and from the docs, this implies the linker is expecting to link to a static version of Boost.Log.

                  如果你想链接到共享版本,似乎你需要定义BOOST_LOG_DYN_LINKBOOST_ALL_DYN_LINK,即在你的CMakeLists.txt中添加:

                  If you want to link to the shared version, it seems you need to define BOOST_LOG_DYN_LINK or BOOST_ALL_DYN_LINK, i.e. in your CMakeLists.txt add:

                  ADD_DEFINITIONS(-DBOOST_LOG_DYN_LINK)
                  

                  如果你想链接到 Boost.Log 的静态版本,你需要在调用 FIND_PACKAGE(Boost ...) 之前添加一个 CMake 变量之前:

                  If you want to link to the static version of Boost.Log, instead you need to add a CMake variable before calling FIND_PACKAGE(Boost ...):

                  SET(Boost_USE_STATIC_LIBS ON)
                  FIND_PACKAGE(Boost 1.54 COMPONENTS log REQUIRED)
                  

                  有关影响 CMake 如何找到 Boost 的更多变量,请参阅 FindBoost.

                  For further variables which affect how CMake finds Boost, see the docs for FindBoost.

                  这篇关于Boost.Log 与 CMake 导致未定义的参考错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to limit the number of running instances in C++(C++中如何限制运行实例的数量)
                  Using boost::asio::async_read with stdin?(将 boost::asio::async_read 与 stdin 一起使用?)
                  How to find out what dependencies (i.e other Boost libraries) a particular Boost library requires?(如何找出特定 Boost 库需要哪些依赖项(即其他 Boost 库)?)
                  What#39;s the purpose of a leading quot;::quot; in a C++ method call(引导“::的目的是什么?在 C++ 方法调用中)
                  Boost Spirit x3: parse into structs(Boost Spirit x3:解析为结构体)
                  How boost auto-linking makes choice?(boost自动链接如何做出选择?)

                  <legend id='J037B'><style id='J037B'><dir id='J037B'><q id='J037B'></q></dir></style></legend>
                    <tbody id='J037B'></tbody>

                    <small id='J037B'></small><noframes id='J037B'>

                  1. <i id='J037B'><tr id='J037B'><dt id='J037B'><q id='J037B'><span id='J037B'><b id='J037B'><form id='J037B'><ins id='J037B'></ins><ul id='J037B'></ul><sub id='J037B'></sub></form><legend id='J037B'></legend><bdo id='J037B'><pre id='J037B'><center id='J037B'></center></pre></bdo></b><th id='J037B'></th></span></q></dt></tr></i><div id='J037B'><tfoot id='J037B'></tfoot><dl id='J037B'><fieldset id='J037B'></fieldset></dl></div>
                  2. <tfoot id='J037B'></tfoot>

                    • <bdo id='J037B'></bdo><ul id='J037B'></ul>