我正在尝试向我的CLion项目添加一个名为OpenAlpr的外部库,其中包含alpr.h和openalpr.lib/openalpr.dll文件。我将头文件放在项目目录中,并将其包含在源代码中,但是我不知道如何添加.dll或.lib文件。我查看了其他答案,如this和this,但它们对我来说太混乱了,我无法让我的答案起作用;当我尝试运行时,会输出以下错误:
undefined reference to `alpr::Alpr::Alpr(std::string, std::string, std::string)'
.text+0x9f): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `alpr::Alpr::Alpr(std::string, std::string, st
undefined reference to `alpr::Alpr::getVersion()'
(.text+0xf3): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `alpr::Alpr::getVersion()'
undefined reference to `alpr::Alpr::~Alpr()'
.text+0x123): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `alpr::Alpr::~Alpr()'
undefined reference to `alpr::Alpr::~Alpr()'
.text+0x1af): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `alpr::Alpr::~Alpr()'
collect2: error: ld returned 1 exit status
make[3]: *** [CMakeFiles/AlprCpp.dir/build.make:84: AlprCpp.exe] Error 1
make[2]: *** [CMakeFiles/Makefile2:73: CMakeFiles/AlprCpp.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:85: CMakeFiles/AlprCpp.dir/rule] Error 2
make: *** [Makefile:118: AlprCpp] Error 2以下是我的CMake文件的内容:
cmake_minimum_required(VERSION 3.12)
project(AlprCpp)
set(CMAKE_CXX_STANDARD 14)
add_executable(AlprCpp main.cpp alpr.h)
link_directories(C:\\Projects\\AlprCpp)
find_library(AlprCpp openalpr.lib)提前谢谢。
发布于 2018-09-10 18:42:15
不要将库的头文件复制到项目中。
在某些情况下,您需要艰难地完成教程,并学习如何使用find_package。如果你只是想让它快速工作,这里有一个简单的方法(假设文件名为Alpr.lib Alpr.h)。
cmake_minimum_required(VERSION 3.12)
project(AlprCpp)
set(ALPR_LIBRARY "" CACHE FILEPATH "Full path to Alpr.lib")
set(ALPR_INCLUDE_PATH "" CACHE PATH "Directory containing Alpr.h")
include_directories(${ALPR_INCLUDE_PATH})
add_executable(AlprCpp main.cpp)
target_link_libraries(AlprCpp ${ALPR_LIBRARY })对于dll文件(假设是Windows),要么设置PATH环境变量,要么将DLL复制到.exe所在的目录。
https://stackoverflow.com/questions/52255867
复制相似问题