apue 在 mac 环境编译错误
作者:互联网
笔者使用 mac 学习 apue, 在编译的时候出现错误,错误如下:
Undefined symbols for architecture x86_64: "_TELL_CHILD", referenced from: _main in 14_5-4244a7.o "_TELL_PARENT", referenced from: _main in 14_5-4244a7.o "_TELL_WAIT", referenced from: _main in 14_5-4244a7.o "_WAIT_CHILD", referenced from: _main in 14_5-4244a7.o "_WAIT_PARENT", referenced from: _main in 14_5-4244a7.o "_err_sys", referenced from: _lock_test in 14_5-4244a7.o _main in 14_5-4244a7.o _lockabyte in 14_5-4244a7.o "_lock_reg", referenced from: _lockabyte in 14_5-4244a7.o ld: symbol(s) not found for architecture x86_64
在解决该问题时浪费很多时间,记下解决办法,希望可以帮助到你。
前提:已经正确安装 apue,安装方法自行搜索,路径如下:
DilldeMacBook-Pro:apue.3e dill$ pwd /Users/dill/Downloads/apue.3e DilldeMacBook-Pro:apue.3e dill$ cp include/* /usr/local/include/ DilldeMacBook-Pro:apue.3e dill$ cp lib/* /usr/local/lib/
避免上文的编译错误,采用如下命令编译:
gcc -o myls myls.c -I /usr/local/include -L /usr/local/lib/ -lapue
myls.c 为需要编译的 C 文件
-I 为 gcc 指定 include 地址
-L 为 gcc 指定 library 地址
-lapue 指定在 lib 文件夹中 library 文件名("/usr/local/lib/libapue.a")
-LXXX means to look for a file in the library directory with the name: libXXX.a or libXXX.so.
标签:referenced,apue,4244a7,编译,mac,usr,main,local,14 来源: https://www.cnblogs.com/DillGao/p/10400024.html