Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using libs/dlls compiled in Linux/MinGW in Visual Studio

Update: I get this warning when compiling: multiple '.text' sections found with different attributes

Hi,

I've compiled some libraries (.a and .dll) in Linux using the MinGW Cross Compiler. I can successfully link against them (.a) in Visual Studio 2008. However, when it runs (using .dll), it terminates with the address pointer pointing at empty memory addresses.

Is there a way/a list of things to do that will allow me to use those libraries successfully in VC08?

The cross compiler generates

  1. *.dll.a
  2. *.dll

Thanks

like image 893
jameszhao00 Avatar asked Aug 18 '09 03:08

jameszhao00


People also ask

Can I use MinGW with Visual Studio?

Use MinGW with Visual Studio. It has been possible to use GCC based compilers with Visual Studio projects for some time already, but many cross-platform projects that build with MinGW on Windows are not organized into Solution and Visual C++ project files.

Does MinGW use DLL?

a from MinGW. Since the MinGW makefile creates an import library in MSVC's lib format, the produced shared library (DLL) can be used from both MinGW and Microsoft Visual Studio with no further adaption. Just link to the import library FreeImage. lib from either MinGW or Microsoft Visual Studio.

How do I add a DLL to C++ project in Visual Studio?

To create a DLL project in Visual Studio 2017On the menu bar, choose File > New > Project to open the New Project dialog box. In the left pane of the New Project dialog box, select Installed > Visual C++ > Windows Desktop. In the center pane, select Dynamic-Link Library (DLL).

How do I create a DLL file in MinGW?

Open a command prompt, change to the directory where you extracted the files, and type "mingw32-make". The DLL and executable should be compiled, linked, and output as "AddLib. dll" and "AddTest.exe" in the "bin" directory. The import library will be created as "libaddlib.


2 Answers

Found it.

http://www.mingw.org/wiki/MSVC_and_MinGW_DLLs

You have to have a def file and use the VC's lib tool to generate an import library.

like image 192
jameszhao00 Avatar answered Sep 21 '22 06:09

jameszhao00


It sounds to me like the two parties are not using the same calling convention, meaning there is a problem in the way the exported dll functions have been defined.

By far the simplest approach would be to define the functions as extern "C" by defining the exported functions as follows:

extern "C"
{
  int  MyExportedFunction(char *buffer, int length);
  void MyOtherFunction();
};
like image 24
jussij Avatar answered Sep 19 '22 06:09

jussij