apue 在 mac 環境編譯錯誤

參考資料:https://unix.stackexchange.com/questions/105483/compiling-code-from-apue學習

筆者使用 mac 學習 apue, 在編譯的時候出現錯誤,錯誤以下:spa

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

在解決該問題時浪費不少時間,記下解決辦法,但願能夠幫助到你。unix

前提:已經正確安裝 apue,安裝方法自行搜索,路徑以下:code

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/

避免上文的編譯錯誤,採用以下命令編譯:blog

gcc -o myls myls.c -I /usr/local/include -L /usr/local/lib/ -lapue

myls.c 爲須要編譯的 C 文件get

-I 爲 gcc 指定 include 地址it

-L 爲 gcc 指定 library 地址io

-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.class

相關文章
相關標籤/搜索