News:

As usual while waiting for the next release - don't forget to check the nightly builds in the forum.

Main Menu

inherit static library dependencies

Started by das-d, November 13, 2012, 08:59:06 AM

Previous topic - Next topic

das-d

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

MortenMacFly

Quote from: das-d on November 13, 2012, 08:59:06 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: [url="https://www.codeblocks.org/docs/main_codeblocks_en.html"]https://www.codeblocks.org/docs/main_codeblocks_en.html[/url]
C::B FAQ: [url="https://wiki.codeblocks.org/index.php?title=FAQ"]https://wiki.codeblocks.org/index.php?title=FAQ[/url]

das-d

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

@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.

das-d

yes but does this mean my userProg depends on both my own "userLib" and the sdk library?

Br Daniel

zabzonk

#5
Quotedoes 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.

das-d

#6
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

zabzonk

#7
@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.

QuoteThat 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.

das-d

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