作者:
ck80865 (bear)
2014-10-31 21:57:31開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
Linux
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
<pthread.h>
<semaphore.h>
問題(Question):
pthread 和 semaphore 一起使用的問題,
在網路上找到的許多範例 compile 都會出現一樣的問題
會顯示`sem_init'、`pthread_create'、`sem_wait'這些都未定義
不知道問題出在哪邊
程式碼(Code):(請善用置底文網頁, 記得排版)
http://codepad.org/9Lt6HuBF
補充說明(Supplement):
gcc -o test test.c -lpthread -lrt
作者:
lantw44 (#######################)
2014-10-31 22:23:00cc -pthread
include給cpp看 link是ld的事可以說include只是定義 實際要呼叫誰是ld去找來link的所以你要告訴他function在pthread(libpthread.so)-l找不到就要再加-Lpath設定dir 詳細的gcc -v可以看
作者:
LPH66 (-6.2598534e+18f)
2014-10-31 22:58:00header 只是元件說明書, 實際元件要 -lxxx 從程式庫拿出來
header是讓你找到.h 我舉個例子,你可以試試看寫一個標準的class, 只寫header不寫cpp,你會發現若是其他檔案include header並且用它, compile是會過的,死在ld(linking)而已普通我們說的三種phase就是compile, linking, run這個觀念一定要弄清楚 不然保證你未來2年很難過
作者:
ah7675 (阿毛)
2014-11-01 13:51:00又要推"程式設計師的自我修養"了XD
還沒搞懂linking time/runtime看那本書是找死而已XD還是循序漸進慢慢先學下去吧~