link MinGW gcc c++ application against mvsc c++ .lib - c++

I need to integrate the Intel RealSense C++ library (legacy 2016 R3 not the current 2.0 SDK) to an already existing application built with Qt MinGW g++ 32-bit (installed by Qt5.11 offline installer)
basically, they provide the headers and some .lib files to compile and link applications
when I try to compile the Segmentation example in Visual Studio, they work, (they provide a .props file that I can add to the Visual Studio Solution's Project's Property Manager, btw, I am using Visual Studio Community 2017 on Windows 10 Home 64-bit), but, the application I am developing was made using QtCreator so I need to be able to compile with QtCreator, and migrating the build to Visual Studio might not be a viable solution
if I try to compile the Segmentation example with MinGW (32-bit) in QtCreator (installed by Qt5.11 offline installer) I get error messages like this one
C:\src\Debug\app\main.cpp:34: error: undefined reference to `UtilCmdLine::UtilCmdLine(Intel::RealSense::Session*, int)'
and even if I try to use MSVC (64-bit) in QtCreator (installed by Qt5.11 offline installer) (which is not really a great option)
I get error messages like this one
C:\src\Debug\app\main.cpp.obj:-1: error: LNK2019: unresolved external symbol PXCSession_CreateFromPath referenced in function "public: static class Intel::RealSense::SenseManager * __cdecl Intel::RealSense::SenseManager::CreateInstance(wchar_t const *)" (?CreateInstance#SenseManager#RealSense#Intel##SAPEAV123#PEB_W#Z)
for several symbols
has anyone solved a similar problem?
MinGW I think I understand not working, because of MSVC symbol mangling and a general different ABI, and because the tools to work with .lib files in MinGW are no longer being available (at least not in the official website), but why is MSVC not working? am I missing something that Visual Studio has that QtCreator does not?
would there be a way to make something like a wrapper library in visual studio so that I can use in MinGW? I saw some people who had similar problems with .lib files being told to use a COM style interface if they could
I saw that being the
just to clarify, I'm not sure if it's a problem introduced by the Qt libraries but there is some of the application's code just doesn't compile correctly with MSVC, so for now, I'd prefer a way to compile with MinGW in QtCreator, though we might eventually get it to work with both compilers (or at least try to)

Related

Do libraries compiled with MinGW work with MSVC?

Problem:
I would use a MinGW library in Visual Studio project.
How my system is built:
I downloaded ZBar library for my Windows 10 system ( zbar-0.23.91-win_x86_64-DShow.zip
This is the link: https://linuxtv.org/downloads/zbar/binaries/).
I have these files in the folder of lib and bin:
libzbar.a
libzbar.dll.a
libzbar.la
libzbar-0.dll
Error when build:
error LNK2019: unresolved external symbol __mingw_vsnprintf referenced in snprintf
My question
Do libraries compiled with MinGW work with MSVC?
No, libraries compiled on MinGW can't be used with MSVC. The main reasons are:
Lack of ABI compatibility. That is to say that in binary, the way things can be laid out are different depending on the compiler.
Difference in how the standard library is implemented. The standard library can be implemented in many ways. The C++ Standard just says how functions should behave and does not force compiler developers to implement them in the same way.
In general, things compiled with one compiler aren't compatible with another compiler.
The problem is that the libraries have been compiled with mingw while I need to compile them in an mscv project.
The solution was to rebuild the library with Visual Studio.
It was possible to use everything without problems.
You can use C-lion because It has direct support of MinGW.
A sample tutorial for how to select MinGW as a toolchain in C-lion is given in this link.
https://www.jetbrains.com/help/clion/how-to-create-toolchain-in-clion.html#custom-targets-toolchain
Using this you will have direct access to all the libraries available for MinGW directly.
No it can't. A library compiled with MinGW will only work with MinGW. You need to compile it from source code with MSVC.
I haven't used windows much and hardly used visual studio. But you can use MinGW on visual studio ide if you want.
Using MinGW with Visual Studio IDE

Error LNK2019 with creating DirectX11 [duplicate]

I am running a DirectX 11 application on windows 7 and visual studio community 2015 RC. I'm still using functions from the DX SDK. It worked fine on VS2013 but when I switched over I get only the following error:
Error LNK2019 unresolved external symbol __vsnprintf referenced in function "long __stdcall StringVPrintfWorkerA(char *,unsigned int,unsigned int *,char const *,char *)" (?StringVPrintfWorkerA##YGJPADIPAIPBD0#Z) Ancora D:\Moody\Moody\Projects\Projects\Ancora\Ancora\dxerr.lib(dxerra.obj) 1
I only use the DXGetErrorDescriptionA function from the dxerr library and when I comment it out, the program compiles fine. I have no idea what's wrong but it can't be from the DX SDK or otherwise the other functions would fail right?
I experienced the same problem using DXGetErrorMessage() with Dx9 and found out that MS have provided an additional library to include in the Additional Dependencies properties page to address this problem. The library name is: legacy_stdio_definitions.lib
Adding this resolved the issue for me.
just add
#pragma comment(lib, "legacy_stdio_definitions.lib")
https://msdn.microsoft.com/en-us/library/bb531344.aspx
Instead of hacking dxerr.lib manually, you could add
#include <Windows.h>
#include <stdio.h>
int (WINAPIV * __vsnprintf)(char *, size_t, const char*, va_list) = _vsnprintf;
somewhere in your code
The legacy DirectX SDK is quite old, and dxerr.lib in the DXSDK is not compatible with VS 2015's C Runtime as you have encountered.
In general static libraries with code in them don't mix well from different versions of the compiler. Most of the .libs in the legacy DirectX SDK work with VS 2015 because they are import libraries for dlls or all data libraries and therefore contain no code at all. The DXSDK has not been updated since VS 2010.
Aside: The VS team has made a heroic effort to keep the Visual C/C++ Runtime link compatible between VS 2015 Update 3, VS 2017, and VS 2019 per Microsoft Docs. This is not the normal pattern.
Be sure to read the instructions on Microsoft Docs on the proper way to mix the legacy DirectX SDK with the Windows 8.x SDK used by VS 2015. You are presumably using something else from the legacy DirectX SDK in this project besides dxerr.
I have implemented a version of DXERR that you can build from source in your project to remove this dependency of the legacy DirectX SDK. See this post for details. That said, I purposely only supported Unicode (the W version). You can work out how to make the ANSI (the A version) easily enough, but it would be best if updated your app to use Unicode.
See Where is the DirectX SDK (2021 Edition)? and DXUT for Direct3D 11.
UPDATE: As noted in another answer linking with legacy_stdio_definitions.lib should make the old legacy DirectX SDK version of dxerr.lib link again with VS 2015/2017. That said, you should work on removing dependencies on the legacy DirectX SDK as much as possible and DXERR is easily replaced by your own module. See Living without D3DX.
The DirectX libraries you are using are compiled with an older version of Visual Studio than you are using. Microsoft sometimes makes changes to their C runtime, creating incompatibilities between libraries compiled with different versions. __vsnprintf was an internal symbol in older versions of their C runtime, it does not exist in the 2015 RC version.
Unfortunately, dxerr.lib (along with d3dx11.lib) have been deprecated. You have two options - you can switch back to VS2013 or you can stop using functionality from dxerr.lib. The latter is probably better, because you can duplicate its functionality by using FormatMessage now (more info in the linked article).
HACKY but you could patch dxerr.lib.
Replace __vsnprintf with _vsnprintf (with a null at the end to account for the removed underscore at the beginning)
You can change the Platform Toolset from Visual Studio 2015 to Visual Studio 2013 and then it compiles.
The Platform Toolset is found on the General tab of the Project Properties.

Accommodate VS2013 project to VS2015

So I've recently upgraded VS2013 to VS2015 and I'm still struggling accommodating the code & project's definitions to make it work.
I have dozens of projects in my solution. I also use jsoncpp as an additional lib.
When compiling a single project, I get this error:
3>LINK : fatal error C1047: The object or library file '..\Libs\json_cpp\build\vs71\release\lib_json\json_vc71_libmt.lib' was created with an older compiler than other objects; rebuild old objects and libraries
So I've open the Libs\json_cpp\makefiles\vs71\jsoncpp.sln with VS2015 and rebuild the solution.
that didn't help.
Possible Reason
My projects are all using Platform Toolset Visual Studio 2015 - Windows XP (v140_xp)
while the jsoncpp Platform Toolset is Visual Studio 2013 - Windows XP (v120_xp)
If this is indeed the issue so the obvious solution is to have both solutions compile in the same Platform Toolset Visual Studio 2015 - Windows XP (v140_xp).
Possible Solution
So, I've tried that. and got countless of these warnings:
json_value.obj : warning LNK4006: "public: static int const std::numeric_limits<unsigned short>::digits10" (?digits10#?$numeric_limits#G#std##2HB) already defined in json_writer.obj; second definition ignored
Anybody else suffered from this agonizing process of VS upgrade and can share some insights?

MSCVP120D.dll missing even though redistributable is installed?

I'm creating a C++ application using Visual Studio 2013 and using libraries such as FMOD and SDL. I'm trying to package the application to run on other machines through the .exe. I have all my library paths correct and dependencies referenced locally, but when I run the .exe on another machine I get the "MSCVP120D.dll not found" error.
I have installed the Visual Studio 2013 redistributable on these test machines (Since it's 120.dll) and yet the error persists.
As far as I'm aware, other than the libraries specified, which all work, I'm only using standard libraries and windows.h.
I have been told another option is to install the dll file locally and link it statically to the CRT, but honestly I don't know enough to know if this is a correct option or not.
For more information, I'm on a Windows 8.1 machine and have tested on Windows 8 and 7, with no success other than on my own machine.
You are compiling your program in debug-mode and linking to the MS C++ debug-runtime.
Change to release-configuration, and either compile it statically or preferably add the Visual C++ Redistributable Packages for Visual Studio to your deployment (the last part is not neccessary if it's already installed).

MSVCR100D.dll is missing when build/running project from another PC/VS

I uploaded my (VS2013) project folder and provided it to the other members of my team, but when they tried to build/run it, using Visual Studio 2012 they got this error, it also happened on their version of Visual Studio 2013.
The program can't start because MSVCR100D.dll is missing from your computer. Try reinstalling the
program to fix this problem.
They reinstalled VS2010 but no go.
I also tried to statically link my project by using /MT in the Code Generation options but now I get:
Unresolved External Symbol __free_dbg libcmptd.lib cout.obj
....25 more...
How can I get it so my project can be build/ran on my team members pc? How do I resolve the unresolved externals? It seems to happen purely with regular Microsoft files.
You are mixing C++ libraries built with different versions of the compiler (and as we know some of them are linked against debug dynamic version of VC10 runtime library). This is not supported, as different compiler versions have different ABIs.
To fix the mess you need to find libraries built with parameters that match parameters of your project. They should be built:
with the same compiler version (ex. VS 2013)
with the same configuration (Debug/Release)
against the same platform (x86/x64/ARM)
against the same runtime library variant (static/dynamic + debug/release)
You could either try to find prebuilt versions on the web or to build libraries yourself from source codes. Often, you will want to have multiple configuration/platforms for your project and, thus, you will need multiple versions of your libraries.
If your search will not succeed (for example if there is no VS2013 build for a closed source library) you could roll back your project to another version of compiler and to start over.
Any attempts to link incompatible libraries even if somehow succeeded will lead to random crashes.
This message generally states that the dll is referred to directly or indirectly in your application and is missing.
The 'D' at the end show us this is the Debug version of the file, this is DLL file is provided with the Visual Studio 2010 installation. So the MSVCR100D.dll would be provided with the installation of Visual Studio 2010.
Of course, you could be missing other versions 2008 (MSVCR90D) 2010 (MSVCR100D) 2012 (MSVCR110D) or the 2013 (MSVCR120D), each dll is provided according to the Visual Studio version.
There are a few ways to solve this:
Check to be sure that you're compiling all the components of your
project in Release mode. If this does not solve the issue continue
to the next steps.
You could solve this locally by installing Visual Studio 2010 on your
machine. This is not what I would recommend, but it would surely
overcome the issue
You could also download the file from this third party website and
copy it to your projects bin:
http://www.dll-files.com/dllindex/dll-files.shtml?msvcr100d
This option is the LEAST recommended option.
Run dependency Walker and see what file depends on the MSVCR100D.dll
and the try and fix that file in order to break your dependency. You can download depends here: http://www.dependencywalker.com/
Check to be sure that you're project is linking the correct version of
the CRT and any other libraries you may be using (e.g., MFC, ATL,
etc.)
Note: Installing the redistributables alone will NOT solve this problem, since the redistributables only contain the release version of the file MSVCR100.dll (notice no 'D')
Would it be possible that in your project you are somehow using some component/library built with Visual Studio 2010, which requires the MSVCR100D DLL?