Visual Studio 2010 C++: How to tell which LIB files the linker actually tries to link? - visual-studio-2010

I am working on an (unmanaged) x64 Win32 C++ application in Visual Studio 2010 Pro, and keep getting a strange linking error.
This application makes use of the LoadImage() Windows API function through including windows.h. While the application compiles fine in the Release configuration (and LoadImage() does its job), I cannot get the executable linked in the Debug configuration. I keep getting this error:
Redacted.obj : error LNK2019: unresolved external symbol __imp_LoadImageW referenced in function "public: int __cdecl Redacted::Redacted::Execute(void)" (?Execute#Redacted#Redacted##QEAAHXZ)
C:\Users\redacted\Documents\Visual Studio 2010\Projects\Redacted\x64\Debug\Redacted.exe : fatal error LNK1120: 1 unresolved externals
If I switch from Unicode to non-multi-byte character set, the error message will change from LoadImageW() to LoadImageA() accordingly, but otherwise persist. As I cannot find any relevant differences in the properties for the Release and Debug configuration, I am at a loss why it will compile in one, but not the other. User32.lib is correctly set as an Additional dependency for the Linker in both configurations, and the /MACHINE:X64 flag is set in both as well.
Since the linker doesn't complain about not finding the User32.lib, I am led to believe that it tries to link a wrong version from the Platform SDK, i.e. the 32-bit one. But how can I find out which exact copy of a LIB file the linker actually tries to use?

Check the linker paths in the global configuration settings. Most probably one of those is wrong.
Beyond that, I believe there's a linker /VERBOSE flag (or something similar) which will display the information you're looking for. It's somewhere in the linker settings for the project you're building.

Related

Cannot find or open PDB File error when running the program even though it builds successfully

I have a project in visual c++ where I am referring some external DLL.
I have already included the lib directory in linker section and mention it in the input section of the linker and also included the same in c/c++ General Additional Include Directories section.
Thus the project compiles successfully but whenever I try to run it; it fails with an error "Application was unable to start correctly" but if I see the output section it seems everything is loaded correctly but against that particular Dll it says that "Cannot find or open the PDB file".
How to fix this error so that I can run my program. It is an MFC program running in Visual Studio 2010.
when I run the program through the Dependency Walker, most of the API-MS-WIN-CORE-HEAP, FILE, and EXT-MS-WIN-SESSION USERMGR -l1-1-0.dll many similar to this are unavailable. I even tried to repair the visual studio it didn't work. Is there any idea how to go about it
0x0000007b sounds familiar to me.
Most likely that is due to 32/64 bit library mixture you are linking with.
Either you are building for x64 and linking with a win32 external library or vice versa.
In your Visual Studio project settings separately configure platform architectures you are compiling for and then you can choose the profile which you are actually compiling for.

Linker warning: uuid.lib(unknwn_i.obj) : MSIL .netmodule or module compiled with /GL found; restarting link with /LTCG

I have a Visual C++ solution with static and dynamic libraries, and one executable that uses these libraries. I'm currently upgrading from Visual Studio 2010 to Visual Studio 2015, I also upgraded the SDK version the projects use to 10.0.10586.0 (Windows 10).
Everything compiles and links correctly, except for one linker warning:
uuid.lib(unknwn_i.obj) : MSIL .netmodule or module compiled with /GL found; restarting link with /LTCG; add /LTCG to the link command line to improve linker performance
uuid.lib is part of the Windows SDK. It might have been compiled with /GL, but does that mean that every executable that gets linked against this library must use /GL? That would be pretty constraining. By the way, if I switch to Windows SDK version 8.1 (but still using Visual Studio 2015), the warning goes away.
I have a feeling that something else might be wrong here (even though the linker points to a very specific location), because I found zero Google references of this particular error with this particular object file, which is very strange...
Any ideas?
Edit:
The warning is present in both Debug and Release builds
According to link.exe with /VERBOSE, X.obj (and only that object) in my executable project is referencing unknwn_i.obj, that's why it is "pulled in". This project does not use /GL nor /LTCG at all (checked the project properties, each cpp file's properties in the project, and there are no "standalone" property sheets in the solution)
I also tried removing all libraries linked to the exe project from it's linkage list. When only the default ones were linked (kernel32.lib, uuid.lib, etc.), the warning still persisted (aside from tons of unresolved references, but that's because I intentionally removed libraries). So it's not external libraries that cause this issue.

Qt, VC 2010 and static libraries

I need to use a static library in my Qt5 project. I'm using VC++ 2010 as my compiler and QtCreator as IDE.
If I use the dynamic version (.DLL) everything works fine.
If I try to use the static version (.LIB) it seems like the library is looking for other dependencies that can't be satisfied.
Sadly, using the DLL is not an option for my project.
The point is that if I try to use the static library from VC++ IDE everything works fine.
Please note that I can use other VC++ headers without any problem in my Qt project.
It seems like the compiler can find everything it needs (basically, my source code and all the required headers) while the linker is missing something.
error: LNK2019: unresolved external symbol _imp_SystemTimeToVariantTime#8 referenced in function "bool __cdecl SystemTimeToMinute(struct _SYSTEMTIME *,unsigned long *)" (?SystemTimeToMinute##YA_NPAU_SYSTEMTIME##PAK#Z)
SystemTimeToVariantTime is defined in OleAut32.lib.
Am I wrong expecting the linker to automatically look for needed libraries and headers based on the content of the global variables INCLUDE and LIB?
Solved.
The problem was that I was trying to include external (SDK) libraries using
LIBS += -l OleAut32.lib
While I had to simply use
LIBS += OleAut32.lib
Well, problem solved.
I hope this can help someone in the future!

Why VC2010 tries to link the MFC42 dll after I upgraded my VC6 project

I upgraded my Win32 project from VC6 to VC2010, and fixed a lot of codes which only work on VC6, compiling is OK, but when the project began linking, it failed with the following message
LINK : fatal error LNK1104: cannot open file 'mfc42ud.lib'
I tried to find where the MFC42ud is referred, but I cannot, it drives me mad.
Could anyone help me?
updated:
Now I downloaded the MFC42ud.lib, but there is still link error, now it becomes
atlsd.lib(atltypes.obj) : error LNK2005: "public: __thiscall CRect::CRect(void)" (??0CRect##QAE#XZ) already defined in mfc42ud.lib(MFC42uD.DLL)
atlsd.lib(atltypes.obj) : error LNK2005: "public: int __thiscall CRect::Width(void)const " (?Width#CRect##QBEHXZ) already defined in mfc42ud.lib(MFC42uD.DLL)
atlsd.lib(atltypes.obj) : error LNK2005: "public: int __thiscall CRect::Height(void)const " (?Height#CRect##QBEHXZ) already defined in mfc42ud.lib(MFC42uD.DLL)
LINK : fatal error LNK1104: cannot open file 'mfcs42ud.lib'
It seems it is not compatible if I just copy the MFC42ud.lib, so now error is multiple definition
OK, at last I resolved it. It is because there are some libs I need link, and there is some linkage information in these libs.
The reason is the Microsoft VC specified preprocessor #pragma comment(lib, "some.lib")
Actually it is really a bad solution, especially to link system provided libs, like mfc libs. Even you upgraded the project, it still wants to link the old mfc libs.
The solution is to ignore the old mfc libs.
It is Unicode Debug version of the MFC DLL for Visual Studio 6, part of optional parts during Visual Studio 6 installation.
Install it from the VS6 installation CD.
Reference: http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/46a26f16-a407-4628-962b-2a6899391293/
p.s. it's Google's first result, by the way.
In my case, my project was linking against another library, and that library had been built with
#pragma comment(lib, "mfc42.lib")
inside it.
Linking that library into my project instructed my project to link against mfc42.lib, even though I never had any such setting.
Tracking down and removing the offending library was not easy.

Linker error with debug build with different compiler versions

We have a DLL, built with MS Visual Studio 2010, in release mode. We provide this DLL to different customers, along with a .lib file. The functions in the DLL are exported with:
extern "C" __declspec(dllexport) int analyze(int id);
Our customers have two applications that makes use of this DLL. Both of these applications import the DLL functions using:
extern "C" __declspec(dllimport) int analyze(int id);
One of these applications is built with MS Visual Studio 2010. This application can be built successfully in both debug and release modes.
The other application must unfortunately use MS Visual Studio 2005 as its build environment. In this application, the release build can be built successfully, however, when we try to build in debug mode, we get linker errors:
LNK2019: unresolved external symbol __imp_analyze referenced in function "void __cdecl process(char const *,char const *)" (?process##ABCERFG0#Z)
Can someone help me understand what we are missing here? Are we exporting the functions in a manner that is not portable across compilers? What's the solution?
Regards,
The .obj file format is highly conserved between VS2005 and VS2010. This should not be a problem, especially since it is a simple non-mangled symbol reference. And especially not when it works in the Release configuration but not in Debug. A simple explanation is always better than a convoluted one: your customer simply forgot to add your .lib file to the linker's Additional Dependencies setting.
Beware that the setting change needs to be made for both configurations, use the "Configuration" combo in the upper left corner of the dialog.
You can help your customer fall into the pit of success by using #pragma comment(lib, "mumble.lib") in your .h file.

Resources