Author Topic: How to set up a project to build both static and dynamic libraries  (Read 4433 times)

Offline alexchen

  • Multiple posting newcomer
  • *
  • Posts: 84
Is there a way to set a project's 'Build Targets' property to generate both static (.a) and dynamic (.so) libraries in the same build in Linux?
It seems the only way to build static and dynamic libraries is to have separate projects.

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: How to set up a project to build both static and dynamic libraries
« Reply #1 on: December 07, 2013, 12:07:37 am »
Is there a way to set a project's 'Build Targets' property to generate both static (.a) and dynamic (.so) libraries in the same build in Linux?
It seems the only way to build static and dynamic libraries is to have separate projects.

Did you try separate targets?
If not, try that. No idea if it works; but, I really think it should work.

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: How to set up a project to build both static and dynamic libraries
« Reply #2 on: December 07, 2013, 12:08:33 am »
You can have two seperate build targets and put them together in one virtual target, so both get build if you click on the build- or rebuild-button.

Offline dmoore

  • Developer
  • Lives here!
  • *****
  • Posts: 1576
Re: How to set up a project to build both static and dynamic libraries
« Reply #3 on: December 07, 2013, 12:46:56 am »
And if they share the same object dir (and object files) gcc won't need to compile twice, it will just link both ways from the same objects.
« Last Edit: December 07, 2013, 04:53:19 am by dmoore »

Offline alexchen

  • Multiple posting newcomer
  • *
  • Posts: 84
Re: How to set up a project to build both static and dynamic libraries
« Reply #4 on: December 07, 2013, 02:13:59 am »
The original targets were 'Release' and 'Debug'.  I create 'ReleaseStatic' and rename 'Release' to 'ReleaseDynamic' so that a new virtual target 'Release' can invoke both. However, the variable name $TARGET_NAME is tied to 'ReleaseDynamic' instead of 'Release' when I build 'Release' target, and that messes up my pre-build script, which keys on this value to select either 'Release' or 'Debug', not 'ReleaseStatic', 'ReleaseDynamic', 'DebugStatic', or 'DebugDynamic'.

If there is a variable name that represent all the object files, Maybe I can add a 'post-build' script to build static libraries when the dynamic library is built.