You need to add the library which contains the CameraLeaf code to your linker's input. I assume you are in Visual Studio? Right click your unittest project, Properties->Linker-->Input->Additional Dependencies. Add the name of your library into the list there.
[cid:[email protected]] Dieter Rosch Executive M +27 83 461 1988 O +27 11 532 8300 www.bbd.co.za<http://www.bbd.co.za/> 11 Boundary Road, Isle of Houghton, Wilds view, Houghton estate. This e-mail is confidential and subject to the disclaimer published on the BBD website<http://www.bbd.co.za/emaildisclaimer.htm>. From: Onno Filippo [mailto:[email protected]] Sent: 01 July 2013 09:16 AM To: [email protected] Subject: [unittest-cpp-devel] Newbie question - linking errors when trying to compile tests (using UnitTest++), code compiles in 'product' project I've already asked this question on SO (http://stackoverflow.com/questions/17276901/linker-errors-when-trying-to-link-code-in-tests-using-unittest) but unfortunately it hasn't received any answers that would help me any further. I'm really getting frustrated. I don't see any circular inclusions, and the classes all have definitions of the functions and/or constructors in their respective .cpp files. question: ================== So I'm using Unittest++ (version 1.4) I've tried making a couple of dummy tests (CHECK(true) and CHECK(false), and those work fine. However, as soon as I try to include some production code, the linker goes nuts over using any class or function from the headers that I've included for testing. My questions are: 1. Can this be caused by anything in UnitTest++? 2. How do I set up my code or the project in Code::Blocks to make this error go away? Details: ________________________________ I have used unit testing before with java and C#, but I've never before used a C++ based unit testing package. I'm using Code::Blocks 12.11 as my IDE and GCC 4.6.2 as the compiler to do my work. I have unpacked UnitTest++ to my tools folder and compiled it as explained in the tutorial at http://wiki.codeblocks.org/index.php?title=UnitTesting and have built the library file succesfully. I've added the location of the library file to the linker search directory settings in my test projects' settings file. The code under test compiles fine in its own project, but not when called from the tests. I've set up my project so that every class is tested in its own test file. I have a main.cpp to bind all the tests together. #include UnitTest++.h int main(int, char const *[]) { return UnitTest::RunAllTests(); } One class that I'm trying to test is CameraLeaf: #include <SceneManagement\CameraLeaf.h> #include <Camera.hpp> #include <UnitTest++.h> using namespace SceneManagement; TEST(TestCameraLeafInitialisation) { Camera * cam = new Camera(); CameraLeaf * camLeaf = new CameraLeaf(1, 800, 600, 90.0f, cam); CHECK(camLeaf->getType() == 1); } (I'm using search directory includes using angled brackets, but won't show properly on SO) results in: -------------- Build: Release in Scene Graphs Tests (compiler: GNU GCC Compiler)--------------- mingw32-g++.exe -std=c++0x -Wall -fexceptions -O2 -march=core2 -I"C:\tools\Catch\Catch-0.7(may 2013)\include" -IC:\tools\UnitTest++\src -IC:\Projects\Scene_Graphs -c C:\Projects\Scene_Graphs\tests\unit\CameraLeafTestSuite.cpp -o obj\Release\unit\CameraLeafTestSuite.o mingw32-g++.exe -o "bin\Release\Scene Graphs Tests.exe" obj\Release\unit\CameraLeafTestSuite.o obj\Release\unit\TimeTestSuite.o "obj\Release\Scene Graphs Tests\main.o" -s C:\tools\UnitTest++\Deliv\Release\libUnitTest++.a obj\Release\unit\CameraLeafTestSuite.o:CameraLeafTestSuite.cpp:(.text+0x97): undefined reference to `Camera::Camera(std::string, glm::detail::tvec3)' obj\Release\unit\CameraLeafTestSuite.o:CameraLeafTestSuite.cpp:(.text+0xe4): undefined reference to `SceneManagement::CameraLeaf::CameraLeaf(int, int, int, float, Camera*)' obj\Release\unit\TimeTestSuite.o:TimeTestSuite.cpp:(.text+0x25): undefined reference to `Time::getInstance()' collect2: ld gaf exit-status 1 terug Process terminated with status 1 (0 minutes, 3 seconds) 3 errors, 0 warnings (0 minutes, 3 seconds) I must admit that my knowledge of C++ isn't top notch, but so far I've been able to get by. I don't quite know how to solve this problem. The unit tests are in a subdirectory of the project, and should be reachable with either search directory inclusion or using ../ to skip down to the level where the production code is. As far as I can see, the code is found, otherwise the compiler would throw me a file not found error. So I've concluded this must be a linker error. However, this isn't a case of recursive inclusion, as the camera doesn't need a cameraleaf, nor do the tests need things from the unittest++ framework. So I'm a bit at a loss now. Background story: ________________________________ It's all part of the last assignment I have to do to complete my bachelor, these versions came recommended by the guy who's teaching the course, as it works best with the boiler plate code he provided. Apparently there are some problems with newer versions of GCC. I've completed most of the assignment, but I've run into some problems, so I've decided to create some tests after all. ============== I really don't know where to start. The product project compiles and runs, but contains errors. I need to do some repeatable tests to continue. Any help/pointers to info regarding linker errors in code that compiles and links fine in its 'original project' would really be appreciated. I really don't have a clue if this is due to something in my code, thnx, Onno
<<inline: image003.png>>
------------------------------------------------------------------------------ This SF.net email is sponsored by Windows: Build for Windows Store. http://p.sf.net/sfu/windows-dev2dev
_______________________________________________ unittest-cpp-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/unittest-cpp-devel
