我具有以下目录结构:
├── CMakeLists.txt
├── main.cpp
├── libusb
│ ├── lubusb.h
│ ├── libusb-1.0.def
│ └── libusb-1.0.a
libusb / libusb-1.0.a的转储文件:
File Type: LIBRARY
摘要
DB0 .bss
350 .data
40 .drectve
CFC .pdata
7060 .rdata
20 .rdata$.refptr.INVALID_WINFD
20 .rdata$.refptr.pCancelIoEx
10 .rdata$.refptr.usbdk_backend
30 .rdata$.refptr.usbi_backend
20 .rdata$.refptr.usbi_default_context
10 .rdata$.refptr.windows_version
10 .rdata$.refptr.winusb_backend
160 .rdata$zzz
488 .rsrc
132F0 .text
0 .text.unlikely
1090 .xdata
然后将以下内容写入CMakeLists.txt:
cmake_minimum_required(VERSION 2.8)
project(untitled1)
set(CMAKE_CXX_STANDARD 11)
set(SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp)
add_executable(untitled1 ${SOURCE_FILES})
target_link_libraries(untitled1 ${CMAKE_CURRENT_SOURCE_DIR}/libusb/libusb-1.0.a)
main.cpp的代码:
#include <iostream>
#include "libusb/libusb.h"
int main() {
libusb_init(NULL);
std::cout << "Hello, World!" << std::endl;
return 0;
}
结果是,我得到了未定义的参考:
CMakeFiles\untitled1.dir/objects.a(main.cpp.obj): In function `main':
C:/.../untitled1/main.cpp:5: undefined reference to `libusb_init@4'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [untitled1.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles/untitled1.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles/untitled1.dir/rule] Error 2
mingw32-make.exe: *** [untitled1] Error 2
我在做错什么吗 有人可以帮忙吗?