User forums > Using Code::Blocks
build issue
jomeggs:
If you have a mix of .c and .cpp files, there is another way. Right click your .c file in your CB project, select "Properties" and afterwards the "Advanced" tab. Set the "Compiler variable" field to CC for .c for standard C or CPP for C++.
thomas:
The only acceptable solution to the apparent problem of including this header from a .c file is not to do it.
Name files properly to solve the problem instead of working around it, and don't even think about tampering with toolchain executables or changing individual file properties. This will only, in the average case, cause more problems, for example when you try to compile entirely legal third party C programs.
oBFusCATed:
A year ago, I had to work on a pure C project.
I had created (I think) a console project, than in the wizard I had chosen that the project is C, not C++.
Than every time I had added a file (through ctrl + shift(alt) + n) it was considered a C++ file, not C.
The way I had it fixed: choose the file in the tree -> properties -> switch the type of the file in the dialog
I don't know if this is a known and fixed problem, I will check it tonight, when I get home.
Edit:
I've done a test -> created console c project and added a file, the compiler is correctly chosen, but g++ is used for linking
Here is the full log
--- Code: ---gcc -Wall -g -Werror=return-type -Woverloaded-virtual -c /home/obfuscated/projects/tests/test_c_proj/main.c -o .obj/Debug/main.o
gcc -Wall -g -Werror=return-type -Woverloaded-virtual -c /home/obfuscated/projects/tests/test_c_proj/test.c -o .obj/Debug/test.o
g++ -o bin/Debug/test_c_proj .obj/Debug/main.o .obj/Debug/test.o
cc1: warning: command line option "-Woverloaded-virtual" is valid for C++/ObjC++ but not for C
cc1: warning: command line option "-Woverloaded-virtual" is valid for C++/ObjC++ but not for C
Output size is 10,04 KB
--- End code ---
Is that correct? I'm on linux 64bit gcc 4.3.3.
Maybe the GCC compiler should be split in two GCC C and GCC C++ compiler...
Sphere:
--- Quote from: jomeggs on June 10, 2009, 12:01:20 pm ---If you have a mix of .c and .cpp files, there is another way. Right click your .c file in your CB project, select "Properties" and afterwards the "Advanced" tab. Set the "Compiler variable" field to CC for .c for standard C or CPP for C++.
--- End quote ---
Good Morning,
I also have a project that contains both C and C++ files, however, I get linker errors when I call functions from the C files in classes defined in the C++ files. The only workaround I have found so far is to make both C and C++ files use the CPP compiler variable. What I would like to know is whether this is a Codeblocks issue, or MinGW issue, since it does not make sense (to me) to have to manually switch the compiler for each C file I add to my C++ project which uses both C and C++ code.
The reason I ask this is because I develop C code for embedded systems but often want to interface with the system using some sort of PC based software which uses common C files between both projects.
System Details: Codeblocks svn 5535 (though I have had this problem from at least 8.02); MinGW - all versions I have tried including the version that comes with 8.02, TDM's gcc builds with GCC 4.4.0 and 4.4.1; Windows XP, Vista and 7.
Thanks for any insight,
Chris
oBFusCATed:
You need to surround your C headers with
--- Code: ---#ifdef __cplusplus
extern "C" {
#endif
Your code
#ifdef __cplusplus
}
#endif
--- End code ---
Name mangling in C and CPP is diffrent, with this you tell the c++ compiler that the files are C files and he knows what to do.
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version