Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: Otto on March 12, 2011, 10:35:56 pm

Title: How to solve project dependencies? [Beginner question]
Post by: Otto on March 12, 2011, 10:35:56 pm
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 (http://wiki.codeblocks.org/index.php?title=The_build_process_of_Code::Blocks) 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 (http://wiki.codeblocks.org/index.php?title=UnitTesting) 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> >)

The code was:

Code
MyClass obj("/home/otto/path/to/file");

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.
Title: Re: How to solve project dependencies? [Beginner question]
Post by: oBFusCATed on March 12, 2011, 10:51:11 pm
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
Title: Re: How to solve project dependencies? [Beginner question]
Post by: Otto on March 13, 2011, 06:57:01 pm
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.
Title: Re: How to solve project dependencies? [Beginner question]
Post by: oBFusCATed on March 13, 2011, 07:28:15 pm
For 1, right click on the unittest project -> add files -> add the files with the undefined symbols (.cpp/.c).
Title: Re: How to solve project dependencies? [Beginner question]
Post by: Otto on March 13, 2011, 11:00:34 pm
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?
Title: Re: How to solve project dependencies? [Beginner question]
Post by: oBFusCATed on March 13, 2011, 11:15:31 pm
C::B uses them to calculate the correct build order for the projects.
At the moment C::B doesn't support automatic linking of project dependencies...
Title: Re: How to solve project dependencies? [Beginner question]
Post by: Otto on March 14, 2011, 02:07:40 am
I hope that's planned for a future release  :)
Title: Re: How to solve project dependencies? [Beginner question]
Post by: oBFusCATed on March 14, 2011, 08:23:19 am
It would not have helped you in your current case.