<bdo id='XwVRf'></bdo><ul id='XwVRf'></ul>

<tfoot id='XwVRf'></tfoot>
  • <small id='XwVRf'></small><noframes id='XwVRf'>

  • <legend id='XwVRf'><style id='XwVRf'><dir id='XwVRf'><q id='XwVRf'></q></dir></style></legend>

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

      1. 在 Windows 上使用 Boost_USE_STATIC_LIB OFF 链接 boost 库

        时间:2023-07-20
          • <bdo id='ztgzG'></bdo><ul id='ztgzG'></ul>
              <tbody id='ztgzG'></tbody>

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

              <legend id='ztgzG'><style id='ztgzG'><dir id='ztgzG'><q id='ztgzG'></q></dir></style></legend>

            • <tfoot id='ztgzG'></tfoot>
                  <i id='ztgzG'><tr id='ztgzG'><dt id='ztgzG'><q id='ztgzG'><span id='ztgzG'><b id='ztgzG'><form id='ztgzG'><ins id='ztgzG'></ins><ul id='ztgzG'></ul><sub id='ztgzG'></sub></form><legend id='ztgzG'></legend><bdo id='ztgzG'><pre id='ztgzG'><center id='ztgzG'></center></pre></bdo></b><th id='ztgzG'></th></span></q></dt></tr></i><div id='ztgzG'><tfoot id='ztgzG'></tfoot><dl id='ztgzG'><fieldset id='ztgzG'></fieldset></dl></div>
                1. 本文介绍了在 Windows 上使用 Boost_USE_STATIC_LIB OFF 链接 boost 库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我的 CMakeFiles.txt 看起来像这样:

                  My CMakeFiles.txt looks like this:

                  cmake_minimum_required ( VERSION 2.6 )
                  
                  # Set warnings on and enable debugging
                  SET( CMAKE_C_FLAGS "-Wall -q" )
                  
                  include(FindBoost)
                  
                  set(Boost_USE_STATIC_LIBS ON)
                  set(Boost_USE_MULTITHREADED ON)
                  set(Boost_USE_STATIC_RUNTIME OFF)
                  
                  find_package( Boost 1.57.0 COMPONENTS system filesystem REQUIRED )
                  
                  if( Boost_FOUND )
                      message( STATUS "Boost found!" )
                      include_directories(${Boost_INCLUDE_DIRS})
                      add_executable(foo main.cpp)
                  
                      # Needed for asio
                      if(WIN32)
                        target_link_libraries(foo wsock32 ws2_32)
                      endif()
                  
                      target_link_libraries(foo ${Boost_LIBRARIES})
                  endif()
                  

                  我为 Visual Studio 2013 64 位渲染项目:

                  I render the project for Visual Studio 2013 64-bit:

                  cmake -G "Visual Studio 12 Win64" -DBOOST_LIBRARYDIR=D:DevelopmentToolsoost_1_57_0stagex64lib ..KServer
                  

                  输出为:

                  -- The C compiler identification is MSVC 18.0.31101.0
                  -- The CXX compiler identification is MSVC 18.0.31101.0
                  -- Check for working C compiler using: Visual Studio 12 2013 Win64
                  -- Check for working C compiler using: Visual Studio 12 2013 Win64 -- works
                  -- Detecting C compiler ABI info
                  -- Detecting C compiler ABI info - done
                  -- Check for working CXX compiler using: Visual Studio 12 2013 Win64
                  -- Check for working CXX compiler using: Visual Studio 12 2013 Win64 -- works
                  -- Detecting CXX compiler ABI info
                  -- Detecting CXX compiler ABI info - done
                  -- Boost version: 1.57.0
                  -- Boost version: 1.57.0
                  -- Found the following Boost libraries:
                  --   system
                  --   filesystem
                  -- Boost found!
                  -- Configuring done
                  -- Generating done
                  -- Build files have been written to: D:/Development/Private/C++/KServerProject
                  

                  这一切都很好.

                  问题从这里开始:

                  当我更改要使用的 cmake 文件时:

                  When I change my cmake file to use:

                  set(Boost_USE_STATIC_LIBS OFF)
                  

                  然后我在构建时在 Visual Studio 中收到以下错误:

                  I then get the following error in Visual Studio when building:

                  error LNK1104: cannot open file 'libboost_filesystem-vc120-mt-gd-1_57.lib'  D:DevelopmentPrivateC++KServerProjectsrcLINK  foo
                  

                  检查工作室中的Property Pages,将库添加为依赖项:

                  Checking the Property Pages in the studio the library is added as a dependency:

                  当手动添加文件夹 D:DevelopmentToolsoost_1_57_0stagex64libAdditional Library Directory 时,它构建得很好.

                  When manually adding the folder D:DevelopmentToolsoost_1_57_0stagex64lib to Additional Library Directories it builds fine.

                  如何让它使用动态库创建项目?

                  How can I get it to create project using dynamic libs?

                  推荐答案

                  我相信你需要补充

                  add_definitions( -DBOOST_ALL_NO_LIB )
                  

                  参见 http://www.boost.org/doc/libs/1_57_0/libs/config/doc/html/index.html.我在我的 CMakeLists.txt 中设置了它,它适用于我的视觉工作室构建.作为测试,我删除了它并得到与您相同的错误.

                  See http://www.boost.org/doc/libs/1_57_0/libs/config/doc/html/index.html. I have it set in my CMakeLists.txt and it works for my visual studio builds with boost. As a test, I removed it and got the same error you did.

                  就其价值而言,以下是我将 boost 与 cmake 结合使用的方法.

                  For what it is worth, here is how I use boost with cmake.

                  # boost
                  set(Boost_NO_SYSTEM_PATHS true)
                  set (Boost_USE_STATIC_LIBS OFF CACHE BOOL "use static libraries from Boost")
                  set (Boost_USE_MULTITHREADED ON)
                  find_package(Boost REQUIRED 
                    COMPONENTS
                    system program_options thread filesystem
                    date_time chrono timer regex serialization
                    )
                  include_directories(${Boost_INCLUDE_DIRS})
                  link_libraries(${Boost_LIBRARIES})
                  
                  if (WIN32)
                    # disable autolinking in boost
                    add_definitions( -DBOOST_ALL_NO_LIB )
                  
                    # force all boost libraries to dynamic link (we already disabled
                    # autolinking, so I don't know why we need this, but we do!)
                    add_definitions( -DBOOST_ALL_DYN_LINK )
                  endif()
                  

                  这篇关于在 Windows 上使用 Boost_USE_STATIC_LIB OFF 链接 boost 库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:boost::asio 线程池与 io_service_per_cpu 设计 下一篇:带有 Boost Regex 的 C++ 正则表达式

                  相关文章

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

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

                      <legend id='JGidZ'><style id='JGidZ'><dir id='JGidZ'><q id='JGidZ'></q></dir></style></legend>
                      <tfoot id='JGidZ'></tfoot>