Code::Blocks Forums
User forums => Using Code::Blocks => Topic started by: das-d 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
-
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.
-
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
-
@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.
-
yes but does this mean my userProg depends on both my own "userLib" and the sdk library?
Br Daniel
-
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.
-
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
-
@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.
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.
-
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