[英]I have a .dll compiled with various optimization flags using g++, how do I dynamically link it to my application?
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 ). 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据我了解,这是隐式/动态链接)。 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.
这最初是一个macOS项目,所以我不知道如何将它链接到我的Visual Studio项目,因为我似乎需要一个 .lib 文件。
The way I create the .dll file is by inputting this command in cmd inside the lib folder:我创建.dll文件的方法是在 lib 文件夹内的 cmd 中输入此命令:
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?有没有办法让我在维护这些编译标志的同时创建.lib 文件?
You can add -Wl,--output-def,libfoo.def
to generate libfoo.def
.您可以添加
-Wl,--output-def,libfoo.def
来生成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?然后您应该能够生成一个 MSVC
.lib
文件,请参阅: 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但是要正确移植到 Windows,您需要确保符号实际上是由库使用
__declspec(dllexport)
导出并由使用库的代码使用__declspec(dllimport)
导入的,例如: linking between dllimport and dllexport
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.