开发者

Unresolved external symbol when lib is linked, compiler adds the letter 'A' to the function name

开发者 https://www.devze.com 2022-12-20 19:58 出处:网络
I get this error when trying to link a win32 exe project. I have linked in the lib that contains the code for this method. But still gets an unresolved symbol error.

I get this error when trying to link a win32 exe project. I have linked in the lib that contains the code for this method. But still gets an unresolved symbol error.

error LNK2001: unresolved external symbol "public: bool __thiscall SharedJobQueue::AddJobA(class boost::shared_ptr<class domain::Job>)" (?AddJobA@SharedJobQueue@@QAE_NV?$shared_ptr@VJob@domain@@@boost@@@Z)

Why does it say AddJobA with the 'A' at the end. The method is declared as AddJob.

I have looked in the output from 'dumpbin /symbols' and it only contains symbols for AddJob not AddJobA. Why do the compiler add an 'A' to the end of the funct开发者_运维问答ion name?


MS uses macros for the Win32 API to support both Unicode and Ansi builds by suffixing the function names with A or W.
AddJob() is a function in the Win32 API and thus has such a macro - you can #undef AddJob to get rid of your problem.


And here we see the problem with macros.

There is nothing wrong with your code per se, the problem is with the windows libraries. There is actually a function called AddJob in the Win32 headers, but not quite... The don't declare an Addjob function, but instead an AddJobA and an AddJobW function, which deal with non-unicode and unicode strings respectively.

The A at the end of your function name is due to a macro defined in the windows header that was defined to deal with unicode. Essentially they'll have something like:

#ifdef UNICODE
#  define AddJob AddJobW
#else
#  define AddJob AddJobA
#endif

This allows people to just use AddJob and the macros will point the function towards the correct unicode/non-unicode function. The problem of course is that the #define affects everything, which is what's happening to your function.

To fix this, you can either #undef AddJob or simply change the name of your function to something that isn't a Win32 function.


Windows functions may have A or W at the end of a function -- A signifies ASCII and W signifies a Wide fixed size unicode. Your project settings determine which function is used. addJob could have had W at the end if you had unicode enabled for your project..

0

精彩评论

暂无评论...
验证码 换一张
取 消