编译C和C ++文件一起使用GCC [英] Compiling C and C++ files together using GCC

查看:351
本文介绍了编译C和C ++文件一起使用GCC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图编译C和C ++源一起使用GCC。

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 I get two warnings.

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

所以我不能使用 -Werror 与此设置。这些警告可以燮$ P $莫名其妙pssed?

Therefore I can't use -Werror with this setup. Can these warnings be suppressed somehow?

推荐答案

单独编译的文件,使用g ++链接

Compile the files separately, link with 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

这篇关于编译C和C ++文件一起使用GCC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆