Author Topic: Dependencies to static libs don't work?  (Read 12424 times)

Offline cacb

  • Lives here!
  • ****
  • Posts: 536
Dependencies to static libs don't work?
« on: December 05, 2008, 03:56:47 pm »
Hi,

I have a workspace with a couple of application projects both depending on a common static library project. I want to have it like that because the resulting builds are then self contained.

The application projects are defined to be dependent on the static library, and a full rebuild works fine. But I find that very often after I make a change in one of the .cpp files of the static library, and then build one of the applicatons (not complete rebuild), it reports that it is already up to date and does not re-link. This is not correct and very annoying as I keep running/debugging the wrong code.... I have to manually change one of the application source files to force a relink.

Have you seen this before, is there something I have missed?

Offline cacb

  • Lives here!
  • ****
  • Posts: 536
Re: Dependencies to static libs don't work?
« Reply #1 on: December 09, 2008, 07:00:54 pm »
Nobody has any opinion on this? I am seeing this problem.

If a header files in the static lib project is changed, all is fine, the main project recompiles and relinks. If a .cpp file in the static lib is changed, the static lib is recompiled and a new.lib file is generated.

But the application project using the lib claims it is up to date and does not relink, resulting in wrong behaviour.

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Dependencies to static libs don't work?
« Reply #2 on: December 09, 2008, 08:22:20 pm »
You can set dependencies to external files in the projects properties.

Right-click your project and chose "Properties -> Build targets". For every build target (e.g. Release, Debug) you can click on "Dependencies" and set the static lib(s) it depends on as external file.

If you want to make sure the lib is checked for changes and eventually build before the actual project, include the project containing the lib in "Project's dependencies" (on "Project settings" tab).

Offline cacb

  • Lives here!
  • ****
  • Posts: 536
Re: Dependencies to static libs don't work?
« Reply #3 on: December 10, 2008, 12:03:54 am »
Thank you Jens  :D

I tried with the first technique, defining external dependencies, and that did in fact work.

But the project as such was already defined as depending on the lib using Project Dependencies ("Project Settings"). I would not have expected dependency to work without declaring a dependency....

I thought that when using Project Dependencies I would have an automatic dependency to the lib file as you explain. But it certainly does not work here (I am using build 5309 on Windows and Kubuntu). It seems odd to have to declare a project dependency AND declare external dependency to the project lib for every build target?

flobadob

  • Guest
Re: Dependencies to static libs don't work?
« Reply #4 on: January 12, 2009, 01:59:14 am »
I can't even get my dependencies to build if they are missing. How does one setup dependencies correctly for, say, an exe project and a static lib project in the same workspace?

Offline raybert

  • Multiple posting newcomer
  • *
  • Posts: 21
Re: Dependencies to static libs don't work?
« Reply #5 on: April 23, 2009, 10:30:28 pm »
I thought that when using Project Dependencies I would have an automatic dependency to the lib file as you explain. But it certainly does not work here (I am using build 5309 on Windows and Kubuntu). It seems odd to have to declare a project dependency AND declare external dependency to the project lib for every build target?

Not only that but you also have to add the lib (in the case of a static lib) to the linker list or it won't link against it.

I admit that I expected Project Dependencies to handle dependency checking and linking automatically when the dependency is another CB (static lib) project.

~ray

Offline edwin

  • Multiple posting newcomer
  • *
  • Posts: 38
Re: Dependencies to static libs don't work?
« Reply #6 on: September 03, 2010, 04:14:17 pm »
jens,

I was building/debugging code this morning and also came across this behavior. I am using trunk SVN 6564.

I have a project that builds a shared library that is also dependant on other static libraries (also my own). I have a “main” workspace that I use for all the projects that sets up the project dependencies (the build order). Nice.

Your suggestion regarding “external dependency files” works beautifully to force a relink of my shared library when one of the other static libraries changes. I am glad this capability exists.

I have to agree however with cacb’s December 10, 2008 post. If we set up a build dependency (build order), that should also imply that the final target get relinked if any of the depandancy output images change. Having to do this manually is an extra step and a bit cumbersome when having a project with many build targets (debug, release, trial_debug, trial_release) not to mention supporting multiple platforms (Windows, Linux and OS X). I do not think setting up a dependency should also “auto link” with the dependency. We should always have to manually specify static libs we need to link against. All the dev tools I have used in the past 26 years have pretty much worked this way… and it might help to simplify the C::B developer experience.


I hope this information is helpful. I think C::B is great and my only wish is to see it get better.

Thank you,

edwin



Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Dependencies to static libs don't work?
« Reply #7 on: September 03, 2010, 06:23:19 pm »
I've argued the same thing with Morten and he said it would be impossible to implement the auto-mumbo-jumbo for all compilers that C::B supports. I think it is possible, but I've no desire/need to implement this feature. :)

Probably you could write a script that could set the options and still leaves you in full control.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Dependencies to static libs don't work?
« Reply #8 on: September 03, 2010, 08:45:43 pm »
I've argued the same thing with Morten and he said it would be impossible to implement the auto-mumbo-jumbo for all compilers that C::B supports.
I am not saying it is impossible, but I actually don't want such auto-magic and I bet I am not the only one. In fact I never understood why MSVS does such things and in fact what's done in MSVS is not something clever but linking against all available libraries in the end and let the linker choose what's right. Look what you#ll find in nearly every MS project:
Code
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386
(...just try to google for it...). So why do I need to link against winspool or odbc if I do a hello world application?! I don't think that's a good thing to do... really.

However, If I got that topic right this is a rather different problem: It means that you want to link against your own libraries if they've changed, so only within your project / workspace. This is something worth to discuss. But I really wouldn't want to do such for system libraries.
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 oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Dependencies to static libs don't work?
« Reply #9 on: September 03, 2010, 11:38:26 pm »
Hm, I've never wanted C::B to resolve the system libraries my project is using.
But, I want automatic linking for my projects, this should be doable and is done in VS (works without problems).
Probably the most annoying thing is the external deps setup, if that is automated the other is OK.

p.s. here is a link to the old thread: http://forums.codeblocks.org/index.php/topic,11905.msg81001.html
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline edwin

  • Multiple posting newcomer
  • *
  • Posts: 38
Re: Dependencies to static libs don't work?
« Reply #10 on: September 04, 2010, 02:00:44 am »
MortenMacFly:
Quote
I am not saying it is impossible, but I actually don't want such auto-magic…

Yes - I agree. The way MSVC links to all sorts of system libraries seems rather overkill and uncontrolled. I like your term “auto-magic”. Yes, that type of automatic “stuff” causes trouble eventually.

oBFusCATed:
Quote
I've never wanted C::B to resolve the system libraries my project is using.

Yes – perfect.

Quote
Probably the most annoying thing is the external deps setup, if that is automated the other is OK.

Supurb – absolutely accurate. :) :) :)


You guys are very great… very, very smart. :)

Sorry again for my “sig thing” a week ago. I still feel the sting…  :oops:

Have a good weekend,


edwin