Hi again, After writing my last reply I wind completely wild and did something I thought would be outrageously stupid, but it turned out to work because you started about including libraries.
I imported all the production code headers and implementation files into the test project. When I tried to build the code I got different errors then I did before. Guessing I was on to something, I also included all the libs necessary to build the production code, since the errors were clearly pointing to the kind of linker errors you get when you forget a lib. After I did this the test compiled OK and it ran! I'm still not sure if why it is necessary to include all those classes in both projects. (I wish I could use VS12 for my project, I wouldn't have had this problem at all if I'd been able to use that) If anyone knows why, I reckon it would add value to future readers of this thread. Anyways, it works now. Thnx for the push in the right direction :) Regards, Onno On Mon, Jul 1, 2013 at 12:52 PM, Onno Filippo <c.o.fili...@gmail.com> wrote: > Hello Dieter, > > Thank you for trying to help me, I really appreciate it! > > I'm working on my final assignment for my bachelor. Unfortunately this > means my choices are a bit limited. > I'm using Code::Blocks 12.11 as my IDE and GCC 4.6.2 as my compiler. I'm > more used to using C# and java, but for this assignment I need to use C++. > > I have some extra questions for you that I hadn't thought of before: > > I'm not trying to write a library. Can I only use UnitTest++ to test code > that has been compiled into a library? > Do you know how to get Code::Blocks to have GCC build a library with code > that otherwise is intended to be run as part of a runtime? (Do I need to > change anything else other than some compiler flags?) > I kind of assumed that if the compiler can find the .h(pp) files, which it > does (compiler errors are different if I don't do the include), it can > compile the code and then link it. I'm not (really||at all) up to speed on > solving linker problems, except for the most basic cases. (it seems 90% of > the results that I found on google deal with missing implementations, > circular inclusion and missing main functions) > > I hope you can help me inch my way forward. (or if anyone else knows what > cures there might be, you're most welcome as well ;-) ) > > > Yours sincerely, > > Onno > > > On Mon, Jul 1, 2013 at 11:39 AM, Dieter Rosch <die...@bbd.co.za> wrote: > >> 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. **** >> >> ** ** >> >> ** ** >> >> ** ** >> >> *[image: Adobe Systems]*** >> >> *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:c.o.fili...@gmail.com] >> *Sent:* 01 July 2013 09:16 AM >> *To:* unittest-cpp-devel@lists.sourceforge.net >> *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**** >> >> >> ------------------------------------------------------------------------------ >> This SF.net email is sponsored by Windows: >> >> Build for Windows Store. >> >> http://p.sf.net/sfu/windows-dev2dev >> _______________________________________________ >> unittest-cpp-devel mailing list >> unittest-cpp-devel@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/unittest-cpp-devel >> >> >
<<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 unittest-cpp-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/unittest-cpp-devel