Eclipse+MinGW+ACE环境搭建成功

来源:互联网 发布:sql语句相同数据合并 编辑:程序博客网 时间:2024/05/16 09:30
声       明:笔者对这三个环境也不太熟,如有疏漏或错误之处,还望看客指正!

原文出处:http://vin-mail.blog.163.com/blog/static/37895280201272563632186/

编       者:Gavin Tung

一、准备

(1)Eclipse  For C++

(2)MinGW

(3)ACE

这里我偷懒了,看客可以通过搜索引擎到网上搜索各自的安装包然后下载,对于ACE和Eclipse我将在后文给出下载地址。

二、环境安装(Windows 7)

1.MinGW  ——这里我用的是4.6.2

(1)MinGW(安装还是比较傻瓜的)

下载个安装包,我是安装到D:\OpenSoftware\MinGW目录下的:

Eclipse+MinGW+ACE环境搭建成功 - Gavin Tung - 文文博客
然后进入bin目录,将make-win32.exe在当前目录下copy一份,并命名为make.exe
(2)配置MinGW环境变量
方法:计算机->属性->高级系统设置->高级->环境变量->系统变量:using 新建/编辑
这里有几个变量:
MINGW=D:\OpenSoftware\MinGW
MINGW_HOME=D:\OpenSoftware\MinGW
MINGW_VERSION=4.6.2
C_INCLUDE_PATH=%MINGW_HOME%\include;%MINGW_HOME%\lib\gcc\mingw32\%MINGW_VERSION%\include
CPLUS_INCLUDE_PATH=%MINGW_HOME%\include\;%MINGW_HOME%\lib\gcc\mingw32\%MINGW_VERSION%\include
PATH + =%MINGW_HOME%\bin;%MINGW_HOME%\libexec\gcc\mingw32\%MINGW_VERSION%
(这里用+=,你懂得,实际上是采用编辑方式追加到系统PATH变量中,其他用等号的表示新建变量)
LIBRARY_PATH=%MINGW_HOME%\lib;%MINGW_HOME%\lib\gcc\mingw32\%MINGW_VERSION%
添加完成后依次点击所有的确定。Okay,Congratulations! 你可以使用命令行的g++/gcc了
Eclipse+MinGW+ACE环境搭建成功 - Gavin Tung - 文文博客
 
 
 2.ACE
(1)安装ACE
首先下载ACE源码:
ACE官网下载ACE源码:http://www.cs.wustl.edu/~schmidt/ACE.html
download from here:  http://download.dre.vanderbilt.edu/
这里我只下载了ACE.tar.gz,解压出来是ACE_wrappers目录,然后我放在:D:\OpenSoftware\ACE_wrappers_MinGW(目录已更名)
 接下来就是编译了。可以参考目录下的ACE-INSTALL.html->Windows (including MinGW and Cygwin) ->MingW:

Building and Installing ACE on Win32 with MinGW/ MSYS

If you are building for a machine without a network card, you may want to check here first.

Building and installing ACE on MinGW uses a mix of a UNIX building process and Win32 configuration files. Also, as MinGW uses GNU g++, you may want to take a look at the Compiling ACE with GNU g++ section.

You will need the MinGW build tools and libraries, downloable from http://www.mingw.org. For our build we require the packages MinGW and MSYS. Install the MinGW tools (including the MinGW Development toolkit) into a common directory, say c:/mingw. Install the MSYS tools into a common directory, say c:/msys. Open a MSYS shell. Set your PATH environment variable so your MinGW's bin directory is first:

       % export PATH=/c/mingw/bin:$PATH  Add an ACE_ROOT environment variable pointing to the root of your ACE wrappers source tree: 
       % export ACE_ROOT=/c/work/mingw/ACE_wrappers         


From now on, we will refer to the root directory of the ACE source tree as $ACE_ROOT.
Create a file called config.h in the $ACE_ROOT/ace directory that contains:

       #include "ace/config-win32.h"         


Create a file called platform_macros.GNU in the $ACE_ROOT/include/makeinclude directory containing:

       include $(ACE_ROOT)/include/makeinclude/platform_mingw32.GNU         


In the above text, don't replace $(ACE_ROOT) with the actual directory, GNU make will take the value from the environment variable you defined previously.

If you lack Winsock 2, add the line


       winsock2 = 0         


before the previous one.

If you want to install ACE (using "make install") and want all the .pc files generated, set the installation prefix in platform_macros.GNU.


      INSTALL_PREFIX=/c/ACE         


Headers will be installed to $INSTALL_PREFIX/include, documentation and build system files to $INSTALL_PREFIX/share and libraries to $INSTALL_PREFIX/lib. With INSTALL_PREFIX set, RPATH will be enabled. To disable RPATH (for example, if $INSTALL_PREFIX/$INSTALL_LIB is already a system-known location for shared libraries), set the make macro install_rpath to 0 by adding install_rpath=0 to platform_macros.GNU.
In the MSYS shell, change to the $ACE_ROOT/ace directory and run make:

       % cd $ACE_ROOT/ace         % make         


This should create libACE.dll (the Win32 shared library) and libACE.dll.a (the Win32 import library for the DLL). Note that the name for the ACE DLL follows the MinGW convention, which itself resembles UNIX.

If you want static libs also, you may run:


       % make static_libs_only=1         


Run make install:

       % make install         


This should create ACE.pc to use with pkg-config.


The same rules for Win32 search of DLLs apply for MinGW. If you want to run some ACE programs from the MSYS shell, you may need to add the directory for libACE.dll to your PATH:

       % export PATH=/c/work/mingw/ACE_wrappers/ace:$PATH  


英语不好的童鞋也不用担心,其实关键的也就只有下面这几步:
a.进入MinGW shell或者在cmd下运行:.\MinGW\msys\1.0\msys.bat
Eclipse+MinGW+ACE环境搭建成功 - Gavin Tung - 文文博客
 设置环境变量:(shell中运行)
export ACE_ROOT=/d/OpenSoftware/ACE_wrappers_MinGWexport PATH=/d/OpenSoftware/mingw/bin:$PATH
实际上是Windows路径的一种Linux路径表示。D:\OpenSoftware....,你可以根据实际情况映射成自己的路径.
然后在$ACE_ROOT/ace,我这里也就是D:\OpenSoftware\ACE_wrappers_MinGW\ace
创建config.h文件,内容是: #include "ace/config-win32.h"
在$ACE_ROOT/include/makeinclude,我这里也就是D:\OpenSoftware\ACE_wrappers_MinGW\include\makeinclude下
创建platform_macros.GNU文件,内容是:include $(ACE_ROOT)/include/makeinclude/platform_mingw32.GNU
这两个文件可以不用控制台方式创建,直接手工到相应文件夹下去创建,并通过文本编辑器如记事本写入内容并保存即可。
然后在刚刚那个shell中运行一下命令:
% cd $ACE_ROOT/ace
% make
这个过程就比较长,呵呵,看客可以去抽干烟,看看其他的了。完了之后会在$ACE_ROOT/ace(也就是我的:D:\OpenSoftware\ACE_wrappers_MinGW\ace)下生成两个文件:
libACE.dll.a
libACE.dll
呵呵,明眼人一看都懂,libACE.dll是ACE开发的程序需要的动态链接库,libACE.dll.a就是传说中的lib文件了。
然后我们需要添加几个环境变量:(同 二-1-(2)节)
ACE_ROOT=D:\OpenSoftware\ACE_wrappers_MinGW
ACE_LIB=%ACE_ROOT%\ace
C_INCLUDE_PATH+=%ACE_LIB%CPLUS_INCLUDE_PATH+=%ACE_LIB%LIBRARY_PATH+=%ACE_LIB%PATH+=%ACE_ROOT%;%ACE_ROOT%
(这里用+=,你懂得,实际上是采用编辑方式追加到系统原有变量中,其他用等号的表示新建变量)
这样做的目的是为了方便找到头文件、lib文件和动态链接库文件。
当然,ACE的头文件也在D:\OpenSoftware\ACE_wrappers_MinGW\ace下
 
3.Eclipse For C++  ——这里我用的是Version: Juno Release
(1)安装Eclipse
直接从官网下载安装包,C++版的,然后解压即可。我下载的是:Eclipse IDE for C/C++ Developers
download: http://www.eclipse.org/downloads/
我放在D:\OpenSoftware\Eclipse_32
Eclipse+MinGW+ACE环境搭建成功 - Gavin Tung - 文文博客
第一次启动的时候会让用户配置一个工作空间,你自己设置一个目录就可以了,这个目录就是以后的默认工程文件目录。
(2)创建HelloACE工程并配置ACE环境:
启动eclipse.exe后,File->New->C++ Project
Project Name:HelloACE
Project Type:Executable->Hello wold Project
Tool Chains:MinGW GCC

在 libraries (-l) 中 写入 ACE.dll (说明 它就是 libACE.dll.a 去掉 lib 和.a)

* 有时需要加入 wsock32 如 使用 ACE_SOCK_Dgram 时
在 library search path(-L) 中 写入 "D:\OpenSoftware\ACE_wrappers_MinGW\ace"

完成配置。

Eclipse+MinGW+ACE环境搭建成功 - Gavin Tung - 文文博客
 
将工程下main所在的cpp文件修改为一下测试程序:(我也是网上找的^_^)

#include <iostream>#include "ace/OS.h"#include "ace/Log_Msg.h"#include "ace/INET_Addr.h"#include "ace/SOCK_Stream.h"#include "ace/SOCK_Connector.h"#include "ace/Log_Msg.h"

 

using namespace std;

 

int main(int, ACE_TCHAR *[]){ /* ACE_INET_Addr srvr(50000, ACE_LOCALHOST);

 ACE_SOCK_Connector connector; ACE_SOCK_Stream peer;

 if (-1 == connector.connect(peer, srvr))

  ACE_ERROR_RETURN ((LM_ERROR,      ACE_TEXT ("%p\n"),      ACE_TEXT ("connect")), 1);

 int bc; char buf[64];

 peer.send_n("uptime\n", 7); bc = peer.recv(buf, sizeof(buf)); write(1, buf, bc); peer.close();

 return (0); */ const ACE_Time_Value max_tm(24*60*60); // 取当前系统日期 ACE_Time_Value today = ACE_OS::gettimeofday();

 cout << "当前日期秒数 = "; cout << today.sec() << endl;

 cout << "明天此时秒数 = "; today += max_tm; cout << today.sec() << endl;

 getchar(); system("PAUSE"); return(0);

}

此时一定会出现很多错误提示吧,嘿嘿,不用着急,那是因为工程还不能找到ACE的环境,接下来这样设置:
菜单:Project->Property->C/C++ Build->Environment下添加%ACE_ROOT%和%ACE_LIB%:
Eclipse+MinGW+ACE环境搭建成功 - Gavin Tung - 文文博客
 
然后同时在Project->Property->C/C++ Build->Setting下MinGW GCC Linker项的library下添加lib和lib所在路径信息:
Libraries下:ACE.dll
Library Search Path下:"D:\OpenSoftware\ACE_wrappers_MinGW\ace"
Eclipse+MinGW+ACE环境搭建成功 - Gavin Tung - 文文博客
这下就可以编译运行测试程序了,测试结果如下:
当前日期秒数 = 1345902680明天此时秒数 = 1345989080
 
编译测试工程过程中可能会出现一下问题
XXX头文件不能找到;
XXX标示cannot be resolved;
或者未定义__XXXACE__标示等什么什么错误的
优先解决方案:添加ACE头文件和Lib文件所在路径,如果编译成功但是不能运行可能是dll未找到,要指定文件或文件所在路径到PATH或者工程的查找路径选项中。
 
差不多就这些吧,预祝您安装成功!O(∩_∩)O谢谢!!!
 
0 0
原创粉丝点击