Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unresolved external symbol from a static library in one project, not the other. (C++)

I have a static library that compiles fine (lets call it A), and it is reliant on another static library (lets call it B).

I also have project X, which uses library A. So in X I include B and then, below it, include A, both in stdafx.h. I do this using #pragma comments. Project X compiles fine.

However, I then have project Y which also uses library A. But, even though project Y's stdafx.h is IDENTICAL to X's, Y does not compile, giving "unresolved external symbol" errors. What is even stranger is that the errors refer to a function in library B from a function referenced in library A.

Does anyone know why this would be happening? Sorry if I wasn't clear; there's so much code I wouldn't know where to start including it here. Thanks!

like image 870
Raiden616 Avatar asked Feb 10 '14 09:02

Raiden616


1 Answers

I am going to assume you are using MSVS based on the stdafx.h header name. When including static libraries, you not only have to include the needed header files, but you have to link with a static library file, i.e. a .lib file. My guess is that project X has access to that .lib file, while project Y doesn't.

Perhaps through properties->common properties->References and then "add new reference" to point to both your libraries.

Is your project Y, as well as Project X, A, B in the same solution? Adding those projects to the same solution as Y might help. I have only done this having a solution containing all the static libraries I want to include. In my case the paths were automatically (and correctly) set by MSVS. Though that likely requires adding the projects to the solution. (that would be using the method I mentioned above "properties->common properties->References" etc.).

If this is a .lib file from outside your project, you have to include it in "properties->Configuration Properties->Linker->Input->Additional dependencies", and make sure it's path is in "properties->Configuration Properties->Linker->General->Additional Library Directories"

Hope that helps

like image 79
cgeroux Avatar answered Oct 14 '22 03:10

cgeroux