ACE6.0的安装_出错处理_检验

本文详细介绍了在Windows平台上安装和编译ACE的过程,包括环境设置、代码配置及常见问题解决,旨在帮助开发者顺利搭建ACE开发环境。
部署运行你感兴趣的模型镜像

转自http://blog.youkuaiyun.com/zhaohaidao/article/details/6330273

步骤:

1.       安装VS2008

2.       下载ACE

3.       新建config.h  并写入

#define ACE_HAS_STANDARD_CPP_LIBRARY 1

//#define ACE_HAS_MFC 1(这句须注掉,不然会有内存泄露)

#include "ace/config-win32.h"并保存于D:/ACE_wrappers

4.       添加环境变量 ACE_ROOT 变量值D:/ACE_wrappers

5.       打开D:/ACE_wrappers/ace/ACE_vc9.sln

6.       工具—选项—VC++目录

包含文件中添加 $(ACE_ROOT)

引用文件中添加 $(ACE_ROOT)/lib

库文件    添加 $(ACE_ROOT)/lib

源文件    添加 $(ACE_ROOT)/ace

7.       编译,如无意外,应该能编译成功

8.       新建win32控制台应用程序—空项目,源文件右键新建C++ CPP文件。

写入hello world 程序

 

 

途中所遇问题:

1.  环境变量的设置。

2.  路径混乱。

3.  error PRJ0003 :生成“cmd.exe”时出错。 导致原因,将工具—选项—VC++目录下可执行文件中$(Path)不小心删除,系统路径出错。

注意1:

ACE项目的字符集设置是"未设置",而VS2005的c++项目默认字符集是"使用Unicode字符集",如果用到了ACE链接库时需要将字符集改为"未设置"(在"项目属性->配置属性->常规->字符集"中配置),否则可能出现链接错误。

至此,ACE的安装工作便算完成,希望这篇文章对大家安装ACE有点帮助。

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

支持unicode的ACE编译

编译前在config.h中多添加如下两行,并且将项目默认字符集改为"使用Unicode字符集"。
      #define ACE_USE_WCHAR
      #define ACE_HAS_WCHAR

注意2:

在windows平台下,如果没有定义如上两个宏,ACE会自动将main函数重定义,并主动替你把ACE::init()和ACE::fini()调用好。添加这两个宏后,需要在main函数中手动调用。

main函数重定义这一行为不能保证在所有平台和环境下都正常运作(如使用MFC时),其实不管如何,不妨在main函数的开头和结尾分别再调用一次ACE::init()和ACE::fini()。ACE::init()和ACE::fini()里面都有嵌套层次计数机制,因此只要它们能够保证成对出现,并且不出现交叉嵌套,多调用一遍并不会出现任何问题。

 

 

检验

// serverMain.cpp

// 如果是WIN32平台上报错
// f:\ace\ace_wrappers\ace\config-win32-common.h(23): fatal error C1189: #error :  Please define WIN32 in your project settings.
// 可以文件头添加WIN32的预定义解决
#ifndef WIN32
#define WIN32
#endif

// 针对Debug版和Release版进行不同预处理
#ifdef _DEBUG
#pragma comment(lib,"ACEd.lib")
#else
#pragma comment(lib,"ACE.lib")
#endif

#include <ace\Log_Msg.h>
#include <ace\Time_Value.h>
#include <ace\SOCK_Acceptor.h>
#include <ace\SOCK_Stream.h>
#include <ace\OS_NS_stdlib.h>

#define SIZE_DATA 18
#define SIZE_BUF 1024
#define NO_ITERATIONS 5

class Server
{
public:
	Server (int port): server_addr_(port),peer_acceptor_(server_addr_)
	{
		data_buf_= new char[SIZE_BUF];
	}
	
	//Handle the connection once it has been established. Here the
	//connection is handled by reading SIZE_DATA amount of data from the
	//remote and then closing the connection stream down.
	int handle_connection()
	{
		// Read data from client
		for(int i=0;i<NO_ITERATIONS;i++)
		{
			int byte_count=0;
			if( (byte_count=new_stream_.recv_n (data_buf_, SIZE_DATA, 0))==-1)
				ACE_ERROR ((LM_ERROR, "%p\n", "Error in recv"));
			else
			{
				data_buf_[byte_count]=0;
				ACE_DEBUG((LM_DEBUG,"Server received %s \n",data_buf_));
			}
		}
		// Close new endpoint
		if (new_stream_.close () == -1)
			ACE_ERROR ((LM_ERROR, "%p\n", "close"));
		return 0;
	}
	
	//Use the acceptor component peer_acceptor_ to accept the connection
	//into the underlying stream new_stream_. After the connection has been
	//established call the handle_connection() method.
	int accept_connections ()
	{
		if (peer_acceptor_.get_local_addr (server_addr_) == -1)
			ACE_ERROR_RETURN ((LM_ERROR,"%p\n","Error in get_local_addr"),1);
		ACE_DEBUG ((LM_DEBUG,"Starting server at port %d\n",
			server_addr_.get_port_number ()));
		// Performs the iterative server activities.
		while(1)
		{
			ACE_Time_Value timeout (ACE_DEFAULT_TIMEOUT);
			if (peer_acceptor_.accept (new_stream_, &client_addr_, &timeout)== -1)
			{
				ACE_ERROR ((LM_ERROR, "%p\n", "accept"));
				continue;
			}
			else
			{
				ACE_DEBUG((LM_DEBUG,
					"Connection established with remote %s:%d\n",
					client_addr_.get_host_name(),client_addr_.get_port_number()));
				//Handle the connection
				handle_connection();
			}
		}
	}
private:
	char *data_buf_;
	ACE_INET_Addr server_addr_;
	ACE_INET_Addr client_addr_;
	ACE_SOCK_Acceptor peer_acceptor_;
	ACE_SOCK_Stream new_stream_;
};

int main (int argc, char *argv[])
{
	if(argc<2)
	{
		ACE_ERROR((LM_ERROR,"Usage %s <port_num>", argv[0]));
		ACE_OS::exit(1);
	}
	Server server(ACE_OS::atoi(argv[1]));
	server.accept_connections();
	return 0;
}

 

 

 

转自http://blog.youkuaiyun.com/stanjiang2010/article/details/6106708
 ACE的编译与安装(windows篇)

(一)源码包的获取

 

1、下载最新的ACE源码包,我的是ACE+TAO+CIAO-6.0.0.tar.gz;

 

2、解压至一目录如:D:/ACE_wrappers;

 

(二)设置环境变量

 

1、在操作系统添加一个名为ACE_ROOT的用户环境变量,值为刚才ace的解压路径D:、ACE_wrappers

2、添加用户的Path环境变量,值为%ACE_ROOT%/lib,这样才能保证系统能找到ace生成的动态连接库;

 

3、设置VS2005的C++开发项目信息,依次打开菜单 工具-选项-项目和解决方案-VC++目录 ,在右侧目录列表中选择"包含目录",添加$(ACE_ROOT),在右侧目录列表中选择"库文件",添加$(ACE_ROOT)/lib

 

(三)编译ACE

 

1、在ACE_ROOT/ace目录创建一个名为 config.h的文件。编辑文件并加入以下内容
#define ACE_HAS_STANDARD_CPP_LIBRARY 1
#include "ace/config-win32.h"
其中第一行是因为我想用标准C++跨平台,第二行则是必须要的,表明当前是在win32的环境下进行ace的项目

 

2、进入ACE_ROOT/ace目录中,能发现ACE现在已经带VS2005的编译项目了,直接打开ace_vc8.sln,直接生成ACE项目的Debug版和Release版;

 

(四)设置编译环境

1、配置属性->链接器->常规->附加依赖项,添入ACEd.lib(ACE.lib);

2、如果运行时报没有找到ACEd.dll的错误,则需在检查环境变量path中路径是否设置正确;

(五)例子

#include "ace/ACE.h"
#include "ace/OS_NS_stdio.h"
#include <iostream>
using namespace std;
int main (int argc, char *argv[])
{
    char msg[100] = {0};
    ACE_OS::sprintf(msg, "hello %s ", "world");
    cout << msg << endl;
    system("pause");
    return 0;
}

您可能感兴趣的与本文相关的镜像

ACE-Step

ACE-Step

音乐合成
ACE-Step

ACE-Step是由中国团队阶跃星辰(StepFun)与ACE Studio联手打造的开源音乐生成模型。 它拥有3.5B参数量,支持快速高质量生成、强可控性和易于拓展的特点。 最厉害的是,它可以生成多种语言的歌曲,包括但不限于中文、英文、日文等19种语言

public void Connect() { Connect(ModbusEndianness.LittleEndian); } /// <summary> /// Connect to localhost at port 502. /// </summary> /// <param name="endianness">Specifies the endianness of the data exchanged with the Modbus server.</param> public void Connect(ModbusEndianness endianness) { Connect(new IPEndPoint(IPAddress.Loopback, 502), endianness); } /// <summary> /// Connect to the specified <paramref name="remoteEndpoint"/>. /// </summary> /// <param name="remoteEndpoint">The IP address and optional port of the end unit with <see cref="ModbusEndianness.LittleEndian"/> as default byte layout. Examples: "192.168.0.1", "192.168.0.1:502", "::1", "[::1]:502". The default port is 502.</param> public void Connect(string remoteEndpoint) { Connect(remoteEndpoint, ModbusEndianness.LittleEndian); } /// <summary> /// Connect to the specified <paramref name="remoteEndpoint"/>. /// </summary> /// <param name="remoteEndpoint">The IP address and optional port of the end unit. Examples: "192.168.0.1", "192.168.0.1:502", "::1", "[::1]:502". The default port is 502.</param> /// <param name="endianness">Specifies the endianness of the data exchanged with the Modbus server.</param> public void Connect(string remoteEndpoint, ModbusEndianness endianness) { if (!ModbusUtils.TryParseEndpoint(remoteEndpoint.AsSpan(), out var parsedRemoteEndpoint)) throw new FormatException("An invalid IPEndPoint was specified."); #if NETSTANDARD2_0 Connect(parsedRemoteEndpoint!, endianness); #endif #if NETSTANDARD2_1_OR_GREATER Connect(parsedRemoteEndpoint, endianness); #endif } /// <summary> /// Connect to the specified <paramref name="remoteIpAddress"/> at port 502. /// </summary> /// <param name="remoteIpAddress">The IP address of the end unit with <see cref="ModbusEndianness.LittleEndian"/> as default byte layout. Example: IPAddress.Parse("192.168.0.1").</param> public void Connect(IPAddress remoteIpAddress) { Connect(remoteIpAddress, ModbusEndianness.LittleEndian); } /// <summary> /// Connect to the specified <paramref name="remoteIpAddress"/> at port 502. /// </summary> /// <param name="remoteIpAddress">The IP address of the end unit. Example: IPAddress.Parse("192.168.0.1").</param> /// <param name="endianness">Specifies the endianness of the data exchanged with the Modbus server.</param> public void Connect(IPAddress remoteIpAddress, ModbusEndianness endianness) { Connect(new IPEndPoint(remoteIpAddress, 502), endianness); } /// <summary> /// Connect to the specified <paramref name="remoteEndpoint"/> with <see cref="ModbusEndianness.LittleEndian"/> as default byte layout. /// </summary> /// <param name="remoteEndpoint">The IP address and port of the end unit.</param> public void Connect(IPEndPoint remoteEndpoint) { Connect(remoteEndpoint, ModbusEndianness.LittleEndian); } /// <summary> /// Connect to the specified <paramref name="remoteEndpoint"/>. /// </summary> /// <param name="remoteEndpoint">The IP address and port of the end unit.</param> /// <param name="endianness">Specifies the endianness of the data exchanged with the Modbus server.</param> public void Connect(IPEndPoint remoteEndpoint, ModbusEndianness endianness) { Initialize(new TcpClient(), remoteEndpoint, endianness); } /// <summary> /// Initialize the Modbus TCP client with an externally managed <see cref="TcpClient"/>. /// </summary> /// <param name="tcpClient">The externally managed <see cref="TcpClient"/>.</param> /// <param name="endianness">Specifies the endianness of the data exchanged with the Modbus server.</param> public void Initialize(TcpClient tcpClient, ModbusEndianness endianness) { Initialize(tcpClient, default, endianness); } private void Initialize(TcpClient tcpClient, IPEndPoint? remoteEndpoint, ModbusEndianness endianness) { base.SwapBytes = BitConverter.IsLittleEndian && endianness == ModbusEndianness.BigEndian || !BitConverter.IsLittleEndian && endianness == ModbusEndianness.LittleEndian; _frameBuffer = new ModbusFrameBuffer(size: 260); if (_tcpClient.HasValue && _tcpClient.Value.IsInternal) _tcpClient.Value.Value.Close(); var isInternal = remoteEndpoint is not null; _tcpClient = (tcpClient, isInternal); if (remoteEndpoint is not null && !tcpClient.ConnectAsync(remoteEndpoint.Address, remoteEndpoint.Port).Wait(ConnectTimeout)) throw new Exception(ErrorMessage.ModbusClient_TcpConnectTimeout); // Why no method signature with NetworkStream only and then set the timeouts // in the Connect method like for the RTU client? // // "If a NetworkStream was associated with a TcpClient, the Close method will // close the TCP connection, but not dispose of the associated TcpClient." // -> https://docs.microsoft.com/en-us/dotnet/api/system.net.sockets.networkstream.close?view=net-6.0 _networkStream = tcpClient.GetStream(); if (isInternal) { _networkStream.ReadTimeout = ReadTimeout; _networkStream.WriteTimeout = WriteTimeout; } } /// <summary> /// Disconnect from the end unit. /// </summary> public void Disconnect() { if (_tcpClient.HasValue && _tcpClient.Value.IsInternal) _tcpClient.Value.Value.Close(); _frameBuffer?.Dispose(); // workaround for https://github.com/Apollo3zehn/FluentModbus/issues/44#issuecomment-747321152 if (RuntimeInformation.FrameworkDescription.StartsWith(".NET Framework", StringComparison.OrdinalIgnoreCase)) _tcpClient = null; } ///<inheritdoc/> protected override Span<byte> TransceiveFrame(byte unitIdentifier, ModbusFunctionCode functionCode, Action<ExtendedBinaryWriter> extendFrame) { // WARNING: IF YOU EDIT THIS METHOD, REFLECT ALL CHANGES ALSO IN TransceiveFrameAsync! int frameLength; ushort protocolIdentifier; ushort bytesFollowing; byte rawFunctionCode; bool isParsed; ModbusFrameBuffer frameBuffer; ExtendedBinaryWriter writer; ExtendedBinaryReader reader; bytesFollowing = 0; frameBuffer = _frameBuffer; writer = _frameBuffer.Writer; reader = _frameBuffer.Reader; // build request writer.Seek(7, SeekOrigin.Begin); extendFrame(writer); frameLength = (int)writer.BaseStream.Position; writer.Seek(0, SeekOrigin.Begin); if (BitConverter.IsLittleEndian) { writer.WriteReverse(GetTransactionIdentifier()); // 00-01 Transaction Identifier writer.WriteReverse((ushort)0); // 02-03 Protocol Identifier writer.WriteReverse((ushort)(frameLength - 6)); // 04-05 Length } else { writer.Write(GetTransactionIdentifier()); // 00-01 Transaction Identifier writer.Write((ushort)0); // 02-03 Protocol Identifier writer.Write((ushort)(frameLength - 6)); // 04-05 Length } writer.Write(unitIdentifier); // 06 Unit Identifier // send request _networkStream.Write(frameBuffer.Buffer, 0, frameLength); // wait for and process response frameLength = 0; isParsed = false; reader.BaseStream.Seek(0, SeekOrigin.Begin); while (true) { int partialLength; // ASYNC-ONLY: using var timeoutCts = new CancellationTokenSource(_networkStream.ReadTimeout); // ASYNC-ONLY: // ASYNC-ONLY: // https://stackoverflow.com/a/62162138 // ASYNC-ONLY: // https://github.com/Apollo3zehn/FluentModbus/blob/181586d88cbbef3b2b3e6ace7b29099e04b30627/src/FluentModbus/ModbusRtuSerialPort.cs#L54 // ASYNC-ONLY: using (timeoutCts.Token.Register(_networkStream.Close)) // ASYNC-ONLY: using (cancellationToken.Register(timeoutCts.Cancel)) // ASYNC-ONLY: { // ASYNC-ONLY: try // ASYNC-ONLY: { partialLength = _networkStream.Read(frameBuffer.Buffer, frameLength, frameBuffer.Buffer.Length - frameLength); // ASYNC-ONLY: } // ASYNC-ONLY: catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested) // ASYNC-ONLY: { // ASYNC-ONLY: throw; // ASYNC-ONLY: } // ASYNC-ONLY: catch (OperationCanceledException) when (timeoutCts.IsCancellationRequested) // ASYNC-ONLY: { // ASYNC-ONLY: throw new TimeoutException("The asynchronous read operation timed out."); // ASYNC-ONLY: } // ASYNC-ONLY: catch (IOException) when (timeoutCts.IsCancellationRequested && !cancellationToken.IsCancellationRequested) // ASYNC-ONLY: { // ASYNC-ONLY: throw new TimeoutException("The asynchronous read operation timed out."); // ASYNC-ONLY: } // ASYNC-ONLY: } /* From MSDN (https://docs.microsoft.com/en-us/dotnet/api/system.io.stream.read): * Implementations of this method read a maximum of count bytes from the current stream and store * them in buffer beginning at offset. The current position within the stream is advanced by the * number of bytes read; however, if an exception occurs, the current position within the stream * remains unchanged. Implementations return the number of bytes read. The implementation will block * until at least one byte of data can be read, in the event that no data is available. Read returns * 0 only when there is no more data in the stream and no more is expected (such as a closed socket or end of file). * An implementation is free to return fewer bytes than requested even if the end of the stream has not been reached. */ if (partialLength == 0) throw new InvalidOperationException(ErrorMessage.ModbusClient_TcpConnectionClosedUnexpectedly); frameLength += partialLength; if (frameLength >= 7) { if (!isParsed) // read MBAP header only once { // read MBAP header _ = reader.ReadUInt16Reverse(); // 00-01 Transaction Identifier protocolIdentifier = reader.ReadUInt16Reverse(); // 02-03 Protocol Identifier bytesFollowing = reader.ReadUInt16Reverse(); // 04-05 Length _ = reader.ReadByte(); // 06 Unit Identifier if (protocolIdentifier != 0) throw new ModbusException(ErrorMessage.ModbusClient_InvalidProtocolIdentifier); isParsed = true; } // full frame received if (frameLength - 6 >= bytesFollowing) break; } } rawFunctionCode = reader.ReadByte(); if (rawFunctionCode == (byte)ModbusFunctionCode.Error + (byte)functionCode) ProcessError(functionCode, (ModbusExceptionCode)frameBuffer.Buffer[8]); else if (rawFunctionCode != (byte)functionCode) throw new ModbusException(ErrorMessage.ModbusClient_InvalidResponseFunctionCode); return frameBuffer.Buffer.AsSpan(7, frameLength - 7); } private ushort GetTransactionIdentifier() { lock (_transactionIdentifierLock) { return _transactionIdentifierBase++; } }
最新发布
01-02
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值