News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

Compiler selection for single file

Started by pizikata, July 17, 2009, 12:30:27 PM

Previous topic - Next topic

pizikata

I want to compile a single source file (with .c extension), without creating a project.
When I build via C::B the executable, the global compilation options defined in Settings -> Compiler and debugger are taken into account, as expected.

However, sometimes the C compiler gcc is used (as I wish),  sometimes it is the C++ compiler g++ ... I don't know why.
Is there a way to set up which compiler is used?

Thanks

Configuration: C::B 8.02 (on ubuntu) with the GCC 4.3.3 compiler.

pizikata

#1
I have investigated further my problem.

It appears on my Ubuntu distribution that when the path of the single source file contains blanks, for example if the path of my file (denoted as main.c) is
~/My Directory/main.c
then g++ is called.

Conversely, if the same file is moved into a directory where there is no blank character, for example:
~/My_Directory/main.c
then the C compiler gcc is used...

Is it a normal behavior with codeblocks, or should it be considered as a bug?

Furthermore, consider single files, i.e. which are not part of a project, and with .c extensions. Which is the default command between gcc and g++ when GCC is set as the default compiler in the C::B settings?







pizikata

#2
I found a workaround by setting the following flag in the compiler options (Compiler Settings -> Other options) with GCC:
-x none

This GCC flag turns off any specification of a language. As a consequence source files are handled according to their file name suffixes *.c
correspond to C files, whereas *.C, *.cc, *.cpp, *.CPP,... stand for C++ files). So, even if the command g++ is invoked,  *.c files are compiled with the C compiler (and not the C++ one).

However, if there is a way to set up which command (gcc or g++) is used for single files, I am still interested!


Jenna

Normally C::B treats *.c files as c-source-code and uses gcc.

I guess the problem comes because of the whitespace, C::B adds quotes around the filename in this case.

It might be that it looks for the extension after adding quotes and in this case wxWidgets possibly returns the wrong extension (c" instead of c).

I will have a look into this issue later.