博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
windos下运用eclipse运行c/c++程序
阅读量:2402 次
发布时间:2019-05-10

本文共 5444 字,大约阅读时间需要 18 分钟。

总算成功了。尝试几次没成功,其原因是自己没有认真看文档

先到下载带有c/c++插件的eclipse 注意其中的插件只有cdt没有编译器,所以你的另外下载其他编译器,大家有必要看一下这段e文:   

》Use the utility for your platform to decompress the downloaded file onto your file system (Windows™ users, see this ).

》Eclipse IDE for C/C++ Developers does not contain a compiler or debugger; if your system does not have one, you need to download and install one. Please see the "" section of the C/C++ Development User Guide in the Help for more information (Click  for more information about C/C++ compilers and tools).

 

 

Windows

For windows, MinGW, and Cygwin are the two main choices for acquiring the GNU toolchain:

  • is a port of the Linux environment to Windows. It provides a compatibility layer in a set of DLLs. These DLLs are , making any code that links to them also subject to the GPL. Cygwin, however, does provide the fullest implementation of the GNU toolchain by supporting the GNU libc C runtime library.

     

  • is a port of the GNU toolchain to the Windows platform. The biggest difference over Cygwin is that MinGW uses the Windows C runtime libraries (mscvrt) instead of GNU's libc. As a result, a compatibility layer is not required, thus avoiding the GPL issues with Cygwin. There are differences, though, between the Windows and GNU C runtime libraries that will make writing portable applications more difficult.

    However, MinGW provides the best integration support with the CDT due to it's direct support for the Windows environment.

    The following are instructions and links on how to install the current version of MinGW. Note that these links may become inaccurate over time as new versions of MinGW components are introduced. Please check the section for the latest versions.

    1. Download and run the MinGW setup program, .
    2. Select download and install the MinGW base tools and the g++ compiler. You may select the Current or Candidate version of these tools. You may also install any of the other available compilers as well.

      Do not install the MinGW Make feature as the MSYS version of make from step 5 is a more complete implementation of make.

    3. The MinGW setup program currently does not install the gdb debugger. To install the debugger, download the file from the following location:
    4. Extract the contents of the file gdb-6.6.tar.bz2 to the same location where you installed MinGW.
    5. If you want to use Makefile projects, download and run the setup program from the following location: . MSYS provides an implementation of make and related command line tools. This is not required for other types of projects with the MinGW toolchain, which use CDT's internal build tools to perform the build.

运行MinGW-5.0.0.exe,选择MinGW base tools(C编译器),g++编译器,和MinGW Make三个包进行下载。其实安装文件是下载了下面几个文件包:

mingw-runtime-3.9.tar.gz w32api-3.6.tar.gz binutils-2.15.91-20040904-1.tar.gz gcc-core-3.4.2-20040916-1.tar.gz gcc-g++-3.4.2-20040916-1.tar.gz mingw32-make-3.80.0-3.tar.gz

如果通过安装程序下载速度很慢的话(一般是不快,呵呵),也可以单独在下载页面中的Current下面单独下载上述文件。

4) 将3中下载下来的所有包拷贝到同一个目录下面,比如C:/MinGW,然后解压缩到当前目录。这里可以使用WinRAR,如果遇到提示相同文件是否覆盖的时候直接选择“是”就可以了。

5) 设置下面的环境变量:

CPLUS_INCLUDE_PATH C:/MinGW/include/c++/3.4.2;C:/MinGW/include/c++/3.4.2/mingw32;C:/MinGW/include/c++/3.4.2/backward;C:/MinGW/include

C_INCLUDE_PATH C:/MinGW/include

LIBRARY_PATH C:/MinGW/lib

Path C:/MinGW/bin;%path%

.先在Command Line模式下测试编译与执行。先将C:/MinGW/bin底下的 mingw32-make.exe更名为make.exe,因为待会在Eclipse使用时它预设 会抓 系统make这个文件名而不是mingw32-make (注:如果不更名或是还有其它make程序时,也可以在稍后的Eclipse设定 中,在make targets view的地方,新增一个task时,build command 取消 use default , 使用 mingw32-make,或在project properties->make project -> make 改为 mingw32-make ) -- snpshu补充。 在环境变量里加入下列设定: PATH C:/MinGW/bin; (如果系统已经有装其它C/C++编译器,请把C:/MinGW/bin加在最前面。) LIBRARY_PATH C:/MinGW/lib C_INCLUDE_PATH C:/MinGW/include CPLUS_INCLUDE_PATH C:/MinGW/include/c++/3.2.3;C:/MinGW/include/c++/3.2.3/mingw32; C:/MinGW/include/c++/3.2.3/backward;C:/MinGW/include 先使用文字编辑器编写测试用的原始档,档名:main.cpp

1 2 3 4 5 6 7 8
#include <iostream>
using namespace std;
 
int
main(
void
)
{
    cout <<
"Can You Feel My World
"
;
 
   
return
0;
}

Command Line
下编译指令:

1
C:/g++ main.cpp -O3 -o hello

(O3
O
是英文大写
"
")
编译成功后:便会产生
hello.exe
的执行档。
执行画面如下:

1 2 3 4 5 6 7 8 9 10
Microsoft Windows XP [
版本
5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
 
C:/Documents and Settings/Sungo>cd/
 
C:/>g++ main.cpp -O3 -o hello
 
C:/>hello
Can You Feel My World
C:/>

注:
-O3
旗标表示采最高级编译最佳化,编译速度最慢,但产生的执行档
档案会最小,执行速度会最快;
-o
旗标表示将编译完的
*.exe
重新更名。
步骤一
.
开启
Eclipse
后,首先先开启
C/C++
专用视景。
Windows->Open Perspective->C/C++ Development
步骤二
.
建立一个
C++
用的 项目
File-New->Project->C++->Standard Make C++ Project
(
接下来的步骤跟建立一般的
Java
项目一样,皆采预设即可
)
步骤三
.
把我们刚刚写的
main.cpp import
进来,加到专案里。
File->Import->File System->
浏览
C:/main.cpp
步骤四
.
建立一个
makefile
File->New->File
,文件名称填:
makefile
(
不需打扩展名
)
makefile
内容如下:

1 2
all:
    g++ main.cpp -g -o run

注意:
makefile
缩排要以
Tab
键作缩排,不能以空格
4
作缩排,
否则
Build
会有问题。
步骤五
.
设定
Make Targets
Windows-Show View->Make Targets
Make Targets
窗口里按 鼠标 右键,
Add Build Target
name
打:编译。
Build Target
打:
all
步骤六
.
编译。
在刚刚建立的
Make Targets "
编译
"
上点鼠标
2
下,即会开始编译,
此时我们可以发现
hello.exe
已经产生在我们项目下了。可在底下
C-Build
窗口看到以下输出结果:

1 2
make -k all
g++ main.cpp -g -o run

步骤七
. *.exe
执行前设定。因为在
Windows
Run
,所以要先作个设定
,请开启
Project->Properties->C/C++ Make Project->Binary Parser
页面。
Binary Parser
下拉式选单,将
ELF Parser
改成
PE Windows Parser
步骤八
.
执行。
Run->Run as->C Local Application
在底下
Consloe
窗口看到
hello.exe
的执行结果。
注:当原始档有 修改 ,要重新编译时,只要鼠标双击我们在步骤五
所建立的
Make Targets "
编译
"
,即可
Rebuilding

转载地址:http://dipob.baihongyu.com/

你可能感兴趣的文章
Linux中的C语言妙用(转)
查看>>
ConfiguringanHP-UXKernel(转)
查看>>
微软重大补丁(转)
查看>>
圣彼得的新安排(转)
查看>>
iptables应用之动态DNS(转)
查看>>
单网卡redhat 7.2利用iptables作为简单网关的配置(转)
查看>>
CVS使用简介(转)
查看>>
CVS教學(转)
查看>>
Linux下FrameBuffer直接写屏(转)
查看>>
游戏设计制作中对锁定设置的应用(转)
查看>>
漏洞遭披露思科提起诉讼要求封口(转)
查看>>
从社会软件看游戏设计的个性特色(转)
查看>>
看传奇老化问题重思网络游戏企划(转)
查看>>
05全国网络与信息安全技术研讨会召开(转)
查看>>
通过例子学习Lua(4)--函数的调用(转)
查看>>
自己研究的一个场景物体剔除方法(转)
查看>>
通过例子学习Lua(3)----Lua数据结构(转)
查看>>
用OpenGL实现射线拣取对象程序设计(转)
查看>>
四大银行联手金山毒霸重拳出击(转)
查看>>
通过例子学习Lua(2)---Lua流程控制(转)
查看>>