设置Eclipse C ++编译器,而不自动安装或更改Windows上的系统路径 [英] Set up Eclipse C++ compiler without auto-install or altering System Path on Windows

查看:800
本文介绍了设置Eclipse C ++编译器,而不自动安装或更改Windows上的系统路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Eclipse上安装一个C ++编译器,而不改变路径变量,因为我不能,机器有限的权限。 Eclipse显然运行良好,它的生成不是,它抱怨。



我注意到的第一件事是一个警告,说Unresolved包含的libary文件stdio.h



我在Eclipse的Windows> Preferences> C / C ++> Environment中添加了一个路径变量,名为Path的新环境变量, minGW / bin文件夹,但无效。我还尝试将其设置为用指定的一个替换本机环境变量,但也没有变化。



生成错误说:

  ****警告:默认配置可能不生成**** 
****,因为它使用MinGW GCC ****
****此系统不支持的工具链。 ****

,然后

 (无法运行程序make:启动失败)

当然没有更多。这是一个简单的Hello World测试,所以代码不应该是一个问题。我可以看到Eclipse生成的包括区域(D:\MinGW\binutils\lib)中的一个文件夹下的包含,但在Eclipse的Outline选项卡中单击它会出现错误找不到包含文件。

解决方案

看起来你正在尝试使用Eclipse / CDT构建一个简单的hello world程序,一个开发环境和使用mingw作为编译工具链。我能够得到这个工作,只是现在没有修改我的系统路径环境变量。这是我做的:




  • 我已经安装了Eclipse 3.5(Galileo)CDT

  • 安装MinGW到C:\MinGW(我假设你已经这样做)。确保mingw-make组件已安装(默认情况下不安装,我不得不选中框来安装此组件)。

  • 创建一个新的空makefile项目,添加main.c ,写hello世界代码(因为你说这不是问题所以我跳过细节在这里),添加一个新的文件称为makefile并填写。



我的main.c文件的内容

  #include 
int main )
{
printf(Hello World!);
return 0;
}

我的makefile的内容:

  all:
gcc -o HelloWorld.exe main.c




  • 打开项目属性;在C / C ++ Build下,取消选中使用默认构建命令,并将构建命令更改为mingw32-make。

  • 在C / C ++ Build /在路径中的C:\Mingw\bin

  • 在C / C ++常规/路径和符号下,将C:\mingw\inc添加为包含路径。 li>


这样做后,我的项目成功构建并在我的项目中生成了HelloWorld.exe。



另一个不需要为系统或项目属性添加PATH变量,或者添加项目属性的include路径的选项,只是给makefile中的命令提供完整的路径信息。对于小项目,这是可控的。下面是一个例子makefile:



makefile的内容:

  all: 
c:\mingw\bin\gcc -o HelloWorld.exe -I c:\mingw\include main.c

当然,你也必须将build命令从简单的mingw32-make更改为C:\mingw\bin \mingw32-make。 / p>

这种方法的另一个缺点是,CDT代码解析器将无法找到包含文件,因此您在编辑器中会出现警告。


I am trying to install a C++ compiler on Eclipse without altering the Path variables as I can't, the machine has limited rights. Eclipse obviously runs fine, it's the build that doesn't, it complains about.

The first thing I noticed was a warning that said "Unresolved inclusion" for the libary file stdio.h

I added the path variable inside Eclipse's "Windows > Preferences > C/C++ > Environment" with a new environment variable named "Path" with a path to my minGW/bin folder but to no avail. I also tried setting it to "Replace the native environment variable with specified one" but also no change.

The build errors out saying:

****  WARNING: The "Default" Configuration may not build  ****
****  because it uses the "MinGW GCC"  ****
****  tool-chain that is unsupported on this system.  ****

and then

(Cannot run program "make": Launching failed)

And of course no more. It's a simple Hello World test, so the code shouldn't be an issue. I can see the includes under a folder in the "Includes" area that Eclipse generates (D:\MinGW\binutils\lib) but clicking on them in the Outline tab of Eclipse brings up the error "No include files were found that matched that name".

解决方案

It looks like you're trying to build a simple hello world program using Eclipse/CDT and a development environment and using mingw as the compiler tool chain. I was able to get this working just now without modifying my system path environment variable. This is what I did:

  • I already had Eclipse 3.5 (Galileo) installed with CDT
  • Installed MinGW to C:\MinGW (I assume you already had this done). Make sure the mingw-make component is installed (it's not installed by default, I had to check the box to install this component).
  • Create a new empty makefile project, add main.c, write hello world code (as you say this isn't the problem so I'm skipping detail here), add a new file called "makefile" and fill it in.

Contents of my main.c file

    #include   
    int main()  
    {  
        printf("Hello World!");  
        return 0;  
    }  

Contents of my makefile:

    all:  
        gcc -o HelloWorld.exe main.c 

  • Open the project properties; Under C/C++ Build uncheck the "use default build command" and change the build command to "mingw32-make".
  • Under "C/C++ Build/Environment" add a new PATH variable with C:\Mingw\bin in the path
  • Under "C/C++ General/Paths and Symbols" add C:\mingw\include as an include path.

After doing this, my project built successfully and produced a HelloWorld.exe exectuable in my project.

Another option that doesn't require adding a PATH variable to the system or project properties, or adding the include path to the project properties is to simply gives full path info to the commands in the makefile. For small projects this is manageable. Here's an example makefile:

Contents of makefile:

    all:  
        c:\mingw\bin\gcc -o HelloWorld.exe -I c:\mingw\include main.c 

Of course you'll also have to change the build command from simply "mingw32-make" to "C:\mingw\bin\mingw32-make" as well.

Another downside of this approach is that the CDT code parser will not be able to locate include files so you'll have warning in the editor to that effect.

这篇关于设置Eclipse C ++编译器,而不自动安装或更改Windows上的系统路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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