Trouble to compile a native c++ program in 64 bits - c++

I try to compile a native Visual Studio 2008 C++ program in 64 bits on my windows 32 bits.
I have an error during the link because the version of msvcprtd.lib in 64 bits is not found.
msvcprt.lib(MSVCP90.dll) : fatal error LNK1112: module machine type 'X86' conflicts with target machine type 'x64'
I have installed the last version of Microsoft Windows SDK but I can't found the msvcprtd.lib file in x64 directory.

This error is likely due to not having the library directories set up to reference the x64 ones. This can easily happen if you add a new x64 configuration to a project. The simplest solution is to create a new solution with project for both win32 and x64 and then look at the VC++ Directories/Library Directories in the project properties, and ensure the ones you have in your project are the same.

msvcprtd.lib doesn't appear in my latest SDK in either 32 or 64 bits. I do see it in version 5.0 of the SDK though, but only for the IA64 platform type.
Perhaps that lib simply doesn't exist. Try removing it from the list of lib's you're linking against and see what errors you get then, googling those errors may lead you to the name of the lib you actually want to link.

Try this: Go to your project property -> Configuration Manager and then create a configuration manager which specifies x64 as platform and set it as active.

My short answer is did you make sure you have the cross complier installed. I remember going crazy when trying to compiled a 64 bit binary on my 32 bit XP, when I realized I did not have the cross compiler installed. (Having my Visual studio media handy is helpful).
Also as Madhur said make sure your Configuration is set for 64 bit.

Related

Qt - module machine type 'x64' conflicts with target machine type 'X86'

I get the above error when trying to compile my Qt project from Qt Creator. Can I change the target machine type to x64 somewhere?
When I convert the project to a VC++ project from the command line, it builds and runs. This is good enough, but it would be convenient to be able to build and run directly from the Qt Creator.
Does this result from Qt being 32 bit and other components being 64 bit?
The 32/64-bit build of Qt must correspond to the Visual Studio project settings of your project. Remember that it is perfectly normal to have multiple (perhaps dozens) of Qt builds existing side-by-side on a given development system. The particular project you're building should use the Qt build that is compatible with it: the Visual Studio versions and 32/64-bit choices must agree.
Note that VS2015 Update 3 is binary compatible with VS2017. Otherwise, C++ code built with mismatched Visual Studio major releases is not binary compatible (won't link or will crash on startup).

Qt module error - LNK 1112 in QtOpenGL

I am trying to build a project (x64) connected with Qt library in Microsoft Visual Studio 2010. The project I want to compile was built using Visual Studio 2008.
I have all the dependencies added, downloaded compiled the Qt library 64-bit and done all the proper changes in project properties in VS 2010. Although, I get the error below:
Error 2616 error LNK1112: module machine type 'X86' conflicts with
target machine type 'x64' D:\project\Windows\QtOpenGL4.lib(QtOpenGL4.dll)
I have checked my .dll and .lib files and they are an in x64 bit version. Also, my QtOpenGL4.dll file is in another path from the one mentioned in error.
Could it be an error from the QtOpenGL4 module? How could I solve this? Could you please help me?
The instructions I followed in order to build the 64-bit version of Qt are in this link : https://en.wikibooks.org/wiki/Opticks_Developer_Guide/Getting_Started/Building_Qt_From_Source
Finally I found a solution in my error. I compiled again the Qt library in 64-bit and entered all the proper values in project Properties. I also entered the proper path in
Project Properties -> Linker ->Input ->Additional Dependencies.
With the right paths it solved the linkage error for me.
I have to mention that I also downloaded the precompiled libraries from the answers in this link
How to compile Qt for 64-bit Windows from a 32-bit environment with Visual C++ 2010 Express?
You are probably trying to link your 64-bit project with 32-bit Qt libraries.
This says more about the error you are facing.
Similarly, if you create one module with the x64 compiler and another
module with the x86 compiler, and try to link them, the linker will
generate LNK1112.
Check if you are using 64-bit precompiled Qt libraries.

msvcprtd.lib(MSVCP100D.dll) : fatal error LNK1112: module machine type 'X86' conflicts with target machine type 'x64'

I created a vs 2010 win 32 program (Operation system: Win 8-64bit)
Then, I tried to convert this win32 program in to x64 by doing like this:
Configuration Manager -> new solution platform (select x64) -> copy settings from win32
The vs2010 created a new x64 program based on the previous win32 program.
However, when I tried to compile and run the x64 program, there is a single error:
msvcprtd.lib(MSVCP100D.dll) : fatal error LNK1112: module machine type 'X86' conflicts with target machine type 'x64'
By renaming both win32 version and x64 version of msvcprtd.lib, I found the program is still using the win32 msvcprtd.lib.
I checked and found msvcprtd.lib is in $(VCInstallDir)lib\amd64. Moreover:
Library Directories -> Inherited values has included all the necessary directories (I think):
$(VCInstallDir)lib\amd64
$(VCInstallDir)atlmfc\lib\amd64
$(WindowsSdkDir)lib\x64
I also checked the 3rd party libraries and dlls the program is using are of x64 version.
My question is why the program is still using the win32 msvcprtd.lib and how to solve this problem?
In the project Library Directories, be sure you change
$(VCInstallDir)lib and $(VCInstallDir)atlmfc\lib
to
$(VCInstallDir)lib\amd64 and $(VCInstallDir)atlmfc\lib\amd64
After searching I came across an useful page MSDN Info. "It is a known problem that on occasions VC picks up certain settings from older versions of VC installed and causes these kinds of problems."
For me it worked by adding the following:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\lib\x64
Anyway, don't hesitate to search the msvcprtd.lib file directly from Visual Studio installation directory.
I have faced same problem.It comes rarely and occasionally when we create new project for X64 platform.
Here is the solution: for X64 platform
In Configuration properties-->
1.Include directories -> $(VCInstallDir)PlatformSDK\include;$(IncludePath);
2.Library directories -> $(VCInstallDir)PlatformSDK\lib;$(LibraryPath);

Visual Studio 2012 32bit compilation on 64bit system

I have recently wanted to build a dll plugin for a program. Problem is, the program is 32bit, but by default my Visual Studio 2012's C++ compiler creates 64bit binaries, and I don't know how to change it - I've found the Configuration Manager and tried to create a new platform but there's only x64 as an option.
Am I trying to set the target architecture in the wrong place or what? Is there an update or something I can download so that I can create my dll? Is there a compiler switch that I can set somewhere?
Hope this screen helps:
To build for 32 bit architecture, you have to open project properties window, and then Linker options.
Set the value of Target Machine option to MachineX86.
Check the Build Configuration (Build -> Configuration Manager), and ensure that your DLL project for 32-bit is selected.
Check the linker settings, and ensure correct path is given.
After build, check that .DLL is produced at correct path, and is 32-bit (should be!).
You can use Dependency Walker to check if DLL is 32-bit or 64-bit.
You also didn't mention if /clr option is used with this DLL or not. With /CLR, managed binary is produced. Though this option wouldn't alter bit-ness of the binary, you can just check if this is the case.

how to build 64 bit managed c++ dll in visual studio 2010?

I've got a managed c++ dll, and it builds fine in x86 format. However, when I change the format to x64 in configuration manager, it won't recognize .Net namespaces, like System etc.
What else should I change to be able to build the 64-bit version of the app?
I'll need to be able to build the app for x64 and for x86.
When you changed your project to target x64, the settings that tell the compiler to target the .NET Framework obviously didn't get transferred over.
Check your project's properties to ensure that all of the x64 settings match with the x86 settings.
More specifically, you're looking for the "Common Language Runtime Support" property. On recent versions of Visual Studio, this should probably be set to Common Language Runtime Support, Old Syntax (/clr:oldSyntax) for Managed C++.
You would create an 'x64' configuration there is a second drop down box for 'copy settings from'. That also has to be properly set to copy setting from your other configurations.
But since you have already done that, perhaps all your assembly referenences didn't copied over to your 'x64' configuration. Have you checked in your x64 project settings to see if they are there? Open up your project settings and select:
Common Properties -> Framework and References
Then make sure you have a reference to System (At least)