Using MinGW/GCC built DLL in a Visual Studio 2010 C++/CLI project - visual-studio-2010

I have a communication library built on top of Qt and Google Protocol Buffers. It's currently being built with MinGW/GCC on Windows. My goal is to use the same library in C# on .NET, with the help of a thin wrapper on top using C++/CLI (bridging the unmanaged code with managed code).
I tried using the MinGW produced DLL directly in my C++/CLI project, but I keep getting linker errors (cant remember the error codes right now, but something about missing tokens and functions/signatures).
First question is: Should I be able to use the MinGW-produced DLL with the Visual Studio compiler/linker? Or do I need to compile the library again, using only VS compiler for all projects?
If I should be able to use the MinGW-produced DLL directly, how do I reference it in Visual Studio 2010? In project settings it seems to look for *.lib files, but I can't find any .lib files in the output of MinGW/GCC. It does produce *.a files, but it seems like Visual Studio don't handle this kind of file..
I should also mention that both Qt and protobuf are also compiled with MinGW. But I can of course recompile all the parts in VS 2010 if necessary.. Would have been nice to save the recompile time though, since our buildserver already has a working setup using MinGW.

The easiest way to use it would be by recompiling it with Visual Studio. This is when I am assuming C++ types and classes used in the interface you intend to use.
In case you have a C interface to this library you could dynamically load the library via LoadLibrary and use GetProcAddress to access those functions.
However it depends completly on the way how you intend to use the library.

Related

Depend on DLL without header file, worked in Visual Studio 2005

I have a legacy project that used to be build in Visual C++ 2005 Express, and it depends on a certain third party DLL. As far as I can tell it doesn't come with a lib or header file.
The project compiles fine in Visual C++ 2005, here is a screenshot showing the DLL visible and browsable in the object explorer. The code can also use it without #include or anything like that, which is pretty weird.
Importing the project into Visual Studio 2019 works as well, the code can still use the DLL and it is listed under both the dependencies and the references:
I now want to achieve the same thing in a new project, but I cannot figure out how to register the DLL as a dependency. Things I found online and tried:
"Just include the header or lib file" doesn't work, I don't have one
LoadLibrary() and GetProcAddress() are awfully contrived and don't seem necessary because it's clearly possible without.
Create your own lib file doesn't work either, dumpbin doesn't show any symbols for my DLL: image
How do I register the DLL as a dependency? And where does Visual C++ 2005 get the list of methods in the DLL from is the first place?

Visual Studio DLL reference dependencies

I'm new to the world of .NET and I'm trying to understand the build process. If the concept of DLLs is to resolve references at run time why does visual studio need to to know about DLLs at compile time in order to build an executable ? Can't seem to find a definitive answer anywhere.
DLLs are loaded at runtime so your code can call code in that DLL, indeed. However, they are also needed at compile time so you can write code calling into that library.
Back in C++ I think that was done with .lib files or via COM, so the compiler didn't actually need the DLL. In .NET that's different because the DLL contains the code to run and the interface so other programs can use it.

How do i include RVO2 library in Visual Studio?

I have been writing a code which uses SDL to render particles in Visual Studio. However, there does not seem to be any way to include RVO2 library:
http://gamma.cs.unc.edu/RVO2/downloads/ to Visual Studio. I have been able to include header files, but library file seems to be libRVO.a which Visual Studio is maybe not accepting. Also, there is no .dll file as was with SDL2 download.
So, I wanted to ask is there any way in which I can use RVO library in Visual Studio.
If not, I have another similar question...
I am using wsl(Windows Subsystem for Linux) and found that SDL cannot be run in it. I am able include RVO in wsl. So, can you suggest me a way where I can use both the libraries RVO and SDL2 simultaneously...

gcc compiled code on visual studio

Assume I have source code for a lib/tool that works on gcc compiler. Can I use the same code and compile it in visual studio. will that be possible at all? If it is possible, how do I do it?
if you are just using all the standard C/C++ library like stdio.h, stdlib.h, etc. it should work fine. Pure console program should work fine. If you used some GUI related library (especially if you are porting over from unix to window) then it might not work.
To do so, you can simply just create a new project in visual studio and add the existing source code into the project workspace. Compile it, if you encounter any error, just post here or try solve if you know how
It depends on your code, GCC support a variant of C (C99) which Visual Studio doesn't support yet.
If your trying to compile a Unix program on Windows you best bet will be to use Cygwin.
Check this question for pointers on using Cygwin in Visual Studio.

Managed code in Visual Studio

Is it possible to switch off managed code (and switch on unmanaged code) for c++ coding, so that programs (exes) made are run direct to native machine code in Visual Studio 2008?
Also, is it true that after the first time a .net (managed) exe runs (say written in C#) the exe gets converted to a native code one (like the old c++ ones pre .net)? Or is there a way to make it compile direct to native code if it was written in C#?
The answer to both of these questions is yes.
You can create unmanaged c++ code projects in VS which do not need .Net. You can also link unmanaged C++ code to managed C++ code and (sort of) get the best of both worlds - although the matching of calling parameters between the to systems is interesting.
You can also use the ngen .Net utility to pre-compile .Net projects to pure code. However in doing so you loose some flexibility. The JIT compiler will take account of local capabilities when compiling a .Net project. So if you distribute a .Net project as generated by VS then ngen on the local machine that runs the program will do the compiliing. However if you use ngen on your machine the precompiled code will be tied to the processsor capabilities of your system.
As per Joel's comment. regardless of using ngen or not, you still need .Net framework on the target machine.
In thinking about it, the use of ngen to pre-compile a .Net project probably is no worse than compiling an unmanaged c++ project to native code.
To do what you want for C#, you would use ngen.exe, which comes with the C# compiler. You run that command on the image, and it gets added to the GAC as native code.
As far as i know, you can switch temporarily to unmanaged code, i.e. using unmanaged variables etc. by marshaling. Take a look here: http://msdn.microsoft.com/de-de/library/bb384865.aspx

Resources