views:

619

answers:

4

ith Visual Studio 2008, If the configuration type is a static library, I dont see a linker option in project properties. I need to specify /MACHINE:x64 option for a static library. I tried to specify this in command line option in Librarian. Only then I could build the static library. If I dont specify /MACHINE compiling the static lib fails with LNK1112: module machine type 'X86' conflicts with target machine type 'x64' ( even if I set the platform to X64 for my solution).

With /MACHINE:X64 specified as command line through Project-Properties-Librarian, the static library was built but other project (of configuration type : DLL) in the same solution has a dependency on the static lib, when the DLL is built and tries to use one of the functions in the lib I again get the same error:

fatal error LNK1112: module machine type 'X86' conflicts with target machine type 'x64'

Please suggest, how do I build a 64 bit static library

+1  A: 

Did you try to add a new project configuration (x64) to the existing project?

You should usually not have to edit the project properties at all to build in 64bit. You just have to add the configurations and make sure the solution configuration is correct (64 bit solution configuration contains 64bit project configurations).

You can check this by opening Build->Configuration Manager. My Visual Studio sometimes messes with these settings and makes the project uncompilable, so checking it again might help.

Timbo
A: 

For what it's worth, I've come across this exact same issue.

I have a project that compiles a static library, and creating an "x64" configuration did NOT get it actually targeting x64. I had to explicitly add "/MACHINE:X64" as an "additional option" under "Librarian -> Command Line" in the project's property pages, just as you did.

I would expect visual studio to expose this setting as a first-class property in the property pages, as it does for dynamic libraries (under "Linker -> Advanced -> Target Machine"). Perhaps I'm missing something.

Stuart Lange
A: 

I am also trying to compile a static library in 64 bit. Is there a solution to this? It seems like the option under "Linker -> Advanced -> Target Machine" is only for Dynamic DLL.

I tried to add "/MACHINE:X64" to Librarian->Command Line->Additional options but get the fatal error LNK1112: module machine type 'X86' conflicts with target machine type 'x64'

ramrocket
A: 

As mentioned by Timbo, you need to ensure that you have an x64 configuration that you're building. However, there are a couple of other gotchas to be aware of:

  • Do a total clean of your build directory first in case you still have some 32 bit object files lying around that are causing confusion
  • Check the intermediate and output directories for your project. If the destination is Debug\Mylib.lib then you're going to run into problems because the same name is being used for the 32 and 64 bit libraries. I prefer to select all configurations and all platforms and then rename them all to something standard like ..\build\$(ProjectName)\$(ConfigurationName).$(PlatformName)
  • Check in the configuration manager that when you are building the 64-bit configuration of the solution that it is configured to build the 64-bit configurations of the projects (this doesn't always happen by default)
  • The error: module machine type 'X86' conflicts with target machine type 'x64' means that the object file has been built as 32-bit but the link setting of the project is set with the flag /machine:x64. So this suggests that the project configuration is 32-bit.
  • If in doubt about what you've created, pick one of the object files and type this at a command prompt:

    dumpbin /headers myfile.obj | findstr machine

This will show you the architecture you've actually built for.

the_mandrill