Author Topic: Build Static Library with different CC and CXX flags  (Read 3273 times)

Offline Slammer

  • Multiple posting newcomer
  • *
  • Posts: 15
Build Static Library with different CC and CXX flags
« on: April 12, 2016, 11:30:13 am »
I want to build a static library from c and cpp sources. The CC flags and CXX can't be defined separately so, I create two targets with different flags, one for c source files and one for cpp files.
With this way I have two separate targets,  two separate static libs, but I want only one.
To overcome this problem, I found two possible solutions:

1. Set the same target library filename for two targets and remove the delete command from compiler settings before execution of linker. Builds ok but requires a manual delete of library before building of two targets.
2. Let the filename of two libraries different. Create a new target with all .o files from both targets that builds the final library file.

Both methods working but I ask if there is a more "correct" way to do this....

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: Build Static Library with different CC and CXX flags
« Reply #1 on: April 12, 2016, 05:26:36 pm »
Does the C++ Static lib depends on the C Static lib files?

If no, then the likely correct way is to have two Static lib.

If yes, I would try linking the C++ Static lib to the C Static lib and see if that works for you.

Any other correct way would likely need the Compiler info and use a post build step to merge the two static libs.
(That would NOT be on topic for this forum; but, if you find the proper Compiler command to merge two static libs and need help getting the post build step to work that would be on topic for this forum.)

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