在Linux 64服务器应用开发中,要调用一个第三方的32位静态库,会产生undefined reference to的错误,由于没有源代码,为了兼容可使用 -m32 方式进行编译。不过这种方式会使得整个程序按32位进行编译,以下摘自 man gcc
-m32
-m64
Generate code for a 32-bit or 64-bit environment. The 32-bit environment sets
int, long and pointer to 32 bits and generates code that runs on any i386 system.
The 64-bit environment sets int to 32 bits and long and pointer to 64 bits and
generates code for AMD?s x86-64 architecture.
可以将要调用32位库的功能部分写成独立的部分,再由主程序集成调用(比如先fork,再execl)。