eclipse配置c開發環境


 

eclipse配置c開發環境

1 eclipse配置c開發環境

 

1.1 緣起

公司同事需要開發c語言,想要配置一個開發環境,考慮使用eclipse+cygwin gcc開發,因 此幫着配置了開發環境。機器配置:win10,4G。

首先,Windows下用eclipse玩c用到一下三個東西:

  1. cygwin(Windows平台的unix模擬程序,包含了gcc和g++)
  2. eclipse

1.2 cygwin

cygwin搜索官方網站下載安裝程序,選擇64位的,打開安裝程序setup-x86_64.exe,然后選 install from internet,接着選擇存放位置,打開翻_牆(不翻_牆下載會很慢),進入下載列 表,這個列表就是要求你下載什么程序的列表,請務必安裝以下程序,務必安裝: gcc-core,gcc-g++,make,gdb,binutils;可以參考: http://www.linuxidc.com/Linux/2011-06/37588.htm

將cygwin安裝目錄\bin加入到環境變量PATH中。好了,開個cmd命令行窗口,分別試一下gcc -v, make -v,gdb -v命令。

$ gcc -v
使用內建 specs。
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-cygwin/5.4.0/lto-wrapper.exe
目標:x86_64-pc-cygwin
配置為:/cygdrive/i/szsz/tmpp/gcc/gcc-5.4.0-1.x86_64/src/gcc-5.4.0/configure --srcdir=/cygdrive/i/szsz/tmpp/gcc/gcc-5.4.0-1.x86_64/src/gcc-5.4.0 --prefix=/usr --exec-prefix=/usr --localstatedir=/var --sysconfdir=/etc --docdir=/usr/share/doc/gcc --htmldir=/usr/share/doc/gcc/html -C --build=x86_64-pc-cygwin --host=x86_64-pc-cygwin --target=x86_64-pc-cygwin --without-libiconv-prefix --without-libintl-prefix --libexecdir=/usr/lib --enable-shared --enable-shared-libgcc --enable-static --enable-version-specific-runtime-libs --enable-bootstrap --enable-__cxa_atexit --with-dwarf2 --with-tune=generic --enable-languages=ada,c,c++,fortran,lto,objc,obj-c++ --enable-graphite --enable-threads=posix --enable-libatomic --enable-libcilkrts --enable-libgomp --enable-libitm --enable-libquadmath --enable-libquadmath-support --enable-libssp --enable-libada --enable-libgcj-sublibs --disable-java-awt --disable-symvers --with-ecj-jar=/usr/share/java/ecj.jar --with-gnu-ld --with-gnu-as --with-cloog-include=/usr/include/cloog-isl --without-libiconv-prefix --without-libintl-prefix --with-system-zlib --enable-linker-build-id --with-default-libstdcxx-abi=gcc4-compatible
線程模型:posix
gcc 版本 5.4.0 (GCC)

$ make -v
GNU Make 4.2.1
為 x86_64-unknown-cygwin 編譯
Copyright (C) 1988-2016 Free Software Foundation, Inc.
許可證:GPLv3+:GNU 通用公共許可證第 3 版或更新版本<http://gnu.org/licenses/gpl.html>。
本軟件是自由軟件:您可以自由修改和重新發布它。
在法律允許的范圍內沒有其他保證。


GNU gdb (GDB) (Cygwin 7.10.1-1) 7.10.1
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-pc-cygwin".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".

1.3 eclipse

先安裝jdk1.8,在eclipse官網下載c++開發ide,eclipse-cpp-neon-1-win32-x8664,打開 eclipse,win10下報錯:could not create the Java Virtual Machine,經過查找發現找 不到jdk路徑,可能是win10的問題,因此對eclisp根目錄下的eclipse.ini進行修改:

-startup
plugins/org.eclipse.equinox.launcher_1.3.200.v20160318-1642.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_64_1.1.400.v20160518-1444
-product
org.eclipse.epp.package.cpp.product
--launcher.defaultAction
openFile
-showsplash
org.eclipse.platform
--launcher.defaultAction
openFile
--launcher.appendVmargs
-vmargs
-Dosgi.requiredJavaVersion=1.8
-XX:+UseG1GC
-XX:+UseStringDeduplication
-Dosgi.requiredJavaVersion=1.8
-Xms256m
-Xmx1024m

在最前面加上路徑

-vm
c:\Programs\jdk1.8\bin
-startup
plugins/org.eclipse.equinox.launcher_1.3.200.v20160318-1642.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_64_1.1.400.v20160518-1444
-product
org.eclipse.epp.package.cpp.product
--launcher.defaultAction
openFile
-showsplash
org.eclipse.platform
--launcher.defaultAction
openFile
--launcher.appendVmargs
-vmargs
-Dosgi.requiredJavaVersion=1.8
-XX:+UseG1GC
-XX:+UseStringDeduplication
-Dosgi.requiredJavaVersion=1.8
-Xms256m
-Xmx1024m

1.4 配置

新建一個c項目,選擇cygwin gcc,建立c工程,項目右鍵Properties->C/C++, Build->toolchain 中確定:

o_eclipse-c01.png

Current toolchain = Cygwin Gcc
Current builder = Gnu Make Builder

Used tools 有:
GCC Assembler,
GCC Archiver,
Cywgin C++ Compiler,
Cywgin C Compiler,
Cywgin C Linker,
Cywgin C++ Linker。

最后將Display compatible toolchains only選中

o_eclipse-c02.png

按理來說這個時候點擊運行就可以編譯鏈接程序了,但是出現錯誤,但這里只會編譯鏈接, 但不會運行,也不會調試程序,我們還得手動做個簡單的配置:

o_eclipse-c03.png

o_eclipse-c04.png

進入debug configuration對話框,選擇C/C++application->test debug,點擊Browse…按 鈕,選擇選擇剛才編譯出來的exe文件,debug/test.exe,在點擊run或debug按鈕,ok了。

o_eclipse-c05.png

o_eclipse-c06.png

o_eclipse-c07.png

Created: 2016-10-11 周二 12:34

Emacs 25.1.1 (Org mode 8.2.10)

Validate


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM