I'm using OpenSceneGraph libraries in my application and I want to link them statically, so I don't have to carry DLLs with binary. I have downloaded OpenSceneGraph 3.4.0 sources and generated Visual Studio project by cmake. I did disabled DYNAMIC_OPENSCENEGRAPH and DYNAMIC_OPENTHREADS in cmake GUI. After that I successfully compiled OSG and have static libraries (.lib). In my application I added include and library directories in project properties -> VC++ Directories -> Include Directories & Library Directories (I'm using Visual Studio 2013 by the way). I also added directory with OSG .lib's in Linker -> General -> Additional Library Directories and typed all required libs in Linker -> Input -> Additional Dependencies:
ot20-OpenThreads.lib
osg130-osg.lib
osg130-osgUtil.lib
osg130-osgGA.lib
osg130-osgDB.lib
osg130-osgViewer.lib
osg130-osgText.lib
opengl32.lib
osgdb_3ds.lib
osgdb_freetype.lib
osgdb_png.lib
And I'm still getting unresolved externals errors for OSG symbols. I also tried setting General -> Character Set to Unicode but it didn't help (in OSG project generated by cmake I have Multi-Byte Character anyway). I don't have any ideas how to solve that now, it's my first time compiling application with static linked libraries.
I would really appreciate any help.
P.s. Sorry for no code, I can't provide it but I try to give as much details as I can. With dynamic linking I can build my application without any problems.
I managed to solve this problem myself.
I was missing two more libraries in Linker -> Input -> Additional Dependencies:
msvcrt.lib
libcmt.lib
And I also had to add preprocessor definition OSG_LIBRARY_STATIC in C/C++ -> Preprocessor -> Preprocessor Definitions. The last thing was adding these few lines of code in my main.cpp to link OSG plugins:
#ifdef OSG_LIBRARY_STATIC
USE_OSGPLUGIN(freetype)
USE_OSGPLUGIN(png)
USE_OSGPLUGIN(3ds)
#endif
Now my application is successfully compiling and working :)
P.s. On first build I had errors with PNG and FreeType plugins which were caused by lack of .lib-s for libpng and freetype. There errors were solved in my case by adding libpng16_static.lib and freetype250.lib to Linker -> Input -> Additional Dependencies and copying them into my libraries directory (obviously other plugins would depend on other libraries).
Related
I am trying to extend my knowledge of constrain programming and I want to build a simple example using google's or-tools in VS2015.
However I am constantly nagged by those linker errors. LNK2019 and LNK2001. Why is linking in VS so darn hard.
Google's or-tools comes in a perfect folder, with an include subfolder and lib subfolder with one single .lib file.
I have added Additional Library Dependencies.
Configuration Properties -> Linker -> General Additional Library Dependencies : C:\PATH\or-tools.VisualStudio2013-64b\lib
Set the Input under the Linker properties section.
Configuration Properties -> Linker -> Input Additional Dependencies : ortools.lib
Infomed VC++ where the include directory is.
Configuration Properties -> VC++ Directories : C:\PATH\or-tools.VisualStudio2013-64b
However it is still throwing link errors when building the solution. What am I missing here.
Thanks in advance.
edit:
spelling
Since the VS2013 and VS2015 compiler versions are incompatible, you have to build the lib from source. Though beware that this might entail a bit more work when linking with VS2015. Specifically I've had to manually resolve the following issues:
Change protobuf-3.0.0-beta-1 to protobuf-3.0.0-beta-2(bonus. not really necessary)
gflags 2.1.2 failed to compile due to a conflict of names around snprintf. To resolve this download the latest gflags version from GitHub and overwrite the one in %OR_TOOLS%\dependencies
Look up all VS solution files (.sln) in dependencies\sources\cbc-2.9.7 and convert to VS2015 format by simply double clicking them and following the instructions.
Add the following code to makefiles\Makefile.port
ifeq ("$(VisualStudioVersion)", "14.0")
VISUAL_STUDIO=2015
VS_RELEASE=v140
VS_COMTOOLS=140
else
...
endif
Replace Visual Studio 12 2013 with Visual Studio 14 2015
Rerun make third_party after each step.
Or you can just download the end result, linked on Windows 10 x64 VS2015 update 1. I've included the whole folder after running make third_party && make cc.
I'm trying to build a DLL using Visual Studio 12 Community that depends on OpenCV.
I want to include OpenCV as .lib files so I don't have to distribute it seperately, but I need my file to be built as a DLL.
But I can't configure Visual Studio to import a lib into a DLL. If in
My Project -> Properties -> Configuration Properties -> General -> Configuration Type,
I select "static library (.lib)" and in:
My Project -> Properties -> Configuration Properties -> VC++ Directories -> Library Directories,
I select the path to the OpenCV .lib files, and in
My Project -> Properties -> Configuration Properties -> Linker -> Addition Dependencies
I add a reference to each .lib, it works.
But if I change the Configuration Type do "dynamic library (.dll)", Visual studio tells me:
opencv_highgui2410d.lib(window.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug' in VectorsImport.obj
It seems I can only make .lib files with .lib files. But that seems very unlikely. I've looked this up, but I only find guides on how to make .lib files or .dll files or one out of the other. This must be pretty simple, but I can't figure it out. I'm used to Linux, where a .o can pretty easily be included into a .so . This puzzles me.
The error indicates that you are trying to link a OpenCV module which has been compiled for using the static C/C++ runtime with debugging support with a module VectorsImport.obj (probably from your own project), which has been compiled for using the dynamic C/C++ runtime with debugging support. The four variants of the C runtime library are not compatible in the Microsoft SDK, so all object files (either from your project or from statically linked libs) have to match on that setting. On Visual Studio 2010, it could be found at C/C++-Compiler -> Codegeneration -> Runtime library.
Please note that (as the bold face should emphasize) it is not about OpenCV being a DLL or .lib, but in case OpenCV is linked as separate DLL, it is allowed to use a different kind of C runtime library, so the mismatch does not matter.
For learning purposes, i wanted to create a static library, a "package" of the lib files used in opencv to then link it against my app "opencvuser". Doing so, i get tremendous amounts of erros. (LNK2005 and LNK2019)
My Setup:
Project: staticLib
I've created a static library application without precompiled headers.
Under librarian i've put D:\OpenCV248\build\x64\vc10\staticlib as an additional library
directory. And I've specified all available .lib files as additional
dependencies. (opencv_core248d.lib, opencv_imgproc248d.lib, opencv_highgui248d.lib, ...) Source
Project: opencvuser
I've added C:\OpenCV240\build\include as an additional include directory
Then i've listed "staticLib" under "Properties -> References"
What i expect: Now i should get the same functionallity, as i would add the opencv lib files instead of my built staticLib.lib is my expectation correct?
What i've checked so far:
All Projects are x64
Runtime-Library is set in both Projects to "Multi-threaded Debug"
Anyone knows if the Runtime-Library setting on the static libraries are set to "Multi-threaded Debug"?
You are getting those linker errors because the OpenCV libs you are trying to use were statically linked against the CRT. In your project, you are dynamically linking to CRT and these things won't mix. I would recommend that you don't try to create a "package" of all the OpenCV libs and instead just link to the specific libs you need where you need them.
But I am also going to show you how to solve your problem:
You need to recompile OpenCV without statically linking to the CRT.
You can check out the OpenCV documentation for instructions on how to compile OpenCV using CMake and Visual Studio 2010.
When you run CMake, after you pressed the "Configure" button, look for an option called "BUILD_WITH_STATIC_CRT" and disable it. Then you can press "Generate", open the solution with VS2010 and compile OpenCV.
In your VS2010 project, use the following settings:
In the "opencvuser" project configuration, under Librarian, additional library directories you need to add the path to where the .lib files that you built are located. For me, it's in "c:\opencv248\mybuild\lib\Debug\".
Under Additional Dependencies, you need to include all the OpenCV lib files (opencv_core248d.lib, etc). I also needed to include Comctl32.lib and zlibd.lib because if I didn't I would get some linker errors.
Here are the dependencies I put in:
opencv_calib3d248d.lib
opencv_contrib248d.lib
opencv_core248d.lib
opencv_features2d248d.lib
opencv_flann248d.lib
opencv_gpu248d.lib
opencv_haartraining_engined.lib
opencv_highgui248d.lib
opencv_imgproc248d.lib
opencv_legacy248d.lib
opencv_ml248d.lib
opencv_nonfree248d.lib
opencv_objdetect248d.lib
opencv_ocl248d.lib
opencv_photo248d.lib
opencv_stitching248d.lib
opencv_superres248d.lib
opencv_ts248d.lib
opencv_video248d.lib
opencv_videostab248d.lib
Comctl32.lib
zlibd.lib
Also, in the "opencvuser" project you need to add an empty .cpp file. If you don't add this file, the solution will be empty and Visual Studio won't compile it. I just added a file called "dummy.cpp" to the project. That file is completely empty. Don't put a "main()" function in it because it will collide with the main function in the other project and you will get an error.
In the "staticlib" project, under Linker->General, Additional library directories, you need to include the path to the opencvuser.lib file. For me, it's "..\debug". Also, under Linker->Input, Additional Dependencies, you need to add the "opencvuser.lib" file.
Set project dependencies
You also need to make sure that the projects are built in the right order (first opencvuser, then staticlib). To do this, right-click on the solution and choose Properties. In that window, under Common Properties->Project dependencies, make sure that "opencvuser" does not have a dependency on "staticlib", but "staticlib" must have a dependency on "opencvuser".
That's it, now your project should work. Here are the contents of the two files, and the project running.
I am having issues compiling a basic openGL program on VS 2012. I get a build error upon compiltation giving me:
1>LINK : fatal error LNK1104: cannot open file 'glew32.lib'
I followed the instructions given to me by the documentation for GLEW.
In your OpenGL project open Project -> Properties -> Configuration Properties -> Linker -> Input -> Additional Dependencies -> add glew32.lib.
Also you must include #include in your sources; For that add path to your glew folder: Project -> Properties -> Configuration Properies -> General -> VC++ Directories -> Include Directories and Library Directories;
C/C++ Tab -> General -> Additional Include Directories - Add lib folder there
I have also added the glew32.dll onto my Debug folder within my project folder along with the executable. So far I keep getting this error.
If you need any more further clarification of the steps I have done please don't hesitate to ask
In all honesty, there is no real benefit to using the DLL version of glew (short of reduced executable size, but this hardly matters on modern Windows PCs).
It is not like you can simply drop a new version of the DLL into your application and use extensions that you never used before. Likewise, bug fixes are so infrequent/unnecessary with a library that basically just parses the extension spec. files that using the DLL as a means of fixing extension loading bugs in shipped software is also not practical. Statically linking to glew (this means glew32s.lib) makes much more sense in the long run.
The static linking library is also more portable on Windows, it will work with MSVC and MinGW (whereas the DLL library only works with MSVC). Link against glew32s and put that in whatever directory you decided to use for additional library dependencies.
Here is a sample solution configuration for a project I wrote that uses glew. I have established a convention for this particular software where compile-time dependencies are stored under platform/<Subsystem>. Thus, I have glew32s.lib (32-bit) and glew64s.lib (64-bit) in ./Epsilon/platform/OpenGL/glew{32|64}s.lib
Steps to Use Classes form another project (Add header and solver linker errors)
To be able to add the header from another project, first go to "Properties > c++ > General > Additional Include Directories" and add the directory that contains the header. Now you will be able to add the header of the class from the other project, but running the project will still cause Linker Errors.
Add __declspec(dllexport) before the class you are using for the other project. This can be added in the header file of that class. This should be added right before the function or variable or class name. Now you will get a lib file. (if placed in wrong place, you can get this warning: https://msdn.microsoft.com/en-us/library/eehkcz60.aspx)
"Properties > Linker > Additional Library Directories". Specify the location of the lib file that is generated.
"Properties > Linker > Input > Additional Dependencies”: Add the name of the lib file.
This sounds like the library has been specified as a dependency, but the linker/additional search path(s) has not been set to include the directory where the library is located.
This may help.
It happened to me under this situation, I clean the solution and build it again, then many errors like LNK1104 occur.
After trying to restart IIS, I build solution successfully without LNK1104 errors. I do not know why, but restarting IIS takes much more time than normal, so I guess something is used by other IIS worker process.
Just give a shot to see if this magic happens on you.
This question is old and marked solved, but I had a similar problem symptoms with a completely different solution. So just in case anyone else stumbles in here:
It appeared that because I had 2 projects under one solution (a dll and an exe), the building order was mixed (from the output window):
1> Rebuilding project1..
2> Rebuilding project1..
1> file1.cpp
2> file1.cpp
and so on. By the message you copied, it appears you too have more than one project under one solution. One project was looking for the *.lib file that the other build hadn't created yet.
Solution:
Right click on "main" project -> Build Dependencies -> Project Dependencies.. -> Mark which project the main one depends on.
I'm going to get a book that uses Xerces C++. I'm currently using VS 2010 ultimate, so the program doesn't miss any features. I've downloaded the precompiled binaries for windows x86 VC10. My question is what do I have to do to my environmental variables and files to be able to have Visual studio import the header files i.e. #include . I have no experience linking external libraries, so I need a simple explanation.
Right click on your project -> Properties -> C/C++ -> General -> Additional Include Directories
Include the path of Xerces include files.
For Lib Properties Linker -> General -> Additional Library Directories
Include the path of Xerces lib files.
In Linker -> General -> Input -> Additional dependencies
Add the libs required for linking.