编译动态链接库 [英] Compiling a dynamically linked library

查看:107
本文介绍了编译动态链接库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试使用Windows和MinGW编译动态链接库(用于插件系统).

I'm currently trying to compile a dynamically linked library (for a plugin system) using Windows and MinGW.

我使用此命令行编译每个对象:

I compile each objects using this command line :

mingw-g++ -fPIC test.cpp

以及使用此行的库:

mingw-g++ -rdynamic -shared -Wl,-soname,test.so.1 -o test.so test.o

它根本不起作用(虽然在Linux上使用GCC,但类似的行也可以工作):由于某些原因,忽略了fPIC和rdynamic. 在尝试制作该库时,它失败了,因为编译器尝试将其与应该解析的对象链接,因为我将其与主二进制文件动态链接.

It doesn't work at all (using GCC with Linux, a similar line works though) : fPIC and rdynamic are ignored for some reason. And while trying to make the library, it fails because the compiler try to link it with objects that are supposed to be resolved as I dynamically link it with the main binary.

那么您如何使用MinGW进行编译?

So how do you compile this using MinGW?

谢谢:)!

推荐答案

-fPIC-rdynamic被忽略,因为它们未在Windows中使用.

-fPIC and -rdynamic are ignored because they are unused for Windows.

此外,.so也不是Windows上库的正确输出扩展名.

Also, .so is not the correct output extension for libraries on Windows.

要使用GCC在Windows上/在Windows上创建共享库,请执行以下操作:

To make a shared library for/on windows with GCC:

mingw-g++ -c file.cpp -o file.o
mingw-g++ -shared -Wl,--out-implib,libfile.a -o file.dll file.o 

不多也不少.

而且,拥有文档总是很可爱: http://www.mingw.org/wiki/sampleDLL

And, documentation is always lovely to have: http://www.mingw.org/wiki/sampleDLL

这篇关于编译动态链接库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆