0

I have a .dll library on Windows which I compiled using mingw g++ on the command line with various flags to optimize it, but I need to link it to my project so that the .dll is required to run the compiled .exe (as far as I understand, this is implicit/dynamic linking). This is originally a macOS project, so I can't figure out how to link it to my Visual Studio project since it seems I need a .lib file.

The way I create the .dll file is by inputting this command in cmd inside the lib folder :

g++ -shared -DNDEBUG -IC:\Users\luis.lopez\Documents\libraries\eigen\ -march=native -ftree-vectorize -ffast-math -fstrict-aliasing -O3 -fomit-frame-pointer -fopenmp -o libfoo.dll foolibrary.cpp

Is there a way for me to create the .lib file while maintaining these compilation flags?

1 Answers1

0

You can add -Wl,--output-def,libfoo.def to generate libfoo.def. Then you should be able to generate an MSVC .lib file, see: How to generate an import library (LIB-file) from a DLL?

But to properly port to Windows you need to make sure the symbols are in fact exported by the library using __declspec(dllexport) and imported using __declspec(dllimport) by the code using the library, see for example: linkage between dllimport and dllexport

Brecht Sanders
  • 6,215
  • 1
  • 16
  • 40