views:

310

answers:

2

Hi,

I'll try to explain shortly what I want to do:

A project using a static library which have another one as depandency. It produce a project called MyProject linking on MyLib1 linking on MyLib2. Here is the compile order:

  • MyLib2
  • MyLib1 (linking to MyLib2)
  • MyProject (linking to MyLib1)

I'm using Visual Studio 2008 and I have some troubles at defining include. When linking, I use the property "Additional Include Directory" (on project property C/C++ node). This seems working between MyProject and MyLib1 but not MyLib1 and MyLib2. For Exemple: I've a file in MyLib2 called foo.cpp; Using #include "foo.cpp" makes visual studio telling that foo.cpp is unknow (missing file or folder).

To ensure it's NOT a wrong path I gave, I've done many attemps like following: copy-paste the path shown in Command Line (used to compile the library) into win explorer: I well see the source code of my second library. I've remake the project many times and each times I used differents names (forcing me to pay attention to this) and everything seems well defined (but not "including").

The only way I actually find to make it works: using #include "c:\\foo.cpp" as include... Very nice for portability !

Here is a Zip of the Solution to test it yourself and tell me what's wrong: MyProject.rar

Thanks for taking some time to help me ! Lucyberad

A: 

First, never include *.cpp files.

Second, use forward declaration of your external functions:

void appellib2(void);

void appellib1(void)
{
    appellib2();
}

Third, right-click each project in the Solution Explorer, and select "Project dependencies..." and set-up proper dependencies: MyProject -> MyLib1 -> MyLib2.

At last, in properties for MyProject, set up additional dependencies MyLib1.lib.

Now I can build and run your project without errors.

UPDATE

Never rename *.cpp to *.h just to solve linking problems. If you have a definition in your *.h file you will unable to include it twice or more.

Here is your project YourProject.rar.

Vova
Thank you, it seems working this way.In fact the dependancy don't make the need to use #include but require signatures to work with.Another people find that making available "$(SolutionDir)\MyLib2" into Additional Include Directories (making the following line into: "$(SolutionDir)\MyLib1";"$(SolutionDir)\MyLib2") works either.But this time it make MyLib2 available into MyProject.Whatever you need, the two answers works (and fit well to two specific purpose).Thanks for the help,Lucyberad.
Lucyberad
A: 

I've changed .cpp to .h. I Know I've never to include a CPP file but it was for testing purpose.

I've added prototype of each function but it doesn't works better (It don't include the file mylib2.cpp, the prototype is better but not usefull in this test).

I've set up project dependencies. It still fail.

I've set up additional dependencies MyLib1.lib to MyProject (I think this was the next error I would be able to find, producing a linking a error).

With theses modifications, I still got include error mylib2.h: no such file or directory.

Here is the new archive: MyProject.rar

If you reach to get it working, can you make me an archive of the working solution?

Thanks, Lucyberad.

Lucyberad
I've updated my answer with the link to your project fixed.
Vova
P. S. Respond to my answers, because I get notified in this case.
Vova