我有這個錯誤,我收到的時候我嘗試編譯:CMake的:不能導入外部庫
Linking CXX executable /home/atv/catkin_ws/devel/lib/atvAcrosser/main**
CMakeFiles/main.dir/src/sendToCAN.cpp.o: In function `sendCAN()':
sendToCAN.cpp:(.text+0x432): undefined reference to `sendCanMessage(CanMsg*)'
collect2: ld returned 1 exit status
make[2]: *** [/home/atv/catkin_ws/devel/lib/atvAcrosser/main] Error 1
make[1]: *** [atvAcrosser/CMakeFiles/main.dir/all] Error 2
make: *** [all] Error 2
Invoking "make" failed
Main
調用線程sendCAN
[內sendToCAN.cpp
]誰在外部庫libARV6005.a
調用函數sendCanMessage
。
這是CMakeList.txt
:
include_directories(include ${catkin_INCLUDE_DIRS})
LINK_DIRECTORIES(${CMAKE_SOURCE_DIR}/atvAcrosser/lib/)
add_executable(main src/main.cpp src/setupPacketProtocol.cpp src/sendToCAN.cpp)
target_link_libraries(main ${catkin_LIBRARIES} ARV6005)
這是樹:
src
├── atvAcrosser
│ ├── CMakeLists.txt
│ ├── include
│ │ └── atvAcrosser
│ │ ├── ARV6005Lib.h
│ │ ├── localPlannerCommunication.h
│ │ ├── receiveFromCAN.h
│ │ └── setupPacketProtocol.h
│ ├── lib
│ │ └── libARV6005.a
│ ├── package.xml
│ ├── src
│ │ ├── localPlannerCommunication.cpp
│ │ ├── main.cpp
│ │ ├── sendToCAN.cpp
│ │ ├── setupPacketProtocol.cpp
sendToCAN.h
// included dependencies
#include "ARV6005Lib.h"
//=================================
// function
void sendCAN();
sendToCAN.cpp
#include "../include/atvAcrosser/sendToCAN.h"
...
void sendCAN()
{
struct CanMsg msg;
struct CanMsg msg;
int i, result;
memset((void *)&msg, 0, sizeof msg);
msg.id = 0x33;
msg.id_type = STD_ID;
msg.length = 8;
for(i=0; i<8; i++) {
msg.data[i] = i;
}
result = sendCanMessage(&msg);
}
但這個Makefile
的教程例如,它的工作原理
all: main.c
gcc -w -o TestUtility -D_REENTRANT -I../Library -pthread ./main.c ./libARV6005.a
儘量讓你的問題更容易理解。如果要理解你很難回答。 –