ACE链接错误解决办法

今天编写程序时,某个工程需要用到互斥锁,而ACE正好有这个函数,在成员变量中加入下面这句:

private:
    ACE_Recursive_Thread_Mutex m_listBuffLock;

编译链接的时候报以下错误:

1>Linking...
1>   Creating library ../lib/MediaConverterModule.lib and object ../lib/MediaConverterModule.exp
1>MediaConverter.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: int __thiscall ACE_Recursive_Thread_Mutex::release(void)" (__imp_?release@ACE_Recursive_Thread_Mutex@@QAEHXZ)
1>MediaConverter.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: int __thiscall ACE_Recursive_Thread_Mutex::acquire(void)" (__imp_?acquire@ACE_Recursive_Thread_Mutex@@QAEHXZ)
1>MediaConverter.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall ACE_Recursive_Thread_Mutex::~ACE_Recursive_Thread_Mutex(void)" (__imp_??1ACE_Recursive_Thread_Mutex@@QAE@XZ)
1>MediaConverter.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall ACE_Recursive_Thread_Mutex::ACE_Recursive_Thread_Mutex(wchar_t const *,struct ACE_mutexattr_t *)" (__imp_??0ACE_Recursive_Thread_Mutex@@QAE@PB_WPAUACE_mutexattr_t@@@Z)
1>../bin_release/MediaConverterModule.dll : fatal error LNK1120: 4 unresolved externals


这个是没有加入ACE.lib文件,在工程属性的linker中加入ACE.lib后,发现仍然报错:

1>Linking...
1>   Creating library ../lib/MediaConverterModule.lib and object ../lib/MediaConverterModule.exp
1>MediaConverter.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall ACE_Recursive_Thread_Mutex::ACE_Recursive_Thread_Mutex(wchar_t const *,struct ACE_mutexattr_t *)" (__imp_??0ACE_Recursive_Thread_Mutex@@QAE@PB_WPAUACE_mutexattr_t@@@Z)
1>../bin_release/MediaConverterModule.dll : fatal error LNK1120: 1 unresolved externals

使用clean->Build->clean->Build仍然不能解决,后来发现是工程字符集的问题,打开ACE的vc8工程,在工程属性中没有设置字符集

这样编译出来的默认是Multi-Byte Character Set(多字节字符集),而新建的VS2005工程默认是使用Unicode Character Set(Unicode字符集),字符集不一致,导致导出的函数接口无法使用,就出现上面的链接错误。

将这个位置的字符集修改为Use Multi-Byte Character Set就可以了

或者修改ACE的工程属性的字符集为Unicode的,那么新建的VS2005工程不需要作任何改变。建议在WINDOWS下使用Unicode字符集,因为WINDOWS内部都是使用Unicode的,使用其它的都是要先分配内在经过一次转换,影响代码执行速度。

下面是摘自Windows核心编程的一段话:

开发应用程序的时候,强烈建议你使用Unicode字符和字符串。下面是一些理由。

1.Unicode使程序的本地化变得更容易。
2.使用Unicode,只需发布一个二进制(.exe或DLL)文件,即可支持所有语言。
3.Unicode提升了应用程序的效率,因为代码执行速度更快,占用内存更少。Windows内部的一切工作都是使用Unicode字符和字符串来进行的。所以,假如你非要传入ANSI字符或字符串,Windows就会被迫分配内存,并将ANSI字符或字符串转换为等价的Unicode形式。
4.使用Unicode,你的应用程序能轻松调用所有不反对使用(nondeprecated)的Windows函数,因为一些Windows函数提供了只能处理Unicode字符和字符串的版本。
5.使用Unicode,你的代码很容易与COM集成(后者要求使用Unicode字符和字符串)。
6.使用Unicode,你的代码很容易与.NET Framework集成(后者要要求使用Unicode字符和字符串)。
7.使用Unicode,能保证你的代码能够轻松操纵你自己的资源(其中的字符串总是Unicode的)

Comments are closed.