Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: pozzugno on November 08, 2013, 07:57:02 pm

Title: Two projects that use a library but compiled in two different ways
Post by: pozzugno on November 08, 2013, 07:57:02 pm
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?
Title: Re: Two projects that use a library but compiled in two different ways
Post by: Jenna 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).
Title: Re: Two projects that use a library but compiled in two different ways
Post by: pozzugno 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.
Title: Re: Two projects that use a library but compiled in two different ways
Post by: stahta01 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.
Title: Re: Two projects that use a library but compiled in two different ways
Post by: Jenna 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.