Allow different compilers in a single project

Discussion about CodeLite development process and patches
RJP Computing
CodeLite Enthusiast
Posts: 10
Joined: Tue Sep 02, 2008 7:48 pm
Contact:

Allow different compilers in a single project

Post by RJP Computing »

Is there a way to invoke another compiler that is different then the entire project?

Here is my example. I have a C++ project, but I have one file in the project that is just C and CodeLite is compiling it with g++. This is not what I expected and was wondering if this can be changed to allow what compiler is used to be set on a file level.

Thanks.
--
Regards,
Ryan
User avatar
eranif
CodeLite Plugin
Posts: 6375
Joined: Wed Feb 06, 2008 9:29 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: Allow different compilers in a single project

Post by eranif »

Hi Ryan,

When u choose compiler for a project what it actually does it sets the $(CompilerName) variable to be the selected compiler.

Which is then replaced when creating the build rules for the makefile.

To override this behavior, i.e. to set a different compiler do this:
- assuming that you are using 'gnu g++' compiler
- open the compiler settings from: settings -> build settings -> compilers tab
- select the 'File Type' entry for the selected compiler
- replace the line for the 'C' extension from

Code: Select all

$(CompilerName) $(SourceSwitch) "$(FileFullPath)" $(CmpOptions) $(ObjectSwitch)$(IntermediateDirectory)/$(FileName)$(ObjectSuffix) $(IncludePath)
to

Code: Select all

gcc $(SourceSwitch) "$(FileFullPath)" $(CmpOptions) $(ObjectSwitch)$(IntermediateDirectory)/$(FileName)$(ObjectSuffix) $(IncludePath)
This will invoke the 'C' compiler for 'C' files.

Eran
Make sure you have read the HOW TO POST thread
RJP Computing
CodeLite Enthusiast
Posts: 10
Joined: Tue Sep 02, 2008 7:48 pm
Contact:

Re: Allow different compilers in a single project

Post by RJP Computing »

Perfect!

Do you think this could/should be set by default. There is hardly a time, that I can think of, to treat C files as C++.
--
Regards,
Ryan
User avatar
eranif
CodeLite Plugin
Posts: 6375
Joined: Wed Feb 06, 2008 9:29 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: Allow different compilers in a single project

Post by eranif »

By keeping $(CompilerName) you allow users to use the value set in the tools chain.

Eran
Make sure you have read the HOW TO POST thread
RJP Computing
CodeLite Enthusiast
Posts: 10
Joined: Tue Sep 02, 2008 7:48 pm
Contact:

Re: Allow different compilers in a single project

Post by RJP Computing »

eranif wrote:By keeping $(CompilerName) you allow users to use the value set in the tools chain.

Eran
I agree, but if you have a program that has both C and C++ source what are you suppose to do in a multi-user case. It seems hard for me to tell my team to set this setting each time they install CodeLite. To make this clearer, if I have an Open Source project that uses CodeLite then any number of developers will need to set this before being able to build that application.
--
Regards,
Ryan
User avatar
eranif
CodeLite Plugin
Posts: 6375
Joined: Wed Feb 06, 2008 9:29 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: Allow different compilers in a single project

Post by eranif »

RJP Computing wrote:It seems hard for me to tell my team to set this setting each time they install CodeLite
Once installed and changed codelite will not modify your settings even after upgrade. The settings are saved into the user settings and those are not modified by the installer so it is really a one time mission.
You could add this line to the wiki of your OS project:
...
- install codelite
- change $(CompilerName) to gcc for 'C' extension
...
Eran
Make sure you have read the HOW TO POST thread
Post Reply