Skip to content
Advertisement

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

I have a C++ project using libraries such as wiringPi and MySQL Connector. My regular project compiles normally when I run it. When I try to Test one of my tests, it fails building the project.

Here’s the output:

"/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)

The tests used to work before the implementation of the DatabaseAdapter & SerialDriver classes.

I have added library options to the linker additional options in my main project properties like so:

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

Am I doing something wrong with the linking?

EDIT: The test I try to test does not use any of the failing classes.

Thanks in advance.

Advertisement

Answer

The resolution was to add my dependencies as an option to my library folder. I added -lwiringPi and -lmysqlcppconn to the linker.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement