编译问题:在Windows上使用cmake项目的LIBUSB_1

时间:2016-02-18 08:02:51

标签: c++ windows dll cmake

首次尝试

在我的cmake / c ++项目中,编译时遇到以下错误:

C:\local\projects\synergy-usb\synergy-through-usb-master>cmake .
You have called ADD_LIBRARY for library cryptopp without any source files. This typically indicates a problem with your CMakeLists.txt file
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
LIBUSB_1_INCLUDE_DIR
   used as include directory in directory C:/local/projects/synergy-usb/synergy-through-usb-master/src/lib/arch
   used as include directory in directory C:/local/projects/synergy-usb/synergy-through-usb-master/src/lib/net
LIBUSB_1_LIBRARY
    linked by target "arch" in directory C:/local/projects/synergy-usb/synergy-through-usb-master/src/lib/arch

-- Configuring incomplete, errors occurred!
See also "C:/local/projects/synergy-usb/synergy-through-usb-master/CMakeFiles/CMakeOutput.log".

所以我缺少libusb库。

第二次尝试

所以现在我找到了一个包含文件夹的libusb_1(libusbx-1.0.18-win)版本:

  • 实施例
  • 包括
  • MINGW32
  • MinGW64
  • MS32
  • MS64

我复制了MS64 / dll(windows 64位)内容并将其放在此处:

C:\local\libs\libusbx

我将此路径添加到PATH变量中,然后尝试再次运行cmake:

C:> cd local \ projects \ synergy-usb \ synergy-through-usb-master

C:\local\projects\synergy-usb\synergy-through-usb-master>cmake .
You have called ADD_LIBRARY for library cryptopp without any source files. This typically indicates a problem with your CMakeLists.txt file
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
LIBUSB_1_LIBRARY
    linked by target "arch" in directory C:/local/projects/synergy-usb/synergy-through-usb-master/src/lib/arch

-- Configuring incomplete, errors occurred!
See also "C:/local/projects/synergy-usb/synergy-through-usb-master/CMakeFiles/CMakeOutput.log".

现在我再次陷入困境。我不知道它要我做什么。它知道libusb在哪里......

修改

以下是包含libusb的CMakeLists.txt的部分内容:

find_package(libusb-1.0 REQUIRED)

set(inc
    .
    ../base
    ../common
    ../mt
    ../platform
    ../synergy
    ${LIBUSB_1_INCLUDE_DIRS}
)

if (UNIX)
    list(APPEND inc
        ../../..
        ../arch
    )
endif()

include_directories(${inc})
add_library(arch STATIC ${src})

set(libs
    ../lib
    ${LIBUSB_1_LIBRARIES}
    )

if (WIN32)
    if (GAME_DEVICE_SUPPORT)
        list(APPEND libs synxinhk)
    endif()
endif()

target_link_libraries(arch ${libs})

修改2

我在findlibusb-1.0.cmake文件中添加了以下行:

set(LIBUSB_1_LIBRARY C:\\local\\libs\\libusbx\\libusb-1.0.dll)
message(STATUS "***********************************>   LIBUSB_1_LIBRARY: ${LIBUSB_1_LIBRARY}")

以下是该输出:

C:\local\projects\synergy-usb\synergy-through-usb-master>cmake .
-- ***********************************>   LIBUSB_1_LIBRARY: C:\local\libs\libusbx\libusb-1.0.dll
-- Found libusb-1.0:
--  - Includes: C:/local/libs/libusbx
--  - Libraries: C:\local\libs\libusbx\libusb-1.0.dll
You have called ADD_LIBRARY for library cryptopp without any source files. This typically indicates a problem with your CMakeLists.txt file
-- Configuring done
CMake Error: CMake can not determine linker language for target: cryptopp
CMake Error: CMake can not determine linker language for target: cryptopp
CMake Error: CMake can not determine linker language for target: cryptopp
CMake Error: CMake can not determine linker language for target: cryptopp
-- Generating done
-- Build files have been written to: C:/local/projects/synergy-usb/synergy-through-usb-master

仍然没有构建,但现在这个特殊的库似乎已经添加好了:)

1 个答案:

答案 0 :(得分:0)

synergy具有这种方法,可以将ext子目录中的某些第三方库压缩为zip压缩。通过usb进行synergy-through-usb,但保留了通过Windows if指定包含的方式。

因此,您只需要转到“ ext”目录,并使用gtest,gmock和crypto库解压缩其zip存档。