Including a visual 2005 library in a visual C 2010 project - c++

I have a c++ qt5 project under Microsoft visual studio professionnal 2010. I have to include a library .lib in my project that is compiled with Microsoft Visual 2005 and depends of the visual 2005 vorsion of the STL. As a consequence when I try to compile my project I got the following link error (here are the three first errors among more):
libmegamatching.lib(BImage.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: int __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::sputn(char const *,int)" (__imp_?sputn#?$basic_streambuf#DU?$char_traits#D#std###std##QAEHPBDH#Z)
libmegamatching.lib(makeCanonicalImage.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: int __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::sputn(char const *,int)" (__imp_?sputn#?$basic_streambuf#DU?$char_traits#D#std###std##QAEHPBDH#Z)
M_Control.lib(Logger.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: int __thiscall std::basic_streambuf<char,struct std::char_traits<char> >::sputn(char const *,int)" (__imp_?sputn#?$basic_streambuf#DU?$char_traits#D#std###std##QAEHPBDH#Z)
My collegue solved this problem encapsulating the library into a microsoft managed C++ library…but I didn't try that yet because I am not excited about adding a .NET dependencie to my project.
Is there other solutions? Of cours I cannot recompile the library with visual 2010 nor change my visual version.
I was thinking about making a visual 2005 std library .lib…but I don't know if there is a way to do that?
Thanks in advance

You either need to [a] recompile the library using Visual C++ 2010 or [b] encapsulate the library within its own module (DLL) and provide a flat C interface over it.
Within a single module, you cannot mix objects built with different major versions of the Visual C++ libraries.

Related

Unresolved external symbols in Visual Studio 2013 when using UHD

I can't seem to get a very simple program to compile in Visual Studio 2013. My goal is to incorporate UHD into a C++ program (UHD Driver and Libraries for Windows). I downloaded and installed the Windows UHD package.Since the library also depends on Boost, I also downloaded the appropriate Boost library. After that, I wrote a quick test program in Visual Studio 2013:
#include "stdafx.h"
#include <iostream>
#include <uhd\usrp\multi_usrp.hpp>
#include <uhd\types\device_addr.hpp>
using namespace uhd;
int main(void)
{
device_addr_t hint;
device_addrs_t dev_addrs = device::find(hint);
system("pause");
return 0;
}
In case anyone is interested, this program should locate any USRPs attached to a host PC. I defined the appropriate include paths in Visual Studio: . .
To be clear, I included two paths to the header files:
C:\Program Files (x86)\UHD\include and C:\Program Files (x86)\boost_1_55_0
and one path to the library:
C:\Program Files (x86)\UHD\lib
When I wrote the above program, Visual Studio recognized the additional include files, recognized device_addr_t as a typedef, and didn't throw any errors. However, when I built the program, I received these errors:
Error 3 error LNK2019: unresolved external symbol "__declspec(dllimport) public: static class std::vector<class uhd::device_addr_t,class std::allocator<class uhd::device_addr_t> > __cdecl uhd::device::find(class uhd::device_addr_t const &)" (__imp_?find#device#uhd##SA?AV?$vector#Vdevice_addr_t#uhd##V?$allocator#Vdevice_addr_t#uhd###std###std##ABVdevice_addr_t#2##Z) referenced in function _main C:\Users\...\Documents\Visual Studio 2013\Projects\uhd_test\uhd_test\uhd_test.obj uhd_test
Error 2 error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall uhd::device_addr_t::~device_addr_t(void)" (__imp_??1device_addr_t#uhd##QAE#XZ) referenced in function "public: void * __thiscall uhd::device_addr_t::`scalar deleting destructor'(unsigned int)" (??_Gdevice_addr_t#uhd##QAEPAXI#Z) C:\Users\...\Documents\Visual Studio 2013\Projects\uhd_test\uhd_test\uhd_test.obj uhd_test
Error 1 error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall uhd::device_addr_t::device_addr_t(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (__imp_??0device_addr_t#uhd##QAE#ABV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###Z) referenced in function _main C:\Users\...\Documents\Visual Studio 2013\Projects\uhd_test\uhd_test\uhd_test.obj uhd_test
Error 4 error LNK1120: 3 unresolved externals C:\Users\...\Documents\Visual Studio 2013\Projects\uhd_test\Debug\uhd_test.exe uhd_test
I've encountered these errors before in other programs, but I was able to resolve them relatively easily; either I would misspell a crucial include, or there would be an issue with a template class. However, in this instance, I can't seem to resolve the issue.
Any constructive input would be appreciated.
NOTE: In addition to defining the library directory path, I've explicitly added the UHD library, and I receive the same errors.
I got your example working. Here's the software versions I used since you didn't mention much in your description:
Microsoft Visual Studio 2013
VC++ Redistributable Package for VS2013 (vcredist_x86)
UHD 003.007.002, VS2013, Win32
Boost 1.56, lib32-msvc-12.0 binary package
Here are the project configuration properties you need to set in your VS2013 applications:
C/C++ -> General -> Additional Include Directories
C:\local\boost_1_56_0
C:\Program Files (x86)\uhd\include
Linker -> General -> Additional Library Directories
C:\local\boost_1_56_0\lib32-msvc-12.0
C:\Program Files (x86)\uhd\lib
Linker -> Input -> Additional Dependencies
uhd.lib
I think the last step is what's tripping you up, good luck!
I followed exactly what David Greene said, and I ended up with the same errors. Eventually I figured out that I had downloaded the 64-bit UHD, but I was using Visual Studio 2013 Express, which was a 32-bit compiler. Downloading the 32-bit version of UHD for Visual Studio 2013 solved the problem. For anyone else having this problem, double check that the compiler matches which version of UHD you install.

including a .lib file compiled in vs2010 in a project that is using vs2005

Is there any way I can have the main functions for a library built in vs 2010 be accessible from a vs2005 project? The problem that I face is that I have a project in vs 2005 that needs to use the clang frontend library to parse c code. The clang library requires vs 2010 to compile.
Any light you could shed on my problem is appreciated.
Thanks,
Saketh
EDIT:
I receive the following linker errors on compilation
1>hello.lib(hello.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __int64 __thiscall std::ios_base::width(_int64)" (_imp_?width#ios_base#std##QAE_J_J#Z) referenced in function "class std::basic_ostream > & __cdecl std::operator<< >(class std::basic_ostream > &,char const *)" (??$?6U?$char_traits#D#std###std##YAAAV?$basic_ostream#DU?$char_traits#D#std###0#AAV10#PBD#Z)
1>hello.lib(hello.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __int64 __thiscall std::basic_streambuf >::sputn(char const *,_int64)" (_imp_?sputn#?$basic_streambuf#DU?$char_traits#D#std###std##QAE_JPBD_J#Z) referenced in function "class std::basic_ostream > & __cdecl std::operator<< >(class std::basic_ostream > &,char const *)" (??$?6U?$char_traits#D#std###std##YAAAV?$basic_ostream#DU?$char_traits#D#std###0#AAV10#PBD#Z)
1>hello.lib(hello.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __int64 __thiscall std::ios_base::width(void)const " (_imp?width#ios_base#std##QBE_JXZ) referenced in function "class std::basic_ostream > & __cdecl std::operator<< >(class std::basic_ostream > &,char const *)" (??$?6U?$char_traits#D#std###std##YAAAV?$basic_ostream#DU?$char_traits#D#std###0#AAV10#PBD#Z)
1>C:\Users\sakethk\Perforce\sakethk_SAKETHK_7702\source\qcom\qct\modem\uim\tools\sakethk\hello05\Debug\hello05.exe : fatal error LNK1120: 3 unresolved externals
No. Within a single module, you cannot mix objects compiled against different major versions of the CRT. This generally procludes mixing of objects compiled using different major versions of the compiler.
The correct thing to do would be to encapsulate your usage of Visual C++ 2010 within a DLL, and load that DLL from your executable compiled with Visual C++ 2005. Alternatively, upgrade your sources to use Visual C++ 2010. Visual C++ 2005 is ancient.
Your library functions should be at the lowest level here i mean that you should use C-style parameters to functions and use extern "C" to avoind compilers mangling. Here you will find good article on how to create a great library compatible with every compiler. http://chadaustin.me/cppinterface.html

Trying to use my project with external opencv

I'm attaching some external libraries to my project in C++.
These libraries make use of the opencv2 libraries.
I already added the opencv2 include files to my c/c++ properties. I also added all the relevant lib files which I googled and found to the Linker input list. (I'm running the release version, but I also tried the debug version with the "d" extension).
opencv_core230.lib
opencv_highgui230.lib
opencv_objdetect230.lib
opencv_imgproc230.lib
opencv_ml230.lib
opencv_legacy230.lib
opencv_video230.lib
I'm getting these 4 annoying linking problems regarding the setSVMDetector#HOGDescriptor.
I looked everywhere for a solution and couldn't find one.; no one really uses the setSVM function in the external program.
Here are the linking problems:
Error 14 error LNK2001: unresolved external symbol "public: virtual void __thiscall cv::HOGDescriptor::setSVMDetector(class cv::_InputArray const &)" (?setSVMDetector#HOGDescriptor#cv##UAEXABV_InputArray#2##Z) C:\Users\idan\Documents\Visual Studio 2010\GraspTestingTool\GraspTestingTool\GraspTestingTool.obj GraspTestingTool
Error 15 error LNK2001: unresolved external symbol "public: virtual void __thiscall cv::HOGDescriptor::setSVMDetector(class cv::_InputArray const &)" (?setSVMDetector#HOGDescriptor#cv##UAEXABV_InputArray#2##Z) C:\Users\idan\Documents\Visual Studio 2010\GraspTestingTool\GraspTestingTool\htmlGenerator.obj GraspTestingTool
Error 16 error LNK2001: unresolved external symbol "public: virtual void __thiscall cv::HOGDescriptor::setSVMDetector(class cv::_InputArray const &)" (?setSVMDetector#HOGDescriptor#cv##UAEXABV_InputArray#2##Z) C:\Users\idan\Documents\Visual Studio 2010\GraspTestingTool\GraspTestingTool\sequenceTests.obj GraspTestingTool
Error 17 error LNK2001: unresolved external symbol "public: virtual void __thiscall cv::HOGDescriptor::setSVMDetector(class cv::_InputArray const &)" (?setSVMDetector#HOGDescriptor#cv##UAEXABV_InputArray#2##Z) C:\Users\idan\Documents\Visual Studio 2010\GraspTestingTool\GraspTestingTool\Utilities.obj GraspTestingTool
Does anyone know how to solve this issue?
Thanks a lot!
Error is due to not adding specifice library in debug or releas mode.
use 32 bit or 64 library depending on your target machine
Add respective library of opencv in release mode -
opencv_core242.lib opencv_highgui242.lib opencv_imgproc242.lib opencv_ml242.lib
opencv_legacy242.lib opencv_video242.lib
OR If you want run program in debug mode then
use debug lib of opencv
opencv_core220d.lib
opencv_highgui220d.lib
opencv_video220d.lib
opencv_ml220d.lib
opencv_legacy220d.lib
opencv_imgproc220d.lib
opencv_objdetect242.lib
C:\opencv\build\x86\vc10\lib
Add the library file "opencv_objdetect248.lib; opencv_objdetect248d.lib;" in Project roperties-->Linker-->Input.
You need to add opencv_objdetect library. If you using debug mode add objdetect(version)d.lib, however, if you release mode add objdetect(version).lib

linking error with CMake and Visual Studio 2010

I'm trying to compile osgearth library with VS2010. The library uses CMake, so after setting all dependencies it generates a VS2010 solution file. However when running build in VS I get this linker error (and 200 similar ones)
Error 7 error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall std::basic_ofstream >::`vbase destructor'(void)" (_imp??_D?$basic_ofstream#DU?$char_traits#D#std###std##QAEXXZ) referenced in function "public: virtual void __thiscall osgEarth::DiskCache::setImage(class osgEarth::TileKey const &,struct osgEarth::CacheSpec const &,class osg::Image const *)" (?setImage#DiskCache#osgEarth##UAEXABVTileKey#2#ABUCacheSpec#2#PBVImage#osg###Z) C:\swproj\osgearth-src\src\osgEarth\Caching.obj osgEarth
I'm not very familiar with C++, is there anything else I have to set up?
You're missing a reference to std::ofstream. You either need an #include in one of your files or a reference to the standard library dll in your project.

Linking Lua with Visual Studio 2010

We use Lua (www.lua.org) script to let users to customize our server software written in C++.
At the moment we are porting the 32 bits Windows version of our project to Visual Studio 2010.
Once everything works fine with VS 2008, we thought that we would have no problem on upgrade process.
Unfortunately whenever we tried to link the lualib (as dll) to our project in VS 2010, the lua functions could not be found by the linker (the error messages are displayed below).
It seems that some calling convention is wrong on 2010, like the application may be looking for the lua functions with a prefix '_'.
To access lua functions (written in C) from our project modules (C++) we use this:
extern "C" {
#include "lua/src/lua.h"
#include "lua/src/lualib.h"
#include "lua/src/lauxlib.h"
}
The same project compiles and links with lualib successfully on VS 2008 and Linux (g++).
Could anybody help me with this ?
1>dscscript.obj : error LNK2019: unresolved external symbol __imp__luaL_openlibs referenced in function "public: int __thiscall DsCScriptEngine::Init(void)" (?Init#DsCScriptEngine##QAEHXZ)
1>dscscript.obj : error LNK2019: unresolved external symbol __imp__luaL_newstate referenced in function "public: int __thiscall DsCScriptEngine::Init(void)" (?Init#DsCScriptEngine##QAEHXZ)
1>dscscript.obj : error LNK2019: unresolved external symbol __imp__lua_close referenced in function "public: void __thiscall DsCScriptEngine::Shutdown(void)" (?Shutdown#DsCScriptEngine##QAEXXZ)
1>dscscript.obj : error LNK2019: unresolved external symbol __imp__lua_pcall referenced in function "public: long __thiscall DsCScriptEngine::Execute(char const *)" (?Execute#DsCScriptEngine##QAEJPBD#Z)
etc.
The reported missing names are correct, this not a compile problem. You must be linking the wrong .lib. The name you use sounds wrong, it isn't "lualib", the current version of the import library is named lua5.1.lib (or lua51.lib, not sure what the difference is). Download it from here.