Using libdl.so in MinGW

。_饼干妹妹 提交于 2020-01-10 04:30:05

问题


I want to generate a dll file in MinGW, I have several object dependencies in order to do that, one of my object dependencies is libdl.so, I add this object in unix simply as :

g++ xx.o yy.o /usr/lib/libdl.so -o module.so

but in MinGW, I don't have any idea how to add this object. any ideas?


回答1:


There is a MinGW port of libdl that you can use just like under Unix. Quote from the website:

This library implements a wrapper for dlfcn, as specified in POSIX and SUS, around the dynamic link library functions found in the Windows API.

It requires MinGW to build.

You may get pre-built binaries (with MinGW gcc 3.4.5) and a bundled source code from the Downloads section.

The following commands build and install it in a standard MinGW installation (to be run from your MinGW shell):

./configure --prefix=/ --libdir=/lib --incdir=/include && make && make install

To compile your library as a DLL, use the following command:

g++ -shared xx.o yy.o -ldl -o module.dll




回答2:


I encountered the same problem (msys2, 32bit version of compiler etc.).

For me I found out that the libdl.a was available in /usr/lib but not in /mingw32/lib. I was able to solve the problem by linking it to the /mingw32/lib folder:

ln -s /usr/lib/libdl.a /mingw32/lib


来源:https://stackoverflow.com/questions/12455160/using-libdl-so-in-mingw

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!