Author Topic: Two projects that use a library but compiled in two different ways  (Read 4643 times)

Offline pozzugno

  • Multiple posting newcomer
  • *
  • Posts: 39
I'm designing a library that can be compiled in two different modes depending on the definition of MODE1 or MODE2.

In order to test the two variants, I created two projects in Code::Blocks that use the same source files for the library.
Project1 is configured with -DMODE1 and Project2 is configured with -DMODE2.

If a make Project2 after making Project1, the library isn't compiled another time and is wrongly linked to the executable
in MODE1. The solution I use is to Rebuild Project2 to force the compilation of the library.

Is there a better method?

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7252
Re: Two projects that use a library but compiled in two different ways
« Reply #1 on: November 08, 2013, 08:24:23 pm »
I woule prefer to have the sources in one project not two, but use two differebt targets for the different modes.
And make sure every lib (egally if in project or target) has it's own object folder, probably executable dir and own place for the build lib (or two different names for the libs).

Offline pozzugno

  • Multiple posting newcomer
  • *
  • Posts: 39
Re: Two projects that use a library but compiled in two different ways
« Reply #2 on: November 08, 2013, 10:53:05 pm »
Quote
I woule prefer to have the sources in one project not two, but use two differebt targets for the different modes.
I see two problems with your solution. If I change something in the library (and it often happens because I'm developing the library), I have to recompile the project for two targets, but it seems there isn't a friendly "Make All the Targets" command. I would have to compiler the first target, switch to the second target and compile again.

Quote
And make sure every lib (egally if in project or target) has it's own object folder, probably executable dir and own place for the build lib (or two different names for the libs).
I know how to change the folder for the output executable file of the project, but I don't know how to change in Code::Blocks the object of a single .c file destination folder or the destination folder for all the sources.

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7695
    • My Best Post
Re: Two projects that use a library but compiled in two different ways
« Reply #3 on: November 08, 2013, 10:57:50 pm »
Edit: Look-up Virtual Targets; name one "All" and add both targets to them.

Change the Object Output Directory for each Target.

Project -> Property -> Build Targets

Tim S.
« Last Edit: November 08, 2013, 11:10:33 pm by stahta01 »
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: 7252
Re: Two projects that use a library but compiled in two different ways
« Reply #4 on: November 08, 2013, 11:03:08 pm »
In "Project -> Properties -> Build targets" you can set the "Objects output dir" per target.
Here you can also create a "Virtual target" and add both real targets to it.
If you chose the virtual target in the combobox, all related targets wil be (re-)build.