Building Elf Shared Library with MinGW

寵の児 提交于 2019-12-12 05:50:07

问题


I'm trying to build an shared library on Windows with MinGW, follow this tutorial: Building_elf_shared_libraries

I run this step:

$ gcc -fPICenter code here -c libfoo.c -o libfoo.o
$ gcc -Wall -O2 -shared -Wl,-soname,libfoo.so.1 -o libfoo.so.1.0.0 libfoo.o

When I get the .so I try to read it with readelf and get error:

$ readelf -h libfoo.so.1.0.0
readelf: Error: Not an ELF file - it has the wrong magic bytes at the start

Did I misunderstand something?


回答1:


Yes you did misunderstand something, MinGW is a port of gcc to use gcc to both target windows and run on windows natively (or if your host is linux, to target windows from linux). By default it will output files in PE format, not ELF. That's why your readelf call fails. With all that said I assume your trying to build a dynamically linked library and as such I'll provide a nice tutorial here that should get you moving in the correct direction.



来源:https://stackoverflow.com/questions/31905795/building-elf-shared-library-with-mingw

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