CentOS6.3 下安装codeblocks

时间:2023-02-15 04:39:09

本人用的系统是centos6.3(虚拟机) 需要预先安装gcc编译器(参考:http://www.cnblogs.com/magialmoon/archive/2013/05/05/3061108.html)

1、先安装GTK+

yum install gtk+*
2、下载并安装<span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13.92px; line-height: 20.88px;">wxGDK 下载地址:<a target=_blank href="http://www.wxwidgets.org/downloads/">wxGTK下载地址</a></span>
以<span style="font-family:Verdana, Arial, Helvetica, sans-serif;"><span style="font-size: 13.92px; line-height: 20.88px;">wxGTK-2.8.12.tar.gz为例</span></span>
<span style="font-family:Verdana, Arial, Helvetica, sans-serif;"><span style="font-size: 13.92px; line-height: 20.88px;">首先将它解压:</span></span><pre name="code" class="plain">tar zxvf wxGTK-2.8.12.tar.gz
cd wxGTK-2.8.12

安装:
<pre name="code" class="plain">mkdir build_gtk2_shared_monolithic_unicode
cd build_gtk2_shared_monolithic_unicode
./configure --prefix=/opt/wx/2.8 \
--enable-xrc \
--enable-monolithic \
--enable-unicode
make
su
make install
exit
<span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13.92px; line-height: 20.88px;">安装的路径是</span><span style="margin: 0px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13.92px; line-height: 20.88px; color: rgb(255, 0, 0);">/opt/wx/2.8/</span>
<span style="margin: 0px; padding: 0px; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13.92px; line-height: 20.88px;"><span style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13.92px; line-height: 20.88px;"><span style="color:#ff0000;">设置环境变量:</span></span></span><pre style="color: rgb(51, 51, 51); margin-top: 0px; margin-bottom: 0px; padding: 0px; white-space: pre-wrap; word-wrap: break-word; border-radius: 4px; line-height: 20px; word-break: break-all; border: 0px solid rgba(0, 0, 0, 0.14902); border-image-source: initial; border-image-slice: initial; border-image-width: initial; border-image-outset: initial; border-image-repeat: initial; font-family: 'Courier New' !important; background-color: rgb(245, 245, 245);">export PATH=/usr/bin:/opt/wx/<span style="margin: 0px; padding: 0px; color: rgb(128, 0, 128); line-height: 1.5 !important;">2.8</span>/bin:$PATH

然后运行如下命令:

ldconfig
source /etc/profile

ldconfig命令的作用是让动态链接库为系统所共享,source命令的作用简单来说就是使得配置文件的修改立即生效而不需要重启。

3、下载并安装codeblocks

地址:https://sourceforge.net/projects/codeblocks.berlios/files/codeblocks_12.11-1.tar.gz/download?use_mirror=jaist

解压,然后执行:./bootstrap

bootstrap命令的作用是设置configure脚本及其依赖关系,这个命令只需要执行一次,运行这个命令如果出现下面的错误:

./bootstrap: libtoolize: not found

说明机子上没有安装“libtool”,yum安装下即可:

yum install libtool

可能还会报错:

configure.in:79: warning: macro `AM_OPTIONS_WXCONFIG' not found in library
configure.in:80: warning: macro `AM_PATH_WXCONFIG' not found in library
configure.in:79: error: possibly undefined macro: AM_OPTIONS_WXCONFIG
If this token and others are legitimate, please use m4_pattern_allow.
See the Autoconf documentation.
configure.in:80: error: possibly undefined macro: AM_PATH_WXCONFIG

将wxGTK-2.8.12下的wxwin.m4复制到/usr/share/aclocal

cp ../wxwin.m4 /usr/share/aclocal

configure

./configure --with-wx-config=/opt/wx/2.8/bin/wx-config

然后 make make install



设置LD_LIBRARY_PATH变量:

export LD_LIBRARY_PATH =/opt/wx/2.8/lib/

这种方式是临时的设置环境变量,关闭shell就会失效,需要永久的设置环境变量参看这里这里,修改/etc/profile文件,加入下面这行:

export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/opt/wx/2.8/lib"
source /etc/profile

LD_LIBRARY_PATH这个环境变量的作用是让其他程序找到第三方的动态连接库。设置后就没可以通过命令行启动C::B了。

4、如果发现codeblocks无法启动命令行窗口,提示:terminated with status 255,则需要安装xterm。命令:yum install -y xterm

5、在使用多线程时,如果提示"undefined reference to pthread_create()"等之类的错误,则需要手动将pthread链接库加入到项目中:右键项目-》build选项-》链接器设置-》添加路径“/usr/lib/libpthread.so”。