简体   繁体   English

我有一个.dll 使用 g++ 编译了各种优化标志,我如何将它动态链接到我的应用程序?

[英]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.

相关问题 我将如何指示 extconf.rb 使用额外的 g++ 优化标志,哪些是可取的? - How would I instruct extconf.rb to use additional g++ optimization flags, and which are advisable? 如何使用g ++编译和链接库(SDL),以便拥有独立的程序? - How do I compile and link a library (SDL) with g++ so that I have a standalone program? 如何在g ++中链接同一个库的不同版本? - How do I link different versions of the same library in g++? 如何在静态库中使用g ++正确链接? - How do I correctly link in static libraries with g++? 如何在 linux 上将 gtkmm 与 g++ 链接 - How do I link gtkmm with g++ on linux 如何让 G++ 在 Linux 上链接我的头文件? - How do I get G++ to link my header files on Linux? 为什么我必须在g ++中启用优化才能进行简单的数组访问? - Why do I have to turn on optimization in g++ for simple array access? 在VC ++编译的应用程序中使用G ++编译的DLL(插件)时会出现什么问题? - What problems can appear when using G++ compiled DLL (plugin) in VC++ compiled application? 为什么g ++会使我的代码以不同于编写的顺序执行,以及如何禁用此“优化”? - Why does g++ make my code execute in a different order than written and how do I disable this “optimization”? 如何使用g ++链接.o文件 - How can I link an .o file using g++
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM