AL13N a écrit :
> Op vrijdag 21 september 2012 21:24:17 schreef PhilippeDidier:
>
>
>
> make a small test program, that uses pthread_cancel and try to compile
and
> link it.
when compiling (with gcc or g++) I've got this :
pthread_cancel.c:(.text+0xf0): undefined reference to `pthread_create'
pthread_cancel.c:(.text+0x142): undefined reference to `pthread_cancel'
pthread_cancel.c:(.text+0x184): undefined reference to `pthread_join'
when I compile with gcc -pthread -c
it works...
It seems to be a linkage problem !
Is there anything to do on the computer so that I don't have to add the
-pthread option to compile ?
or something to add in the spec file ?
>
> or you could find out with strings if that function is in there.
>
> lastly, i see you're building the .a file. don't do it and make it
dynamic,
> that could also have been an issue. if not at least it'll make the
problem
> alot more visible
>
>
I didn't change anything neither in the spec file nor in the source file
that I could use on my mandriva 2010.2 engine
(Franck Kober aka emuse maintainer of the music packages for Mandriva
2011 didn't modify the spec file... no more)
Thanks for your help !!
Regards
Philippe
#include <pthread.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#define handle_error_en(en, msg) \
do { errno = en; perror(msg); exit(EXIT_FAILURE); } while (0)
static void *
thread_func(void *ignored_argument)
{
int s;
/* Disable cancellation for a while, so that we don't
immediately react to a cancellation request */
s = pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
if (s != 0)
handle_error_en(s, "pthread_setcancelstate");
printf("thread_func(): started; cancellation disabled\n");
sleep(5);
printf("thread_func(): about to enable cancellation\n");
s = pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
if (s != 0)
handle_error_en(s, "pthread_setcancelstate");
/* sleep() is a cancellation point */
sleep(1000); /* Should get canceled while we sleep */
/* Should never get here */
printf("thread_func(): not canceled!\n");
return NULL;
}
int
main(void)
{
pthread_t thr;
void *res;
int s;
/* Start a thread and then send it a cancellation request */
s = pthread_create(&thr, NULL, &thread_func, NULL);
if (s != 0)
handle_error_en(s, "pthread_create");
sleep(2); /* Give thread a chance to get started */
printf("main(): sending cancellation request\n");
s = pthread_cancel(thr);
if (s != 0)
handle_error_en(s, "pthread_cancel");
/* Join with thread to see what its exit status was */
s = pthread_join(thr, &res);
if (s != 0)
handle_error_en(s, "pthread_join");
if (res == PTHREAD_CANCELED)
printf("main(): thread was canceled\n");
else
printf("main(): thread wasn't canceled (shouldn't happen!)\n");
exit(EXIT_SUCCESS);
}