3

aeon made me realize i need to revise my question.

I have a chain of static c++ libraries that build just fine. For 3 libraries A,B,C ("->" means a dependency): if A->B and A->C than when i build A everything builds successfully.

I'm referencing A from a c++ console application and when i build that application i get unresolved symbols from static library B. example: "Error 195 error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl ..."

I'm working with VS2010 and referencing static libraries the new way meaning i'm not adding the libraries to "Additional libraries" but i'm referencing them from the new "References..." option they created on VS2010. explained here: http://qualapps.blogspot.com/2010/04/static-library-dependencies-in-visual.html (I tried referencing using "Additional Dependencies" but got the same results).

Any idea how can i resolve this issue ?!

refaelos
  • 7,927
  • 7
  • 36
  • 55
  • What does `A->B` and `A->C` mean? – Nawaz May 02 '11 at 14:44
  • When you have an application X that reference something in lib A and the lib A reference lib B as well as lib C, then you have to add libraries A, B and C to the linker when linking application X. If you want to link lib B and lib C automatically when you link X to A, then you need to add linker commands with #pragma comment to lib A. – harper May 02 '11 at 14:48
  • VS2010 has this new method of referencing libraries. If you choose to reference A and set "Link library dependencies" to "True" than it should link to the referenced libraries as well. – refaelos May 02 '11 at 15:02

2 Answers2

7

There is no such thing as a static library chain - a static library does not carry with it information on which libraries it depends. You therefore need to resolve this error by linking with the library that contains the function(s) that cause the error.

  • VS2010 has this new method of referencing libraries. If you choose to reference A and set "Link library dependencies" to "True" than it should link to the referenced libraries as well. I tried your idea and it didn't work. – refaelos May 02 '11 at 15:03
  • @Rafa If I compile a library with my toolchain, and give it to you, I guarantee there will be no dependancy information in it. What magic does VS 2010 perform then? –  May 02 '11 at 15:21
  • There's no magic. I'm just experiencing a problem and i can't understand why it happens. It works for me on other projects and i wanted to know if people can think of something that i might have done wrong here. I understand what you're saying. You're right. But in my case it doesn't work. Maybe you think there's something i should check to see what i did wrong. – refaelos May 02 '11 at 15:25
  • There is no answer here. – Antony Woods Jun 25 '14 at 12:24
0

Just to get the basics right - make sure all the libraries are in the same location as the console app is, when you run it. However make sure your libraries' paths are all right in the project when you build it.

Sorry but I just noticed that you are using the new way to reference libs, what exactly is this new way? Plz enlighten!

aeon
  • 1,029
  • 2
  • 13
  • 23
  • You "unresolved symbols" when linking. The location of the application is not important at all. – harper May 02 '11 at 14:50
  • @harper: Part of my answer was wrong that I asked for the error, though it was the title of the question - I missed it; edited my answer accordingly. However, I meant the location of the libraries, not the app. – aeon May 02 '11 at 15:00
  • Are the symbols you are trying to reference in your app exported from these libraries? – aeon May 02 '11 at 15:24