未找到包含在 CMakeLists.txt 中的依赖项

问题描述 投票:0回答:0

我使用 CLion 在 Windows 11 中创建了一个包含 CMakeLists.txt 和 vcpkg 的新项目。

我想添加 Box2D、OpenGL、GLUT、GLEW 和 SFML

为此,我在项目目录中克隆了 vcpkg 并添加了 vcpkg.json。

vcpkg.json

{
  "name" : "example-project",
  "version-string" : "0.0.1",
  "license" : "MIT",
  "dependencies" : [ 
    "box2d", 
    "sfml", 
    "opengl", 
    "freeglut", 
    "glew"
  ]
}

CMakeLists.txt

cmake_minimum_required(VERSION 3.15)

# Setup vcpkg script with CMake (note: should be placed before project() call)
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake CACHE STRING "Vcpkg toolchain file")

project(ExampleApp)

set(CMAKE_CXX_STANDARD 23)

find_package(SFML COMPONENTS system window graphics network audio CONFIG REQUIRED)
find_package(box2d CONFIG REQUIRED)
find_package(OpenGL REQUIRED)
find_package(GLUT REQUIRED)
find_package(GLEW REQUIRED)

include_directories(SFML)
include_directories(box2d)
include_directories(OpenGL)
include_directories(OpenGL/include) # OpenGL/include has to contain the required OpenGL's .h files
include_directories(OpenGL/lib) # OpenGL/lib has to contain the required OpenGL's .lib files

set(ExampleApp_SourceFiles example/files)

add_executable(ExampleApp ${ExampleApp_SourceFiles})

target_include_directories(ExampleApp
        PUBLIC
        $<INSTALL_INTERFACE:include>
        $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
        PRIVATE
        ${CMAKE_CURRENT_SOURCE_DIR}/src
        ${_VCPKG_INSTALLED_DIR}/include
        )

target_include_directories(ExampleApp PRIVATE ${OPENGL_INCLUDE_DIR})

target_link_libraries(ExampleApp PRIVATE GLEW::GLEW)
target_link_libraries(ExampleApp PRIVATE ${OPENGL_LIBRARIES})
target_link_libraries(ExampleApp PRIVATE sfml-system PRIVATE sfml-network PRIVATE  sfml-graphics PRIVATE sfml-window)
target_link_libraries(ExampleApp PRIVATE FastNoise)
target_link_libraries(ExampleApp PRIVATE box2d::box2d)

我已经为 CLion 添加了此 CMake 选项,如 vcpkg 文档中所述。

-G "MinGW Makefiles" -DCMAKE_TOOLCHAIN_FILE=C:/Users/micha/CLionProjects/cmake-vcpkg-example/vcpkg/scripts/buildsystems/vcpkg.cmake"

构建此后(使用 MinGW 工具链和生成器),我收到错误,指出在 box2d 和 sfml 中找不到文件(也可能在其他依赖项中)。

错误

C:\Program Files\JetBrains\CLion 2023.1.5\bin\mingw\bin/ld.exe: CMakeFiles\ExampleApp.dir/objects.a(Chunk.cpp.obj): in function `Chunk::~Chunk()':

大块

  // undefined reference
  simulation->game->world->DestroyBody(body);

此方法对于添加

fmt
Catch2
库效果很好,但我无法找到这些其他库。

我还需要做什么才能使用这些依赖项?我已经花了几天时间研究这个问题,但找不到任何类似的例子。

c++ cmake box2d
© www.soinside.com 2019 - 2024. All rights reserved.