Can I mix c and cpp files in a C++ project?
c, c++, linker
Solution
`extern "C"` is one approach. The other approach, assuming your C files are of the (almost ubiquitous) sort which are already compilable as C++, is simply to coerce the compiler into treating them as C++ (which gives them the appropriate name mangling to work with your C++ files). For GCC, this is `-x c++`.
Problem
I have a project that had c files and cpp files mixed in it. The linker throws errors at me: ``` undefined reference to <all my functions in the c files> ``` After I rename all `*.c` files to `*.cpp` the errors vanish. So can't I mix those files or is this some compiler/linker options problem? My options: GCC C++ Compiler: ``` -I/usr/include/glib-2.0 -I/usr/include/gtk-2.0 -I"/myPath" -O0 -g3 \ -Wall -c -fmessage-length=0 `pkg-config --cflags glib-2.0 gtk+-2.0 ``` GCC C Compiler: ``` -I/usr/include/glib-2.0 -I/usr/include/gtk-2.0 -I"/myPath" -O0 -g3 \ -Wall -c -fmessage-length=0 -std=c99 `pkg-config --cflags glib-2.0 gtk+-2.0` ``` GCC C++ Linker: ``` -L/usr/include/glib-2.0/glib `pkg-config --libs gtk+-2.0` ``` Since it says C++ Linker, does that mean object files from c files cannot be linked into the project (by default)?