安装 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.