Error LNK1104 when upgrade from VS2008 to VS2010 [duplicate] - c++

I am trying to upgrade a Visual C++ 2008 project to a Visual C++ 2010 project. when the upgrade is finished and I compelled it, I got this error:
fatal error LNK1104: cannot open file 'mfc90d.lib'
I think it should reference to "mfc100d.lib", I tried many ways to fix it but failed.
does anyone meet the same problem?

Possible causes include
a) You are not rebuilding all source files - try deleting all output obj and lib to be sure
b) You are linking a 3rd party static lib that was built with VC9 - you will need the VC10 version
c) Your header paths are pointing at VC9 headers (check your solution's path options)
d) Your project includes an explicit reference to mfc90d for some other reason.
Next diagnosis step: set the /verbose option on the linker and work out exactly which obj is dragging in mfc90d.lib.
Martyn

I found the problem to my missing MFC100.dll by doing a global search of all my source files for the definition "_MFC_FILENAME_VER". I found following definition in one of my header files:
#define _MFC_FILENAME_VER 100
which was used in this block:
#ifdef _DEBUG
#pragma comment(lib, "mfc" _MFC_FILENAME_VER "d.lib")
#pragma comment(lib, "mfcs" _MFC_FILENAME_VER "d.lib")
#else
#pragma comment(lib, "mfc" _MFC_FILENAME_VER ".lib")
#pragma comment(lib, "mfcs" _MFC_FILENAME_VER ".lib")
#endif
I changed it to:
#define _MFC_FILENAME_VER 110
so it would compile with VS 2012's version of MFC (mfc110d.lib).

Related

Use libraries inside injection DLL file

I'm working on the internal mod menu for one game and I want to use CPR library inside my DLL to get the latest version of offset from the server after injection. right now I get a static version of CPR package with vcpkg and move all .lib file and include file to my project and add them in my include and lib directories and use it like this :
#pragma once
#pragma comment(lib, "crypt32.lib")
#pragma comment(lib, "ws2_32.lib")
#pragma comment(lib, "zlib.lib")
#pragma comment(lib, "libcurl.lib")
#pragma comment(lib, "cpr.lib")
#include "cpr/cpr.h"
cpr::Response r = cpr::Get(cpr::Url{ "https://myurl.com/getoffset" });
cout << r.status_code << endl;
cout << r.text << endl;
string json= r.text;
It's work fine without any problem but as you can see it's a bit messy with all those "#pragma comment" so I tried to use a dynamic version of CPR so after compiling it I have 3 DLL files :
myMode.dll
libcurl.dll
zlib1.dll
the problem now is I must put "zlib1.dll" and "libcurl.dll" inside game folder near .exe file otherwise it won't inject; is there any way to locate them inside my DLL and tell DLL to use that location?
or just use it like this but remove this "#pragma comment" somehow and add the location for all of them in visual studio ?
Everything you need to know about DLL search paths is well documented here.
The easiest approach would be to just statically link with libcurl and zlib instead of using the DLL stub libraries. What's the downside of that?
Otherwise, all your dependent DLLs need to be in your EXE folder, the current working directory (usually the same as the EXE folder), a system directory (no!), or the PATH.
If your extension has an installer, then maybe it just updates PATH with your install folder of your DLL and all its dependencies.
As for the "messy" pragma comment statements. The standard approach is to add these via the Visual Studio project IDE. That gives you better control of the link search path so you don't have to dump all the stub .lib files in the same folder you build from.

Auto link static libraries from header file

I'm writing a library for in-house use and I want to automate the linking of static library (.lib) files so users don't have to know all the libraries they need. We use Visual Studio 2015 so I've knocked something up using pragma which seems to work but I'm getting a lot or warnings, which I presume are caused by what I'm doing.
Warning LNK4221 This object file does not define any previously
undefined public symbols, so it will not be used by any link operation
that consumes this library
I include this code in all the public facing interface header files and extend it to include internal and external libraries necessary.
#ifndef GFXK_LIBS_NET_IMPORT__
#define GFXK_LIBS_NET_IMPORT__
#ifdef _DEBUG
#ifdef WIN32
#pragma comment( lib, "gfxk_net_Debug_Win32-v140.lib" )
#else
#pragma comment( lib, "gfxk_net_Debug_x64-v140.lib" )
#endif
#else
#ifdef WIN32
#pragma comment( lib, "gfxk_net_Release_Win32-v140" )
#else
#pragma comment( lib, "gfxk_net_Release_x64-v140" )
#endif
#endif /*_DEBUG*/
#endif /*GFXK_LIBS_NET_IMPORT__*/
My question is how do I do this nicely so that I can remove this hack job. I'm looking for something similar to what Boost does with it's auto linking, I can't find out how to do this. I'm not too worried about cross platform as library targets only Windows at this time.
You can specify .libs path in your project settings Configuration Properties -> Linker -> Input -> Additional dependencies. You may specify different settings for different configurations and platforms. That would be a clearer way.
But the warning won't appear after you add functions to your .lib and use them in your project. Warning is just saying that this pragma-lib statement is pointless as no functions are really imported.

d3dx11.lib not found?

I'm using Windows 8 / Visual Studio 2012, C++11 and Direct3D 11 for development.
I include the Direct3D libraries like this
#pragma comment(lib, "dxgi.lib")
#pragma comment(lib, "d3d11.lib")
#pragma comment(lib, "d3dx11.lib") // <-- error LNK1104: cannot open file 'd3dx11.lib'
#pragma comment(lib, "d3dx10.lib")
However, the linker can't seem to find the d3dx11.lib. After adding the path where the library is located to the 'Library directories' of the project, the linker still can't find those files. Even after I copied the lib files into the project directory itself, it doesn't work.
I installed the Windows 8 SDK as well as the DirectX SDK from June 2010. Am I missing anything?
When dealing with this myself, I started here:
Where is the DirectX SDK?
then - in about the middle of that page, reading about DirectXMath:
DirectXMath
It's pretty much just including the right header files and changing "D3DX" prefixes to "XM". Not quite that simple, but that's the general idea.
Your first program will probably have inclusions/usings like this:
#include <d3d11.h>
#include “DirectXMath.h”
#include “DirectXPackedVector.h”
using namespace DirectX;
using namespace DirectX::PackedVector;
struct mystruct
{
DirectX::XMFLOAT3 position;
DirectX::PackedVector::HALF packedValue;
};
Of course, it's not considered best practice to have "using namespace", but in this one instance I found that "DirectX::" on every line of my program was making my program almost impossible (for me) to read - so I went with the "using".
Good luck!
Probably you included bad path in properties, Instead "*DirectxSDK/Lib/x86", you included ""*DirectxSDK/Lib".
I was running into this issue as well using VS2010, but I just found the solution. You need to provider the Linker with the library file that you are having trouble with.
Project->Properties->Configuration Properties->Linker->Additional Library Directories
Then add the library file that you want into there. Worked for me, hopefully works for you too, and then you don't have to mess with DirectXMath and finding new tutorials for it.

Setup OpenCV in Visual Studio 2010

I have created a new project (without code) that uses OpenCV.
I the project properties I set the requirements like below:
library directory:
C:\OpenCV-2.2.0\lib\Debug
include directories:
C:\OpenCV-2.2.0\include\opencv
C:\OpenCV-2.2.0\include\opencv2
C:\OpenCV-2.2.0\include
The first lines of code :
#pragma comment(lib, "opencv_core230d.lib")
#pragma comment(lib, "opencv_highgui230d.lib")
#pragma comment(lib, "opencv_video230d.lib")
#pragma comment(lib, "opencv_ml230d.lib")
#pragma comment(lib, "opencv_legacy230d.lib")
#pragma comment(lib, "opencv_imgproc230d.lib")
When I built my project I got no error but when I include the <cv.h> file, unresolved external errors appear.
To solve my problem any guide may help me.
You haven added the src directory files. Look at this page: http://opencv.willowgarage.com/wiki/VisualC%2B%2B_VS2010
You need to add these folders:
Source Directories... add: 'C:\OpenCV2.1\src\cv; C:\OpenCV2.1\src\cvaux; C:\OpenCV2.1\src\cxcore; C:\OpenCV2.1\src\highgui; C:\OpenCV2.1\src\ml;'

How to embedd openCV Dll's in Executable

I wrote an image matching tool (console application, without gui or windows), using openCV.
I want to port my EXE file to another computer but it asks for opencv dlls (opencv_core220.dll, opencv_highgui220.dll, ...)
My question is how to do it. I see two ways any of them is good:
Recompile opencv as static library (.lib instead of .dll). That didnt work. I get 10 linker errors regarding cap_vfw.obj
If possible, how to merge/embedd DLL's into exe file.
I tried to use ILMerge, but it doesnt work (Error: coul'd not load assembly from a.exe file) since it is designed for .Net only
P.S. - I am using visual studio 2005, on windows, c++ compiler, openCV 2.2
I found an answer.
You must open the original openCV project and recompile all the relevant parts in static library mode.
Do it for each project starting from libjasper and alphabetically until opencv_video. Also do the same for zlib project
For each project, go to project properties\configuration properties\general\configuration type and set it to static library
Now recompile those projects. They will create many large lib files (of up to 10MB) each. Those files are located mainly in modules directory of opencv. You must find them and copy to the directory when you keep your regular lib files when compiling against dll's. Now is a tricky part
You have to include in your code more libraries, than when you compile against dll's
Here is an example what your code should look like this. Sorry that it is not formatted well. Probably html bugs of this page:
#include "cv.h"
#include "highgui.h"
using namespace std;
using namespace cv;
// Directives to linker to include openCV lib files.
#ifndef STATIC_LIBRARY_LINK
// Linking against DLL. For each 'lib' file that appears below, final EXE will need a DLL.
// Core of openCV
#pragma comment(lib, "opencv_core220.lib")
#pragma comment(lib, "opencv_highgui220.lib")
#pragma comment(lib, "opencv_imgproc220.lib")
// Calibration and image matching
#pragma comment(lib, "opencv_flann220.lib")
#pragma comment(lib, "opencv_features2d220.lib")
#pragma comment(lib, "opencv_calib3d220.lib")
// Other libs that might be needed
/*#pragma comment(lib, "opencv_gpu220.lib")
#pragma comment(lib, "opencv_video220.lib")
#pragma comment(lib, "opencv_legacy220.lib")
#pragma comment(lib, "opencv_ml220.lib")
#pragma comment(lib, "opencv_objdetect220.lib")
#pragma comment(lib, "opencv_ffmpeg220.lib")
#pragma comment(lib, "opencv_contrib220.lib") */
#else
// Static linking. No DLL's would be required but EXE file will be bigger
// and linking in debug mode might produce many warnings since *.pdb are not always
// present with the lib files
// Core of openCV. Must be compiled as lib and not as dll's
#pragma comment(lib, "opencv_core.lib")
#pragma comment(lib, "opencv_highgui.lib")
#pragma comment(lib, "opencv_imgproc.lib")
// Calibration and image matching. Must be compiled as lib and not as dll's
#pragma comment(lib, "opencv_flann.lib")
#pragma comment(lib, "opencv_features2d.lib")
#pragma comment(lib, "opencv_calib3d.lib")
// Image I/O auxillary libraries. Must be compiled as lib and not as dll's
#pragma comment(lib, "libtiff.lib")
#pragma comment(lib, "libpng.lib")
#pragma comment(lib, "zlib.lib")
#pragma comment(lib, "libjasper.lib")
#pragma comment(lib, "libjpeg.lib")
// OpenCV linear algebra methods. Must be compiled as lib and not as dll's
#pragma comment(lib, "opencv_lapack.lib")
// Auxillary libs, found in visual studio microsoft sdk
#pragma comment(lib, "vfw32.lib")
#pragma comment( lib, "comctl32.lib" )
//#pragma comment(lib, "window_w32.lib") // Not needed
#endif
int main(void){
// Your code here
return 0;
}
The term you're looking for is static linking. "DLL" stands for "Dynamically Linked Library", which is the opposite of static. You cannot statically link a dynamically linked library. You need a "normal" library for that.
Go to the properties for the project you are building (right click on project in the solution explorer and seleck propeties). Now expand the Configuration properties->Linker option and under General, set the path to the statically linked libraries (i.e., with .lib extensions). Now select the Configuration properties->Linker->Input option and type in the names of all the libraries you want it to statically link to. Now rebuild the project and they should be linked in to the executable. It will warn you if the paths to the files are not correct.