我正在尝试使用GCC一起编译C和C++源代码.
gcc -std=c++0x test.cpp -std=c99 test.c -lstdc++
现在,这个工作正常,除了我得到两个警告.
cc1plus: warning: command line option "-std=c99" is valid for C/ObjC but not for C++
cc1: warning: command line option "-std=c++0x" is valid for C++/ObjC++ but not for C
Run Code Online (Sandbox Code Playgroud)
因此我无法使用-Werror
此设置.这些警告能以某种方式被抑制吗?
Eri*_*rik 52
单独编译文件,与g ++链接
gcc -c -std=c99 -o file1.o file1.c
g++ -c -std=c++0x -o file2.o file2.cpp
g++ -o myapp file1.o file2.o
Run Code Online (Sandbox Code Playgroud)
小智 15
如果有人想知道在Android中执行此操作的最佳方法,那就是:
LOCAL_CFLAGS := -Werror
LOCAL_CONLYFLAGS := -std=gnu99
LOCAL_CPPFLAGS := -std=c++0x
Run Code Online (Sandbox Code Playgroud)
gcc
是C编译器,g++
是C++编译器。您正在以不同的风格混合两种语言。分开编译然后链接:
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
Run Code Online (Sandbox Code Playgroud)