
如图,报错
Undefined symbols for architecture arm64:
"_InitBoard", referenced from:_game in test_sanziqi-1fb96b.o"_PrintBoard", referenced from:_game in test_sanziqi-1fb96b.old: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
请问下如何解决?
网上查了说可能是自定义库文件不是arm64架构,我的电脑是mac M1芯片,请问怎么处理呢?
链接的时候出的问题吧。
因为主文件 test_sanziqi.c 包含了 sanziqi.h 文件,所以,你要先编译 sanziqi.c 文件,生成一个.o文件。
然后,在编译主文件的命令中,将上述编译的.o文件也添加进去,之后生成的可执行文件中,就会带有你在.h文件中的函数了。
这个是基础问题,和芯片什么的,没有关系。
你要熟悉C语言的基础,比如,预编译,编译,链接 以及 可执行文件的生成等等。这些过程,都干了什么,都能干什么。
你应该学习一下 多源文件的编译
两种方法:
- gcc test_sanziqi.c sanziqi.c -o build/test_sanziqi
- gcc -c sanziqi.c 会生成 sanziqi.o
gcc -c test_sanziqi.c 会生成 test_sanziqi.o
gcc test_sanziqi.o sanziqi.o -o build/test_sanziqi
然后,你执行一下 ./build/test_sanziqi 就可以了。