相关疑难解决方法(0)

Mac OS X的静态库链接问题:找不到架构x86_64的符号

我正在尝试生成一个静态库并将其与执行二进制文件链接.

这是一个库函数:

#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)

c macos clang static-libraries unix-ar

5
推荐指数
1
解决办法
6589
查看次数

标签 统计

c ×1

clang ×1

macos ×1

static-libraries ×1

unix-ar ×1