我正在开发一个由一些组件组成的项目,每个组件都必须与GPS或IMU等传感器通信。 该文件夹的结构如下:
/
build
src
errorCodes.h
Component.h
Component.cpp
IMU.h
IMU.cpp
tests
imu
main.cpp
CMakeLists.txt
我想要做的是编译链接src文件中的实现的测试目录中的main.cpp
文件。
CMakeLists.txt
文件如下:
cmake_minimum_required (VERSION 2.6 FATAL_ERROR)
set (PROJECT_NAME imu)
set (DUT_DIR ${CMAKE_SOURCE_DIR}/../../../src)
project (${PROJECT_NAME})
find_package (Qt5Core REQUIRED)
set (project_SOURCES main.cpp ${DUT_DIR}/IMU.h ${DUT_DIR}/IMU.cpp ${DUT_DIR}/Component.h ${DUT_DIR}/Component.cpp ${DUT_DIR}/errorCodes.h)
include_directories (${DUT_DIR})
ADD_EXECUTABLE (${PROJECT_NAME} ${project_SOURCES}
${project_FORMS_HEADERS}
${project_HEADERS_MOC})
qt5_use_modules(${PROJECT_NAME} Core SerialPort)
但是当我运行make
命令时,我收到以下错误:
CMakeFiles/imu.dir/home/thegr8/Desktop/3d-6dof-scanner/src/IMU.cpp.o: In function `IMU::IMU()':
IMU.cpp:(.text+0x25): undefined reference to `vtable for IMU'
CMakeFiles/imu.dir/home/thegr8/Desktop/3d-6dof-scanner/src/IMU.cpp.o: In function `IMU::~IMU()':
IMU.cpp:(.text+0x7c): undefined reference to `vtable for IMU'
CMakeFiles/imu.dir/home/thegr8/Desktop/3d-6dof-scanner/src/Component.cpp.o: In function `Component::Component(QObject*)':
Component.cpp:(.text+0x2a): undefined reference to `vtable for Component'
CMakeFiles/imu.dir/home/thegr8/Desktop/3d-6dof-scanner/src/Component.cpp.o: In function `Component::~Component()':
Component.cpp:(.text+0x65): undefined reference to `vtable for Component'
我做错了什么?
现在我在构建目录中创建了一个库,并按照评论中的建议从测试文件中链接它们。
编译测试项目时,我收到以下错误:
IMU.cpp:(.text+0x244): undefined reference to `QSerialPortInfo::availablePorts()'
IMU.cpp:(.text+0x265): undefined reference to `QSerialPortInfo::QSerialPortInfo(QSerialPortInfo const&)'
IMU.cpp:(.text+0x28b): undefined reference to `QSerialPort::QSerialPort(QObject*)'
IMU.cpp:(.text+0x2af): undefined reference to `QSerialPortInfo::portName() const'
IMU.cpp:(.text+0x343): undefined reference to `QSerialPortInfo::description() const'
IMU.cpp:(.text+0x3d7): undefined reference to `QSerialPortInfo::manufacturer() const'
IMU.cpp:(.text+0x46b): undefined reference to `QSerialPortInfo::portName() const'
IMU.cpp:(.text+0x488): undefined reference to `QSerialPort::setPortName(QString const&)'
IMU.cpp:(.text+0x560): undefined reference to `QSerialPort::setBaudRate(int, QFlags<QSerialPort::Direction>)'
IMU.cpp:(.text+0xada): undefined reference to `QSerialPort::error() const'
IMU.cpp:(.text+0xb46): undefined reference to `QSerialPortInfo::~QSerialPortInfo()'
IMU.cpp:(.text+0xb91): undefined reference to `QSerialPortInfo::~QSerialPortInfo()'
IMU.cpp:(.text+0xd37): undefined reference to `QSerialPortInfo::~QSerialPortInfo()'
两个项目都使用set(AUTOMOC ON)