Why VC2010 tries to link the MFC42 dll after I upgraded my VC6 project - visual-c++-6

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.

Related

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!

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

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.

Linker error IGameExplorer in Visual C++ Express Edition 2010

I want to add my game programtically to the game explorer.
In order to do this I use the IGameExplorer interface in my code.
When i try to compile and link my code with Visual C++ 2010 Express Edition. I get the following linker error:
error LNK2001: unresolved external symbol _CLSID_GameExplorer
How do resolve this error? Is there any library to link against?
Since you're using Visual C++, you can try using __uuidof(GameExplorer) instead of CLSID_GameExplorer. The GameUX.H file defines:
class DECLSPEC_UUID("9A5EA990-3034-4D6F-9128-01F3C61022BC")
GameExplorer;
#endif
which tells the C++ compiler that the CLSID for GameExplorer is 985EA990-3034-4D6F....

building multiple project in visual studio

I have projects A,B in visual studio under the solution AB.
B is a static library with a simple method named "add" which is already declared with __declspec(dllexport)
and A is an application depending on B.
the build order is configured B -> A
B.lib is getting created properly but i am getting "error LNK2019: unresolved external symbol _add referenced in function _main"
I also referenced the B.lib's directory in Additional dependencies in A's Project settings page
Please let me know where i am making the mistake....
sry got the solution to my problem...
C:\Documents and Settings\absasdf\My Documents\Visual Studio 2010\Projects\AB\Debug; added to Linker>General>Additional Library Directories
and
B.lib added to Linker>Input>Additional Dependencies
Now its working fine..

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