Operating System - Linux
1752421 Members
5816 Online
108788 Solutions
New Discussion юеВ

Re: pthread includes trouble with gcc

 
SOLVED
Go to solution
Florian Heigl (new acc)
Honored Contributor

pthread includes trouble with gcc

Hi,

I'm trying to understand a small issue I see during a compile.

I'm using gcc 3.4.3 from the hp-ux porting archive for the compile.
The software is the backup tool bacula, which to compile on HP-UX is on my todo-list for almost two years now ;)

(I could try to swremove the current gcc and use the itrc version, but right now I'm happy to have grasped the problem and would rather try to fix it)

during make I get the following error:

/usr/local/bin/g++ -L../lib -L../cats -o bconsole console.o console_conf.o authenticate.o conio.o \
-lcurses -lbac -lm -lgen
/usr/ccs/bin/ld: Unsatisfied symbols:
__pthread_cancel_stack (first referenced in ../lib/libbac.a(rwlock.o)) (code)


strings ./src/lib/rwlock.o | grep __pthread_cancel_stack
__pthread_cancel_stack

(yes, it's in there)

I grepped through the sourcetree and found no reference to this function.

After that I looked through /usr/include and found some function declarations refering it in sys/pthread.h:

grep pthread_cancel_stack /usr/include/sys/pthread.h
extern __pthread_cleanup_handler_t **__pthread_cancel_stack(void);
extern __pthread_cleanup_handler_t **__pthread_cancel_stack();
__pth_cleanup_push(func, arg, __pthread_cancel_stack())


But, this is what I don't understand:
where is pthread_cancel_stack defined?

I found nothing in /usr/include or whereever I looked.

(I also checked gcc's include directory out of bad experiences, but nothing there.)

I'd be really thankful if someone with a few spare minutes could give me a little explanation here... :)

Florian
yesterday I stood at the edge. Today I'm one step ahead.
3 REPLIES 3
Florian Heigl (new acc)
Honored Contributor

Re: pthread includes trouble with gcc

I've got it solved, but I'd be still happy if someone could explain me what I actually did :)

I set LDFLAGS="-lcl -lpthread" , as I had that in my perl Configure notes, and this allowed the linking to work, as You can see here:

/usr/bin/ar rc libbac.a alloc.o attr.o base64.o berrno.o bsys.o bget_msg.o bnet.o bnet_server.o bpipe.o bshm.o btime.o cram-md5.o crc32.o daemon.o edit.o fnmatch.o hmac.o idcache.o jcr.o lex.o alist.o dlist.o md5.o message.o mem_pool.o parse_conf.o queue.o rwlock.o scan.o serial.o sha1.o semlock.o signal.o smartall.o tree.o util.o var.o watchdog.o workq.o btimers.o address_conf.o
ranlib libbac.a
yesterday I stood at the edge. Today I'm one step ahead.
Ermin Borovac
Honored Contributor
Solution

Re: pthread includes trouble with gcc

Well it doesn't use __pthread_cancel_stack() directory, but it does use pthread_cleanup_push().

pthread_cleanup_push() is defined in as

#define pthread_cleanup_push(func, arg) \
__pth_cleanup_push(func, arg, __pthread_cancel_stack())

So that's where __pthread_cancel_stack() gets to get used indirectly.

Anyway, these functions are defined in libpthread. By adding it to LDFLAGS I assume libpthread gets added to g++ line (-lpthread) as in

/usr/local/bin/g++ -L../lib -L../cats -o bconsole console.o console_conf.o authenticate.o conio.o \
-lcurses -lbac -lm -lgen -lpthread

so __pthread_cancel_stack() will be resolved when it gets referenced through libbac.a (rwlock.o).

Hope that's not as clear as mud :-)
Florian Heigl (new acc)
Honored Contributor

Re: pthread includes trouble with gcc

I think I understood it now :)))
yesterday I stood at the edge. Today I'm one step ahead.