Compiling C and C++ files together using GCC

后端 未结 6 930
[愿得一人]
[愿得一人] 2020-12-07 16:38

I\'m trying to compile C and C++ sources together using GCC.

gcc -std=c++0x test.cpp -std=c99 test.c -lstdc++

Now, this works fine, except that

6条回答
  •  粉色の甜心
    2020-12-07 17:17

    gcc is the C compiler and g++ is the C++ compiler. You are mixing the two languages with different styles. Compile apart and then link:

    gcc -std=c99 -c -o test.c.o test.c
    g++ -std=c++0x -c -o test.cpp.o test.cpp
    g++ -o executable test.cpp.o test.c.o
    

提交回复
热议问题