Author Topic: How to solve project dependencies? [Beginner question]  (Read 5042 times)

Offline Otto

  • Multiple posting newcomer
  • *
  • Posts: 21
How to solve project dependencies? [Beginner question]
« 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 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> >)

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.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
Re: How to solve project dependencies? [Beginner question]
« Reply #1 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
(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!]

Offline Otto

  • Multiple posting newcomer
  • *
  • Posts: 21
Re: How to solve project dependencies? [Beginner question]
« Reply #2 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.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
Re: How to solve project dependencies? [Beginner question]
« Reply #3 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).
(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!]

Offline Otto

  • Multiple posting newcomer
  • *
  • Posts: 21
Re: How to solve project dependencies? [Beginner question]
« Reply #4 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?

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
Re: How to solve project dependencies? [Beginner question]
« Reply #5 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...
(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!]

Offline Otto

  • Multiple posting newcomer
  • *
  • Posts: 21
Re: How to solve project dependencies? [Beginner question]
« Reply #6 on: March 14, 2011, 02:07:40 am »
I hope that's planned for a future release  :)

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13406
    • Travis build status
Re: How to solve project dependencies? [Beginner question]
« Reply #7 on: March 14, 2011, 08:23:19 am »
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!]