Author Topic: inherit static library dependencies  (Read 5557 times)

Offline das-d

  • Single posting newcomer
  • *
  • Posts: 5
inherit static library dependencies
« on: November 13, 2012, 08:59:06 am »
Hello,
I haven't found a solution to my problem. Also I don't know if this wanted or unwanted behaviour.

Let's assume I have a program "userProg" that is linked to a static library "userLib". My "userLib" depends on another external static library provided by an sdk for target hardware. Now if I add my library to "userProg" that it can use it and trying to compile, I get an error that I have "undefined references" to functions of the external sdk library. This can be solved only if I add the dependcy to external library to both projects "userProg" and "userLib". Is this regular behaviour or do I have to make some special Projectsettings?


Best regards

Daniel

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: inherit static library dependencies
« Reply #1 on: November 13, 2012, 09:01:42 am »
Is this regular behaviour or do I have to make some special Projectsettings?
You should better ask this question to the developer/provider of the SDK. It might be or not. Consult the developers guide what the SDK developer/provider suggests to do - then set it up in Code::Blocks accordingly.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ

Offline das-d

  • Single posting newcomer
  • *
  • Posts: 5
Re: inherit static library dependencies
« Reply #2 on: November 13, 2012, 09:24:58 am »
Hello,
thanks for your reply but I think you missunderstood. For sure in my "userLib" i have to add the sdk lib as a dependency for linker that all references can be defined. But I don't know why I have to add them to my "userProg" linker settings too. I thought with compiling of "userLib" the references are resolved and this library is fully compiled and linked. So I thougt if I add my userlib to my userProg as a linker dependency it just links to the staticlibrary and everything is fine.

BR daniel

zabzonk

  • Guest
Re: inherit static library dependencies
« Reply #3 on: November 13, 2012, 09:41:42 am »
@das-d

Static libraries do not link with other static libraries, so there is no dependency or name resolution between the actual libraries - a library will of course be dependent on any headers from other sources it uses.

Offline das-d

  • Single posting newcomer
  • *
  • Posts: 5
Re: inherit static library dependencies
« Reply #4 on: November 13, 2012, 10:11:46 am »
yes but does this mean my userProg depends on both my own "userLib" and the sdk library?

Br Daniel

zabzonk

  • Guest
Re: inherit static library dependencies
« Reply #5 on: November 13, 2012, 10:16:07 am »
Quote
does this mean my userProg depends on both my own "userLib" and the sdk library?

Yes. Your project is dependent on both the userLib and SDK libraries and headers. The userLib is dependent on the SDK headers, but not on the SDK library.
« Last Edit: November 13, 2012, 10:18:11 am by Neil Butterworth »

Offline das-d

  • Single posting newcomer
  • *
  • Posts: 5
Re: inherit static library dependencies
« Reply #6 on: November 13, 2012, 10:20:37 am »
ok with shared librarys this behaviour is different I guess?

What I never found out yet, sorry I'm new to deep c programming and bigger projects, is a shared library loaded once or twice in target system if two applications running using it. What I mean is if I have some sort of init stuff that should be used seperate by each application for example. Does Application A sees the "initialized" library if Application B that uses the same shared library have already executed the init sequence?

Edit: One of my books says: "dynamic librarys use all the same code, they are loaded only once". That means they share any values of their variables also, correct?


Sorry if this is a stupid question!

BR daniel
« Last Edit: November 13, 2012, 10:29:18 am by das-d »

zabzonk

  • Guest
Re: inherit static library dependencies
« Reply #7 on: November 13, 2012, 10:42:44 am »
@das-d

This is getting off-topic, but yes, shared libraries and DLLs are different - they are much more like executables than static libraries, and they  _do_ link with their dependent libraries, or at least with the dependent libraries import libs.

Quote
That means they share any values of their variables also, correct?

Nope. By default, each loaded instance of a shared library shares code, but gets its own data segment. If two applications use the same shared library, they do not share data.
« Last Edit: November 13, 2012, 10:45:19 am by Neil Butterworth »

Offline das-d

  • Single posting newcomer
  • *
  • Posts: 5
Re: inherit static library dependencies
« Reply #8 on: November 13, 2012, 10:50:10 am »
Thanks for reply to offtopic!

You have really helped me, now I can decide if shared or static librarys are better in my case.

BR Daniel