mixed c and c++
I have to mix c-sources and c++-sources in a linux project.
How can I do it?
I had tried to compile them seperatly. The c-files with the gcc and the cpp files with g++.
After that I link all files with g++ together. By that it doesn't find the calls coming from c++-sources to c-functions.
Depends, to some extent, on the C.
If all you're looking to do is call some C functions from C++, provide a header file that declares all the C functions you wish to call from C++, qualified as extern "C", and #include that in all of your C++ source files that need to call the C functions. Then you can compile the C files using gcc and the C++ files using g++. You will need to link using the g++ driver, not the gcc driver.
An alternative approach is to compile all of the c files using g++, and then link (using the g++ driver, just as you would if linking object files compiled as C++). This is likely to work since a large proportion of C is a subset of C++. There are some exceptions (eg C99 features like variable-length arrays are not part of C++) though. Note also that C++ compilers are pickier than C compilers on some things.
Note that, if you intend to call C++ functions from C code, or make use of C++ classes in C, you cannot compile as C at all, and will need to compile as C++ (any code that uses a C++ feature must be treated as C++ code, even if everything else in the source file is C).
Thanks a lot,
I just surround the header-includes of the c-headers with and it works. Thanks a lot