此导出集中的一些(但不是全部)目标已定义

Some (but not all) targets in this export set were already defined

我创建了一个CMakeLists.txt,内容如下

cmake_minimum_required (VERSION 3.8)
project(CTP_dll)

add_library(CTPdll SHARED CTPdll.cpp)
add_executable(CTPTest CTPTest.cpp)
target_link_libraries(CTPTest CTPdll)

find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
target_link_libraries(CTPdll ${OpenCV_LIBS})

find_package(VTK REQUIRED)
include(${VTK_USE_FILE})
target_link_libraries(CTPTest ${VTK_LIBRARIES})

错误信息是

CMake Error at D:/vcpkg/installed/x64-windows/share/hdf5/hdf5-targets.cmake:37 (message): Some (but not all) targets in this export set were already defined.

Targets Defined: hdf5::hdf5-shared;hdf5::hdf5_hl-shared

Targets not yet defined: hdf5::hdf5_cpp-shared;hdf5::hdf5_hl_cpp-shared

如果我如下删除VTK的include,就不会报错了。但显然我不能在 CTPTest.cpp 中包含 VTK,这是不可接受的。

cmake_minimum_required (VERSION 3.8)
project(CTP_dll)

add_library(CTPdll SHARED CTPdll.cpp)
add_executable(CTPTest CTPTest.cpp)
target_link_libraries(CTPTest CTPdll)

find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
target_link_libraries(CTPdll ${OpenCV_LIBS})

我在 windows10 平台上用 Visual Studio 2022 编译这个。 网上有类似的问题,但没有人回答。所以我提出这个问题,希望有人能提供帮助。

您似乎遇到了 vcpkg issue #15502

有一个pull request with a fix available,显然还没有合并