sem_openへの未定義の参照



Undefined Reference Sem_open



semaphore.hを追加し、sem_openへの未定義の参照も報告しました

エラー



root@xxxxx:~/OSLearn/OS-Assignment-2016/4_Linux_Progress_Control/4_5_shared_memory$ make cc -c init.c cc -o edit init.o common.o common.o: In function `SemInit': common.c:(.text+0x7f): undefined reference to `sem_open' common.c:(.text+0xa2): undefined reference to `sem_open' common.o: In function `SemDestroy': common.c:(.text+0xc6): undefined reference to `sem_open' common.c:(.text+0xe3): undefined reference to `sem_open' common.c:(.text+0xf3): undefined reference to `sem_close' common.c:(.text+0x102): undefined reference to `sem_unlink' common.c:(.text+0x10e): undefined reference to `sem_close' common.c:(.text+0x11d): undefined reference to `sem_unlink' common.o: In function `P': common.c:(.text+0x138): undefined reference to `sem_wait' common.o: In function `V': common.c:(.text+0x153): undefined reference to `sem_post' collect2: error: ld returned 1 exit status makefile:4: recipe for target 'edit' failed make: *** [edit] Error 1

解決
コンパイル時に-pthreadを追加しますか?
PosixのライブラリファイルはLinuxのデフォルトライブラリに含まれていないと思います。したがって、-pthreadパラメーターを追加する必要があります。

gcc -pthread -o init init.o common.o

makefileにメソッドを書き込む

完了

「問題解決」への「未定義の参照」