我正在尝试生成一个静态库并将其与执行二进制文件链接.
这是一个库函数:
#include <stdio.h>
int hello() {
return 10;
}
Run Code Online (Sandbox Code Playgroud)
使用这些命令,我可以得到一个静态库.
gcc -c io.c
ar -crv libio.a io.o
Run Code Online (Sandbox Code Playgroud)
有了lip -info,我检查了它是x86_64架构.
ar> lipo -info libio.a
input file libio.a is not a fat file
Non-fat file: libio.a is architecture: x86_64
Run Code Online (Sandbox Code Playgroud)
这是使用库的主要功能.
#include <stdio.h>
extern int hello();
int main(int argc, char *argv[]) {
printf("%d", hello());
}
Run Code Online (Sandbox Code Playgroud)
但是,当我将对象与静态库链接时,我有错误.
gcc main.c -lio -o main -L.
Run Code Online (Sandbox Code Playgroud)
错误消息是:
ld: warning: ignoring file ./libio.a, file was built for archive which is not the architecture …Run Code Online (Sandbox Code Playgroud)