何以解忧?唯有Java

其实程序员也懂得浪漫!
posts - 90, comments - 637, trackbacks - 0, articles - 2
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

安裝 Cygwin 配合 NetBeans 編輯 C/C++

在 NetBeans 中,我們要編輯 C/C++ 除了要安裝 Plugin 外,還要安裝 C/C++ Compiler。
下方的例子是使用 Cygwin 和 NetBeans 來達成我們的需求:

首先,當然是安裝 Cygwin  ( Windows 平台上的一種 Unix 環境 )

網址:http://www.cygwin.com/

點擊,如下方的圖示下載安裝檔



請選擇下一步



這邊我們使用從網路安裝 (預設)



若干的設定如下圖,大部份的人比較會動到安裝的位置
在這裡我安裝在 d:" cygwin下方:



接著給他一個,放置下載檔案的位置:



選擇連結到網路的方式



設定從那邊下載檔案,要選好自己國家或是速度較快的位置
不然你可能要等上老半天......



等待他下載安裝的資訊。



選擇要安裝的 packages



在這邊我把右上的 view 點至切換成 Full 來檢視 packages
這樣,我們可以依字母的排列來找到要安裝的 package 及說明
如下圖:




然後,我們安裝需要用到的四個 package 就好
分別是 gdb 、 gcc-core 、 gcc-c++ 、 make ,如下圖所示:





選好之後,按下一步並等待安裝結束。



要不要放 link 就因個人習慣囉.....



之後在環境變數中設置
CYGWIN_HOME 為安裝的目錄,在這邊是 D:"cygwin
PATH 加入,%CYGWIN_HOME%"bin,原本有的內容要以 ; 串接哦!



設好了之後到 NetBeans 中選 Tools ---> Plugin



讓我們在可安裝的 Plugins 中選擇 C/C++,並按 Install



按 Next



選 I accept ....... ,  並按 Install



等待下載及安裝過程



顯示安裝 plugin 完成



如下圖,我們就可以在 new project 中看到 C/C++
相關的種類:



我們在建立的 Project 中的 Properties 中可以看到
GNU Complier Collection from Cygwin , 如下圖:



視需要 ( 如在用 JNI 時 ),記得要設定 Complier 中的 Command Line
-mno-cygwin -Wl,--add-stdcall-alias -shared -m32
如下圖



上方,參數的意義如下:
The -mno-cygwin option, enables building DLLs that have no dependencies on Cygwin own libraries and thus can be executed on machines which do not have Cygwin installed.
The -Wl,--add-stdcall-alias passes the --add-stdcall-alias option to the linker; without it, the resulting application would fail with the UnsatisfiedLinkError.
The -shared option tells the compiler to generate a DLL ( not an executable file).
-m32 tells the compiler to create a 32-bit binary. On 64-bit systems the compiled binaries are 64-bit by default , which causes a lot of problems with 32-bit JDKs.

參數的意義截自 http://www.netbeans.org/kb/55/beginning-jni-part1.html

----------------------------------------------------------------------------------

以上如有錯誤,歡迎告知改正

原文地址:http://aa.pro.vexp.idv.tw/viewthread.php?tid=222&extra=page%3D1





只有注册用户登录后才能发表评论。


网站导航: