[RESOLU] compil avec lib pthread sous linux

compil avec lib pthread sous linux [RESOLU] - C - Programmation

Marsh Posté le 30-01-2009 à 12:52:39    

salut,
j'ai écris un programme qui utilise la librairie pthread. Il se compile très bien sous Windows, mais pas sous Linux.
 
Voici ma ligne de compilation :
 

Code :
  1. gcc -g -Wall -o service main.c thread_clock.c thread_led.c thread_machine.c -I./postgresql-8.3.5/src/include/ -I./postgresql-8.3.5/src/interfaces/libpq/ -I./pthreads-w32-2-8-0-release/ -L./pthreads-w32-2-8-0-release/lib/ -L/usr/lib/ -lpq -lpthread -DDEBUG


 
et le résultat :
 

Code :
  1. In file included from ./pthreads-w32-2-8-0-release/pthread.h:288,
  2.                  from main.h:31,
  3.                  from main.c:21:
  4. ./pthreads-w32-2-8-0-release/sched.h:70:3: error: #error Please upgrade your GNU compiler to one that supports __declspec.
  5. In file included from ./pthreads-w32-2-8-0-release/pthread.h:288,
  6.                  from main.h:31,
  7.                  from main.c:21:
  8. ./pthreads-w32-2-8-0-release/sched.h:146: warning: return type defaults to 'int'
  9. ./pthreads-w32-2-8-0-release/sched.h: In function '__declspec':
  10. ./pthreads-w32-2-8-0-release/sched.h:146: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'sched_yield'
  11. ./pthreads-w32-2-8-0-release/sched.h:148: error: expected declaration specifiers before '__declspec'
  12. ./pthreads-w32-2-8-0-release/sched.h:150: error: expected declaration specifiers before '__declspec'
  13. ./pthreads-w32-2-8-0-release/sched.h:152: error: expected declaration specifiers before '__declspec'
  14. ./pthreads-w32-2-8-0-release/sched.h:154: error: expected declaration specifiers before '__declspec'
  15. In file included from main.h:31,
  16.                  from main.c:21:
  17. ./pthreads-w32-2-8-0-release/pthread.h:307: warning: empty declaration
  18. In file included from main.h:31,
  19.                  from main.c:21:
  20. ./pthreads-w32-2-8-0-release/pthread.h:527:3: error: #error Please upgrade your GNU compiler to one that supports __declspec.
  21. ./pthreads-w32-2-8-0-release/pthread.h:569: error: storage class specified for parameter 'ptw32_handle_t'
  22. ./pthreads-w32-2-8-0-release/pthread.h:571: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'pthread_t'
  23. ./pthreads-w32-2-8-0-release/pthread.h:572: error: storage class specified for parameter 'pthread_attr_t'
  24. ./pthreads-w32-2-8-0-release/pthread.h:573: error: storage class specified for parameter 'pthread_once_t'
  25. ./pthreads-w32-2-8-0-release/pthread.h:574: error: storage class specified for parameter 'pthread_key_t'
  26. ./pthreads-w32-2-8-0-release/pthread.h:575: error: storage class specified for parameter 'pthread_mutex_t'
  27. ./pthreads-w32-2-8-0-release/pthread.h:576: error: storage class specified for parameter 'pthread_mutexattr_t'
  28. ./pthreads-w32-2-8-0-release/pthread.h:577: error: storage class specified for parameter 'pthread_cond_t'
  29. ./pthreads-w32-2-8-0-release/pthread.h:578: error: storage class specified for parameter 'pthread_condattr_t'
  30. ./pthreads-w32-2-8-0-release/pthread.h:580: error: storage class specified for parameter 'pthread_rwlock_t'
  31. ./pthreads-w32-2-8-0-release/pthread.h:581: error: storage class specified for parameter 'pthread_rwlockattr_t'
  32. ./pthreads-w32-2-8-0-release/pthread.h:582: error: storage class specified for parameter 'pthread_spinlock_t'
  33. ...


 
Si j'omet d'inclure pthread, voici ce qui se passe :
 

Code :
  1. gcc -g -Wall -o service main.c thread_clock.c thread_led.c thread_machine.c -I./postgresql-8.3.5/src/include/ -I./postgresql-8.3.5/src/interfaces/libpq/  -L./pthreads-w32-2-8-0-release/lib/ -L/usr/lib/ -lpq -lpthread -DDEBUG                               svn: warning: cannot set LC_CTYPE locale
  2. svn: warning: environment variable LANG is fr_FR.UTF-8
  3. svn: warning: please check that your locale name is correct
  4. At revision 878.
  5. thread_clock.c: In function 'thread_clock':
  6. thread_clock.c:102: warning: implicit declaration of function 'pthread_delay_np'
  7. thread_led.c: In function 'thread_led':
  8. thread_led.c:61: warning: implicit declaration of function 'pthread_delay_np'
  9. thread_machine.c: In function 'thread_machine':
  10. thread_machine.c:37: warning: implicit declaration of function 'pthread_delay_np'
  11. thread_machine.c: In function 'ParseEvents':
  12. thread_machine.c:223: warning: statement with no effect
  13. /tmp/ccEPYS1Z.o: In function `thread_clock':
  14. /home/linux/Desktop/service_C2/service_C_v2/thread_clock.c:27: undefined reference to `cmd_19CLK'
  15. /home/linux/Desktop/service_C2/service_C_v2/thread_clock.c:75: undefined reference to `cmd_19CLK_UPDATE'
  16. /home/linux/Desktop/service_C2/service_C_v2/thread_clock.c:82: undefined reference to `cmd_19CLK'
  17. /home/linux/Desktop/service_C2/service_C_v2/thread_clock.c:102: undefined reference to `pthread_delay_np'
  18. /tmp/cckvQVKv.o: In function `thread_led':
  19. /home/linux/Desktop/service_C2/service_C_v2/thread_led.c:61: undefined reference to `pthread_delay_np'
  20. /home/linux/Desktop/service_C2/service_C_v2/thread_led.c:89: undefined reference to `cmd_19PREVENTIVE'
  21. /home/linux/Desktop/service_C2/service_C_v2/thread_led.c:104: undefined reference to `pthread_delay_np'
  22. /tmp/cccxYmWm.o: In function `thread_machine':
  23. /home/linux/Desktop/service_C2/service_C_v2/thread_machine.c:37: undefined reference to `pthread_delay_np'
  24. /home/linux/Desktop/service_C2/service_C_v2/thread_machine.c:54: undefined reference to `pthread_delay_np'
  25. /home/linux/Desktop/service_C2/service_C_v2/thread_machine.c:95: undefined reference to `pthread_delay_np'
  26. /home/linux/Desktop/service_C2/service_C_v2/thread_machine.c:114: undefined reference to `cmd_19EVTS_RETRIEVE'
  27. /home/linux/Desktop/service_C2/service_C_v2/thread_machine.c:140: undefined reference to `pthread_delay_np'
  28. collect2: ld returned 1 exit status


 
J'ai vérifié plusieurs fois ma ligne de compil et les chemins, et tout correspond... Voyez vous l'origine de mon problème ?
 
Merci


Message édité par sonick le 30-01-2009 à 15:09:38
Reply

Marsh Posté le 30-01-2009 à 12:52:39   

Reply

Marsh Posté le 30-01-2009 à 13:36:20    

Pouquoi tu inclues les headers ./pthreads-w32-2-8-0-release plutôt que ceux de /usr/include ? Vu le w32 dans le nom ils m'ont l'air d'être faits pour windows ceux là, non ?

Reply

Marsh Posté le 30-01-2009 à 15:09:16    

Effectivement autant pour moi... J'ai aussi découvert que la fonction pthread_delay_np n'existait que pour win32, je l'ai remplacée par sleep() sous linux (sleep() est thread safe)

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed