与MinGW建立Elf共享库 [英] Building Elf Shared Library with MinGW
问题描述
我正在尝试使用MinGW在Windows上构建共享库,请按照以下教程操作:
Building_elf_shared_libraries
I'm trying to build an shared library on Windows with MinGW, follow this tutorial: Building_elf_shared_libraries
我运行此步骤:
$ 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
当我收到.so时,我尝试阅读它与 readelf 并得到错误:
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我误会了什么?
Did I misunderstand something?
推荐答案
是的,您确实误会了一些东西,MinGW是gcc的一部分,既可以使用gcc来定位目标窗口又可以运行在本机Windows上(或者如果您的主机是Linux,则从linux定位Windows)。默认情况下,它将以PE格式而不是ELF输出文件。这就是您的readelf调用失败的原因。综上所述,我假设您尝试构建动态链接库,因此,我将在此处提供一个不错的教程应该可以使您朝正确的方向前进。
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.
这篇关于与MinGW建立Elf共享库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!