News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

How to solve project dependencies? [Beginner question]

Started by Otto, March 12, 2011, 10:35:56 PM

Previous topic - Next topic

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:

Quoteundefined reference to `MyClass::MyClass(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)

The code was:

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.

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
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

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).
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

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?

oBFusCATed

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...
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Otto


oBFusCATed

It would not have helped you in your current case.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]