楼主:
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还是循序渐进慢慢先学下去吧~