简体   繁体   English

CMake 找不到 Boost_LIBRARIES 变量

[英]CMake can't find Boost_LIBRARIES variable

Final Edit: Solved.最终编辑:已解决。 Guys the problem occured because of the "WinSock32".伙计们,问题是由于“WinSock32”而发生的。 I've added我已经添加

target_link_libraries(modernC__ -lws2_32)

and the code has been builded.并且代码已经构建。

I have been using the Boost library on CLion in Ubuntu for about 1 year.我已经在 Ubuntu 中使用 CLion 上的 Boost 库大约 1 年了。 But this week I also decided to install it on the Windows operating system.但本周我也决定将它安装在 Windows 操作系统上。 so I downloaded the Boost library on GitHub and installed the Boost library using Find.Boost first and then "Find.Boost".所以我在 GitHub 上下载了 Boost 库,并首先使用 Find.Boost 然后“Find.Boost”安装了 Boost 库。

After writing the necessary commands in CMake settings section in CLion, I noticed that the variable $ {Boost_LIBRARIES} is empty.在 CLion 的 CMake 设置部分中编写必要的命令后,我注意到变量 $ {Boost_LIBRARIES} 为空。

When I don't use the message () function, the "CMake" part of the project does not give an error, but I get the error "undefined reference" after "build".当我不使用消息()function时,项目的“CMake”部分没有报错,但是在“build”之后出现错误“undefined reference”。 Below are the CMake commands I wrote on CLion and the errors I received.以下是我在 CLion 上编写的 CMake 命令以及收到的错误。

cmake_minimum_required(VERSION 3.16)
project(modernC__)

set(CMAKE_CXX_STANDARD 17)
find_package(Boost 1.66.0)

message(${Boost_INCLUDE_DIR})
message(${Boost_FOUND})
message(${Boost_LIBRARY_DIRS})

IF (Boost_FOUND)
    include_directories(${Boost_INCLUDE_DIR})
add_executable(modernC__

        main.cpp

        #concurrencyExampleOne.cpp

        #adapterExampleOne.cpp
        )
target_link_libraries(modernC__ ${Boost_LIBRARIES})
    message(${Boost_LIBRARIES})
endif()

My output is:我的 output 是:

"C:\Program Files\JetBrains\CLion 2020.1.1\bin\cmake\win\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - MinGW Makefiles" C:\Users\Berke\CLionProjects\modernC++
C:/boost/include/boost-1_66
TRUE
C:/boost/lib
CMake Error at CMakeLists.txt:22 (message):
  message called with incorrect number of arguments


-- Configuring incomplete, errors occurred!

In this case, obviously Cmake is currently unable to find the.lib files that should link to my code.在这种情况下,显然 Cmake 目前无法找到应该链接到我的代码的.lib 文件。 My question is;我的问题是; How can I permanently drop.lib files into this variable, or is there any other way to do this?我怎样才能将.lib 文件永久地放到这个变量中,或者有没有其他方法可以做到这一点?

If I do not use "message(${Boost_LIBRARIES}" so the compiler gives me this error;如果我不使用 "message(${Boost_LIBRARIES}" 那么编译器会给我这个错误;

[ 50%] Linking CXX executable modernC__.exe
CMakeFiles\modernC__.dir/objects.a(main.cpp.obj): In function `ZNK5boost6system14error_category12std_category10equivalentEiRKSt15error_condition':
C:/boost/include/boost-1_66/boost/system/error_code.hpp:676: undefined reference to `boost::system::generic_category()'
C:/boost/include/boost-1_66/boost/system/error_code.hpp:679: undefined reference to `boost::system::generic_category()'
CMakeFiles\modernC__.dir/objects.a(main.cpp.obj): In function `ZNK5boost6system14error_category12std_category10equivalentERKSt10error_codei':
C:/boost/include/boost-1_66/boost/system/error_code.hpp:706: undefined reference to `boost::system::generic_category()'
C:/boost/include/boost-1_66/boost/system/error_code.hpp:709: undefined reference to `boost::system::generic_category()'
C:/boost/include/boost-1_66/boost/system/error_code.hpp:721: undefined reference to `boost::system::generic_category()'
CMakeFiles\modernC__.dir/objects.a(main.cpp.obj): In function `ZN5boost4asio5error19get_system_categoryEv':
C:/boost/include/boost-1_66/boost/asio/error.hpp:230: undefined reference to `boost::system::system_category()'
CMakeFiles\modernC__.dir/objects.a(main.cpp.obj): In function `ZN5boost4asio6detail17winsock_init_base7startupERNS2_4dataEhh':
C:/boost/include/boost-1_66/boost/asio/detail/impl/winsock_init.ipp:39: undefined reference to `_imp__WSAStartup@8'
CMakeFiles\modernC__.dir/objects.a(main.cpp.obj): In function `ZN5boost4asio6detail17winsock_init_base7cleanupERNS2_4dataE':
C:/boost/include/boost-1_66/boost/asio/detail/impl/winsock_init.ipp:56: undefined reference to `_imp__WSACleanup@0'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [CMakeFiles\modernC__.dir\build.make:86: modernC__.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles\Makefile2:75: CMakeFiles/modernC__.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:82: CMakeFiles/modernC__.dir/rule] Error 2
mingw32-make.exe: *** [Makefile:117: modernC__] Error 2

I think, you should specify boost libraries (as components) explicitly.我认为,您应该明确指定 boost 库(作为组件)。 And you should add libraries to target.您应该将库添加到目标。

Like this:像这样:

find_package(Boost COMPONENTS filesystem system locale context REQUIRED)

...

target_link_libraries(${PROJECT_NAME}
  ...
  ${Boost_FILESYSTEM_LIBRARY}
  ${Boost_SYSTEM_LIBRARY}
  ${Boost_LOCALE_LIBRARY}
  ${Boost_CONTEXT_LIBRARY}
  ...
  )





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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM