CMake未知进口目标的致命错误LNK1107

时间:2019-04-15 15:48:43

标签: cmake

在CMake项目中,我将保存在特殊文件夹中的外部库复制到输出文件夹中,并将其导入为导入目标。

例如,对于libusb:

find_path(LibUsb_INCLUDE_DIR NAMES libusb.h PATHS ${CMAKE_CURRENT_SOURCE_DIR}/LibUsb/Include)
if(NOT LibUsb_INCLUDE_DIR)
message(FATAL_ERROR "LibUsb: include directory wasn't found")
endif()

find_library(LibUsb_LIBRARY NAMES usb-1.0 libusb-1.0 PATHS ${OUTPUT_BIN_DIR})
if(NOT LibUsb_LIBRARY)
    message(FATAL_ERROR "LibUsb: library wasn't found")
endif()

add_library(LibUsb UNKNOWN IMPORTED GLOBAL)
set_target_properties(LibUsb PROPERTIES IMPORTED_LOCATION ${LibUsb_LIBRARY})
set_target_properties(LibUsb PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${LibUsb_INCLUDE_DIR})

message(STATUS "LibUsb: found at ${LibUsb_LIBRARY}")

CMake输出为:

...
-- Building for: Visual Studio 15 2017
-- The C compiler identification is MSVC 19.0.24234.1
-- The CXX compiler identification is MSVC 19.0.24234.1
...
-- CMAKE SYSTEM: Windows-10.0.17763
-- CMAKE VERSION: 3.13.4
...
-- LibUsb: copy binaries
-- VsCan: copy binaries
-- LibUsb: found at C:/myproj/Build/Windows-Debug/Output/Bin/libusb-1.0.lib
-- VsCan: found at C:/myproj/Build/Windows-Debug/Output/Bin/vs_can_api.lib
...
正确找到

LibUsb,如果我打印LibUsb_LIBRARY,则路径正确。一切都可以在Linux上正确编译。

在Windows编译中,我收到致命错误LNK1107:文件无效或损坏

我在做什么错了?

0 个答案:

没有答案