2

how can I use pthread_spinlock_t in gcc 4.6.3? Which flags do I have to specify at compile time? I'm using Ubuntu 12.04!

Thanks

Emanuele
  • 1,408
  • 1
  • 15
  • 39

1 Answers1

3

Just add the option -pthread or -lpthread when linking.

Options -std=c99/c11 will restrict the available library functions to those of C99/C11 standard library

For getting C99/C11 languages features/library and and POSIX (and some BSD and some GNU extension) APIs, one can use -std=gnu99 or -std=gnu11 option to GCC.

chill
  • 16,470
  • 2
  • 40
  • 44
  • Looks like it's not working, I get " error: unknown type name ‘pthread_spinlock_t’ ". I had to add -D_POSIX_C_SOURCE=200112L. Was hoping for a better way without having to use this macro define. – Emanuele Dec 01 '12 at 20:50
  • Did you have other options to GCC ? Like `--std=c99" ? – chill Dec 01 '12 at 20:54
  • @Emanuele, because on Ubuntu 12.01.1 LTS with gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3, the `pthread_spinlock_t` and related functions do not need any gcc command line options by default. – chill Dec 01 '12 at 21:03
  • I had the option -std=c99. Should I use another one? Whitout this option I can't declare variables around the code and in the for loops... – Emanuele Dec 01 '12 at 21:04
  • 1
    You can also use `--std=gnu99` instead. – chill Dec 01 '12 at 21:05
  • Please specify this in the answer, so I can vote it up and close it! Cheers! :-) Ps. Ofc it works like a charm! – Emanuele Dec 01 '12 at 22:43
  • See also: [How to compile a C program that uses pthread.h?](https://askubuntu.com/questions/420722/how-to-compile-a-c-program-that-uses-pthread-h/443607#443607) – Gabriel Staples Jul 19 '21 at 05:05