0

How can I link plain c and c++ code together using gcc and g++. I tryed this:

g++ -c test.c #C++ source;
gcc -c main.c test2.c #Plain c source;
g++ main.o test.o test2.o -o main.exe

And this: Compiling C and C++ files together using GCC

But application doesn't see any functions from C-source files.

main.c: undefined reference to `mainWndInit'
Community
  • 1
  • 1
  • Do you use `extern "C"` to declare the C++ function that's called from C? – Barmar Dec 21 '14 at 08:57
  • Are you sure that your C functions are imported via extern "C" in your C++ code ? – Jean-Baptiste Yunès Dec 21 '14 at 08:57
  • Note that you do not have to use gcc and g++ separately; both will automatically use C or C++ compilation depending on the extension. They are in fact identical except that g++ when used as a linker driver, links libstdc++ by default. You could of course call invoke the linker (ld) directly rather than using g++. – Clifford Dec 21 '14 at 09:14

0 Answers0