geometrian
geometrian

Reputation: 15387

C1905/LNK1257 Combining x64 Release Libraries

I have set up static library builds of zlib and libpng. Both compile fine into .lib files. I am using MSVC 2010.

With this setup, to use libpng.lib, you need to link against zlib.lib as well. To avoid this, I'm trying to use lib.exe to link zlib into libpng directly. My invocation looks like:

call "C:/Program Files (x86)/Microsoft Visual Studio 10.0/VC/bin/lib.exe"  /OUT:x64\Release\libpng2.lib  x64\Release\libpng.lib  ..\zlib\x64\Release\zlib.lib  /LTCG

In both of their project settings, I explicitly set "Librarian->General->Target Machine" to MachineX64. And, using dumpbin, I can check that the relevant zlib.lib and libpng are both compiled for x64.

Additionally, "General->Whole Program Optimization" and "C/C++->Optimization->Whole Program Optimization" have identical values.

The problem only occurs for x64 Release configurations. x86 Debug, x86 Release, and x64 Debug all work fine.

EDIT: Specifically, the problem is that I get a C1905/LNK1257 error:

C1905: Front end and back end not compatible (must target same processor).
LNK1257: code generation failed

Upvotes: 1

Views: 6030

Answers (1)

heinrichj
heinrichj

Reputation: 552

I ran into this problem with VS2012. The lib.exe you're calling is part of the x86 tools. In the amd64 subfolder in VC/bin you will find the x64 versions. Opening a Visual Studio x64 Win64 Command Prompt will set your PATH correctly or you can call the x64 lib.exe directly, specifying its full path as you are doing now.

Upvotes: 2

Related Questions