简体   繁体   English

Eclipse无法使用gcc编译* .C

[英]Eclipse doesn't compile *.C with gcc

I am using Eclipse Kepler and running it under Win7 64-Bit. 我正在使用Eclipse Kepler并在Win7 64位下运行它。 As compiler I use the gcc (4.8.1) from MinGW. 作为编译器,我使用MinGW的gcc(4.8.1)。 Now I have the following problem: 现在我有以下问题:

//edit: Reformulated question to make it more clear // edit:重新设计的问题以使其更清楚

I have a project containing of one source-file with C-Code: main.c 我有一个项目,其中包含一个带有C代码的源文件: main.c

This file can be compiled over 2 ways: 该文件可以通过2种方式进行编译:

  1. Start the compiler over the command-line: gcc -o main.exe main.c 通过命令行启动编译器: gcc -o main.exe main.c
  2. Start the compiler over Eclipse by starting the normal build-routine (which also calls the gcc ) 通过启动正常的构建例程(也称为gcc ),通过Eclipse启动编译器。

Now for some reason I want to add some C++-Code, but I still want to compile it with the gcc . 现在由于某种原因,我想添加一些C ++代码,但是我仍然想使用gcc对其进行gcc

The gcc itself decides how to compile over the file extension - This means, if main.c contains C++-Code and I call gcc -o main.exe main.c it won't work. gcc本身决定如何通过文件扩展名进行编译-这意味着,如果main.c包含C ++代码,并且我调用gcc -o main.exe main.c ,它将无法正常工作。 To make the compiler realize it's C++ I have to change the file-extension to somthing like .C or .cpp and then it will work. 为了使编译器意识到它是C ++,我必须将文件扩展名更改为.C.cpp ,然后它才能工作。

Now back to Eclipse: 现在回到Eclipse:

When I change my Sourcefile to main.C Eclipse interprets it as C++ File, meaning it changes the Code-Highlighting. 当我将源文件更改为main.C Eclipse会将其解释为C ++文件,这意味着它将更改代码突出显示。 When I now start a build process over Eclipse it just tells me 现在,当我通过Eclipse启动构建过程时,它只是告诉我

Info: Nothing to build for PROJECT

This means there is not even a call to the gcc -compiler. 这意味着甚至没有调用gcc -compiler。 My guess is, that Eclipse somehow doesn't want to call the gcc, because the source-file is marked as C++-File. 我的猜测是,Eclipse某种程度上不想调用gcc,因为源文件被标记为C ++-File。

//edit2: Just tried - when I have a C++-Projekt Eclipse just ignores the *.C or the *.cpp -files. // edit2:刚刚尝试过-当我有C ++-Projekt时,Eclipse只会忽略*.C*.cpp .cpp-文件。 I guess I have to add them manually, so they're built too ... but where? 我想我必须手动添加它们,所以它们也是内置的...但是在哪里?

The g++ is the compiler to compile C++ codes. g++是用于编译C++代码的编译器。
Change you compiler in you eclipse project. 在Eclipse项目中更改编译器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM