我正在使用OpenCV和cmake(这是我的新手)进行一个项目,并获得对位于外部文件夹中的函数的未定义引用。
这适用于使用命令行界面的Raspberry Pi。我的CMakeLists.txt文件如下:
let totalOutboxes = 10,
conversations = 99;
const getTotalResponses = () => {
const result = {
totalOutboxes,
conversations
}
return result;
};
const myObject = getTotalResponses();
console.log(myObject.totalOutboxes);
当我使用cmake_minimum_required(VERSION 3.1)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
project(projectName)
find_package(OpenCV REQUIRED)
add_executable(${PROJECT_NAME} project.cpp supportFile.c supportFile2.c)
target_link_libraries(projectName ${OpenCV_LIBS} wiringPi)
和cmake .
进行编译时,它完成了,但是显示以下消息:
make
所有未定义的引用都是supportFile.c,supportFile2.c或connectioningPi库中的函数调用。我不确定如何解决此问题?
project.cpp文件:
CMakeFiles/.dir/projectName.cpp.o: In function `main':
projectName.cpp:(.text+0x4c): undefined reference to `initializeBoard()'
projectName.cpp:(.text+0x98): undefined reference to `setRS485ServoPosition(unsigned short, unsigned short, unsigned short)'
在supportFile.h文件中找到initializeBoard(),在supportFile2.h中找到setRS485ServoPosition()函数。
答案 0 :(得分:0)
我弄清楚了我的问题所在。它不是与cmake一起,而是与supportFile.h和supportFile2.h。我对这两个文件进行了以下更改:
// .h file #include and #define section
#ifdef __cplusplus
extern "C" {
#endif
extern // to all .h functions section
#ifdef __cplusplus
}
#endif
这样做之后,所有内容都会编译并运行。