User forums > Using Code::Blocks
How to solve project dependencies? [Beginner question]
Otto:
Hi, I'm new to C++ and C::B.
I'm almost sure my problem is related to project dependency, but it could be related to C++ too. I tried what is explained in The build process of C::B but didn't understand well.
Right now I have 3 projects in my workspace:
1- My project itself.
2- A project for unit testing.
3- The UnitTest++ library (I used the Unit Testing tutorial for this).
2 and 3 are working good together. 2 recognizes 3.
But it seems 2 can't use 1's code.
I'm trying to write a unit test (2), but when I try to instantiate an object (1), I get this error:
--- Quote ---undefined reference to `MyClass::MyClass(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)
--- End quote ---
The code was:
--- Code: ---MyClass obj("/home/otto/path/to/file");
--- End code ---
I don't if it's worth pasting here code of my classes (they are three right now). If it's necessary, I'll do.
What I've tried:
- In project 2 properties > project's dependencies > added project 1.
- Again in properties > project's build options > debug target > search directories > added project 1 path in linker (it was already in compiler).
None of these worked.
oBFusCATed:
Two solutions:
1. Add the source files to the unittest project
2. Separate the files to be tested in a separate library static or dynamic
Also read this: http://wiki.codeblocks.org/index.php?title=FAQ#Q:_How_do_I_troubleshoot_an_compiler_problem.3F
Otto:
Can you be more specific?
Isn't option 1 what I'm already doing?
In project properties > project's build options > search directories, I added the src directory of the 1st project.
I don't understand why it doesn't work.
How to try option 2?
Ps: just did what the FAQ suggested.
It first generates all the .o for the 1st project, then tries the .o for the unittest (adding the test library) and fails with the undefined reference error.
oBFusCATed:
For 1, right click on the unittest project -> add files -> add the files with the undefined symbols (.cpp/.c).
Otto:
This works, thanks. Although it seems a bit weird.
Anyway, what is the project dependencies for?
Just to build the dependencies too when the main one is built?
Navigation
[0] Message Index
[#] Next page
Go to full version