Code::Blocks Forums
User forums => Embedded development => Topic started by: eckard_klotz on July 31, 2012, 02:59:13 pm
-
Hello All.
My original project is written in c. Normaly I use Microchip MPLAB for compiling and CodeBlocks just to edit the sources. Thus I had never problems in the past. But now I started to use UnitTest++ (like described by Killerbot in his tutorial) and this is written in c++.
Originaly all my sources have the attachment ".c" and in the advanced file-property a "CC" is set. The new sources used to define the tests are written in c++ have the attachment ".cpp" and the advanced file-property a "CPP".
If I build this with the default GNU-MINGW compiler (gcc) all sources will be compiled. But the linker is not able to use the content of the c-objects.
So I have to change the advanced file-property from "CC" to "CPP". Then the c-files will be compiled as c++ files and the linker is able to use the object-files. But for some reasons the compiler finds in the c++ mode some errors wich will not be seen in the c-mode. At the end it may be a good idea to solve those problems by changing the problematic parts of the sources but since this project is an older one I have to do this step by step to be able to check if the target-system (a dsPIC microcontroler )is still working as before or has with some of those changes problems.
My question is now if it is possible to keep the advanced file-property a "CC" for the c-sources so that they are compiled in c-mode but to tell the linker to use this together with the test-file objects created from c++ sources. Is there a possibility to configure this in the build-options?
Best regards,
Eckard Klotz.
-
One way to fix this problems is to make your c header file c++ compatible, by using extern "C" if __cplusplus is defined.
See here for example: http://developers.sun.com/solaris/articles/mixing.html
-
Hello.
Thank You for the fast reply. It was great help especialy this:
extern "C" {
#include "header.h"
}
Once I used this aruond my c-header includes in my "test.cpp" I was able to configure the advanced file-property back to "CC" again and it works.
Best Regards,
Eckard.