Netbeans Cpp编译和运行项目,但不能使用cppunit进行测试

Netbeans Cpp compiles and runs project, but not test with cppunit

本文关键字:cppunit 测试 但不能 编译 Cpp 运行 项目 Netbeans      更新时间:2023-10-16

我有一个c++项目使用库,如wiiringpi和MySQL连接器。我的常规项目在运行时可以正常编译。当我尝试测试其中一个测试时,它无法构建项目。

输出如下:

"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory '/home/nick/NetBeansProjects/utest'
"/usr/bin/make"  -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux/utest
make[2]: Entering directory '/home/nick/NetBeansProjects/utest'
make[2]: 'dist/Debug/GNU-Linux/utest' is up to date.
make[2]: Leaving directory '/home/nick/NetBeansProjects/utest'
make[1]: Leaving directory '/home/nick/NetBeansProjects/utest'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk SUBPROJECTS= .build-tests-conf
make[1]: Entering directory '/home/nick/NetBeansProjects/utest'
"/usr/bin/make"  -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux/utest
make[2]: Entering directory '/home/nick/NetBeansProjects/utest'
make[2]: 'dist/Debug/GNU-Linux/utest' is up to date.
make[2]: Leaving directory '/home/nick/NetBeansProjects/utest'
mkdir -p build/Debug/GNU-Linux/tests/TestFiles
g++ -lmysqlcppconn -lwiringPi      -o build/Debug/GNU-Linux/tests/TestFiles/f1 build/Debug/GNU-Linux/tests/tests/ConfigParserRunner.o build/Debug/GNU-Linux/tests/tests/ConfigParserTest.o build/Debug/GNU-Linux/main_nomain.o build/Debug/GNU-Linux/src/ConfigFactory_nomain.o build/Debug/GNU-Linux/src/DatabaseAdapter_nomain.o build/Debug/GNU-Linux/src/MatrixControl_nomain.o build/Debug/GNU-Linux/src/ModuleEntity_nomain.o build/Debug/GNU-Linux/src/ModuleServer_nomain.o build/Debug/GNU-Linux/src/SerialDriver_nomain.o build/Debug/GNU-Linux/src/StorageManagement_nomain.o -Llib/cpputest-3.8/lib -L/usr/lib/mysql -L/usr/lib/x86_64-linux-gnu -L/usr/include/cppconn -L/usr/include/cppunit -lCppUTest -lCppUTestExt `cppunit-config --libs`   
build/Debug/GNU-Linux/src/DatabaseAdapter_nomain.o: In function `DatabaseAdapter::DatabaseAdapter(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
/home/nick/NetBeansProjects/utest/src/DatabaseAdapter.cxx:8: undefined reference to `get_driver_instance'
build/Debug/GNU-Linux/src/DatabaseAdapter_nomain.o: In function `DatabaseAdapter::addProduct(int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, productData, int)':
/home/nick/NetBeansProjects/utest/src/DatabaseAdapter.cxx:27: undefined reference to `get_driver_instance'
build/Debug/GNU-Linux/src/DatabaseAdapter_nomain.o: In function `DatabaseAdapter::getEntriesByModule(int)':
/home/nick/NetBeansProjects/utest/src/DatabaseAdapter.cxx:66: undefined reference to `get_driver_instance'
build/Debug/GNU-Linux/src/MatrixControl_nomain.o: In function `MatrixControl::MatrixControl(ModuleServer*)':
/home/nick/NetBeansProjects/utest/src/MatrixControl.cpp:23: undefined reference to `wiringPiSetup'
build/Debug/GNU-Linux/src/SerialDriver_nomain.o: In function `SerialDriver::SerialDriver()':
/home/nick/NetBeansProjects/utest/src/SerialDriver.cpp:18: undefined reference to `pinMode'
/home/nick/NetBeansProjects/utest/src/SerialDriver.cpp:19: undefined reference to `pinMode'
/home/nick/NetBeansProjects/utest/src/SerialDriver.cpp:20: undefined reference to `pinMode'
build/Debug/GNU-Linux/src/SerialDriver_nomain.o: In function `SerialDriver::sendShiftData(unsigned char)':
/home/nick/NetBeansProjects/utest/src/SerialDriver.cpp:28: undefined reference to `shiftOut'
build/Debug/GNU-Linux/src/SerialDriver_nomain.o: In function `SerialDriver::setLatch(bool)':
/home/nick/NetBeansProjects/utest/src/SerialDriver.cpp:33: undefined reference to `digitalWrite'
collect2: error: ld returned 1 exit status
nbproject/Makefile-Debug.mk:146: recipe for target 'build/Debug/GNU-Linux/tests/TestFiles/f1' failed
make[1]: *** [build/Debug/GNU-Linux/tests/TestFiles/f1] Error 1
make[1]: Leaving directory '/home/nick/NetBeansProjects/utest'
nbproject/Makefile-impl.mk:67: recipe for target '.build-tests-impl' failed
make: *** [.build-tests-impl] Error 2
BUILD TESTS FAILED (exit value 2, total time: 584ms)

在实现DatabaseAdapter &SerialDriver类。

我在链接器中添加了库选项,在我的主要项目属性中添加了额外选项,如下所示:

-lCppUTest -lCppUTestExt -lwiringPi -lpthread -lmysqlclient -lmysqlcppconn -lcppunit -ldl

我做了什么错误的链接?

编辑:我尝试测试的测试没有使用任何失败的类。

解决方案是将依赖项作为选项添加到库文件夹中。我在链接器中添加了- lwiiringpi和-lmysqlcppconn