簡體   English   中英

使用 CMake 和 Boost,目標可能只鏈接到庫,Cmake 正在刪除該項目

[英]Using CMake and Boost, Targets may link only to libraries, Cmake is dropping the Item

我一直在嘗試使用 Cmake 將 Boost 安裝到我的 CLion IDE 上。 我手動設置了我的 Boost CMake 變量,如下所示:

         set(Boost_INCLUDE_DIR C:/Users/Ethan/BoostFolder/boost_1_75_0/boost_1_75_0)
         set(Boost_LIBRARY_DIR C:/Users/Ethan/BoostFolder/boost_1_75_0/boost_1_75_0/libs)

沒有錯誤彈出。 但是這里的警告:

          WARNING: Target "BoostTest" requests linking to directory "C:/Users/Ethan/BoostFolder/boost_1_75_0/boost_1_75_0/libs".  Targets may link only to libraries.  CMake is dropping the item.

阻止我在我的 CLion 文件中使用 Boost。

這是我的 Complete CMakeLists.txt 文件,我想我不應該手動指定 Boost 變量,但我急於使用它。

          cmake_minimum_required(VERSION 3.17)
          project(Lantern)

          set(CMAKE_CXX_STANDARD 17)






    add_executable(Lantern
    BattleManager.h
    CharacterComponents.h
    CMain.c++
    CTests.cpp
    CTree.h
    GameCharacters.h
    GameCommands.h
    GameStructure_main.h
    GameUtilities.h CPlayGround.cpp CPlayGround.h)

   set(Boost_INCLUDE_DIR C:/Users/Ethan/BoostFolder/boost_1_75_0/boost_1_75_0)
   set(Boost_LIBRARY_DIR C:/Users/Ethan/BoostFolder/boost_1_75_0/boost_1_75_0/libs)

  include_directories(${Boost_INCLUDE_DIRS})
  add_executable(BoostTest CPlayGround.cpp)
  target_link_libraries(BoostTest ${Boost_LIBRARY_DIR})

在這一行中,您告訴 CMake 將您的可執行目標BoostTest鏈接到一個目錄:

target_link_libraries(BoostTest ${Boost_LIBRARY_DIR})

你想要做的是通過find_package使用FindBoost機器:

find_package(Boost REQUIRED <components>)

您需要的 Boost 庫列表在哪里。 然后,您可以通過執行將您的應用程序鏈接到 Boost

target_link_libraries(BoostTest Boost::boost)

並將任何其他非標頭 Boost 庫添加到該列表中。 上面鏈接的頁面解釋了您設置的兩個變量用作FindBoost腳本的提示(和/或輸出)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM