1

I've been working with examples of csapp 3rd edition, and I couldn't successfully compile given codes from csapp website with gcc.

The source code I've tried to compile was "signal1.c" which includes header file "csapp.h" split into source code "csapp.c".

I've been trying to compile "signal1.c" in several ways like "gcc csapp.h csapp.c signal1.c -o signal1" "gcc csapp.c signal1.c -o signal1"

but only error message says

/tmp/ccGJtkct.o: In function Pthread_create': csapp.c:(.text+0x108a): undefined reference topthread_create' /tmp/ccGJtkct.o: In function Pthread_cancel': csapp.c:(.text+0x10bd): undefined reference topthread_cancel' /tmp/ccGJtkct.o: In function Pthread_join': csapp.c:(.text+0x10fb): undefined reference topthread_join' /tmp/ccGJtkct.o: In function Pthread_detach': csapp.c:(.text+0x112e): undefined reference topthread_detach' /tmp/ccGJtkct.o: In function Pthread_once': csapp.c:(.text+0x118f): undefined reference topthread_once' /tmp/ccGJtkct.o: In function Sem_init': csapp.c:(.text+0x11b8): undefined reference tosem_init' /tmp/ccGJtkct.o: In function P': csapp.c:(.text+0x11e1): undefined reference tosem_wait' /tmp/ccGJtkct.o: In function V': csapp.c:(.text+0x120a): undefined reference tosem_post' collect2: error: ld returned 1 exit status

I've checked if header file "csapp.h" doesn't include nor my computer doesn't have with it but it doesn't seem so.

What will be of right choice to compile this?

Thank you.

  • Thank you for the comment. I've figured out yesterday that though is inside standard library, I still need to link it in order to compile the signal1. I tried "gcc -pthread -o csapp.c signal1.c" and this worked for me. – 김태홍 KIM Oct 09 '18 at 08:05
  • Welcome to Stackoverflow. `pthreads.h` is not and never has been a [C Standard library header](https://en.cppreference.com/w/c/header), and you do not link header files; you link the library for which a header file declares an API. – Mike Kinghan Oct 09 '18 at 08:24

0 Answers0