LNK2001 and LNK1120 when compiling a x64 dynamic l

2019-08-15 16:52发布

I recently got assigned to a c++ project, although I am not a c++ developer. I was provided Visual Studio 2010 Professional as IDE. So I gave it a shot.

I am to write a c++ dynamic library (*.dll) which wraps two static libraries (*.lib). The static libraries are third party libraries we bought a couple of years ago from another company. Using the dumpbin /header ... cmd call, I can say that both static libraries have the following file header value:

14C machine (x86)

I got this task working for the Win32 solution platform. I added the header files and the libraries to the project. The libraries are included by writing two #pragma comment(lib, ...) statements within the .cpp I need the functions in. Works like a charm. A sample function looks like this:

extern "C" void OURFreeStringBuf(Cm_StringBuf *sbuf)
{
    FreeStringBuf(sbuf); // the call to the static library
}

This dynamic library is to be used in x64 architectures, aswell. So I tried to set the solution platform to x64. Now I get the following error for each call of one of the static libraries' functions (no code changes or other configuration changes were made):

error LNK2001: unresolved external symbol "..."

followed by a summarizing error:

error LNK1120: 29 unresolved external links

Could these errors be the result of trying to link x86 lib files in a x64 dll? Is there any chance to complete this task using the provided static libraries?

Thank you very much in advance.

1条回答
看我几分像从前
2楼-- · 2019-08-15 17:44

You can not - in other words, there is NO WAY to - link a 32-bit library with a 64-bit executable or DLL (or a 32-bit executable to a 64-bit DLL or vice versa). You will either have to compile your .DLL/.EXE as 32-bit, or find a 64-bit version of the 32-bit library. No other solution!

The 64-bit architecture is different from the 32-bit architecture in several aspects, but most importantly, the addresses (pointers) are 64-bit in a 64-bit architecture, which prevents almost any 32-bit code from working correctly in a 64-bit environment (because the upper 32 bits of the addresses are lost, which doesn't produce anything meaningful).

查看更多
登录 后发表回答