Fedora Linux Support Community & Resources Center
  #1  
Old 28th September 2005, 08:02 PM
afeick Offline
Registered User
 
Join Date: Sep 2005
Posts: 5
static linking pthread lib

Due to numerous "undefined reference to `pthread_.....", I am unable to statically link our program. We just upgraded from RH8 with gcc3.2 to FC4 with gcc4.0. Since we only have one Linux machine, I have no way to test if this is an issue with gcc4.0 or just the way Fedora builds it.

Does anyone have any ideas or suggestions?
Reply With Quote
  #2  
Old 28th September 2005, 09:55 PM
RedFedora Offline
Registered User
 
Join Date: May 2004
Posts: 503
Could you give us an example of trying to compile a simple program? Something
like:
gcc -o MyProgram myprog.c -lpthread
__________________
Registered Linux User # 373325
Reply With Quote
  #3  
Old 29th September 2005, 08:02 PM
afeick Offline
Registered User
 
Join Date: Sep 2005
Posts: 5
g++ -o MyProgram \
-static \
../../myprogram/server/source/port/*.o \
../../myprogram/server/source/stubs/*.o \
../../myprogram/server/source/unix/*.o \
../../myprogram/semiportlib/*.o \
../../myprogram/portlib/*.o \
../../thirdparty/ijgjpeg/*.o \
../../thirdparty/zlib/*.o \
../../thirdparty/freetype/objs/*.o \
-L../../thirdparty/spelling/Unix -lprlib \
-L../../thirdparty/centradoc -lpsi \
-lpthread -lrt



We end up with a lot of errors that look like this:
../../myprogram/server/source/port/MYCode.o(.text+0x36): In function `__gthread_once(int*, void (*)())':
MYCode.cpp: undefined reference to `pthread_once'


Other undifined functions include: pthread_mutex_init, pthread_mutex_lock, pthread_setspecific, pthread_getspecific, pthread_create, pthread_join, pthread_key_create, pthread_key_delete


Also get numerous errors in libstdc++ and libgcc:

/usr/lib/gcc/i386-redhat-linux/4.0.0/libstdc++.a(eh_alloc.o)(.text.__cxa_free_exception +0x8b): In function `__cxa_free_exception':
: undefined reference to `pthread_mutex_lock'

/usr/lib/gcc/i386-redhat-linux/4.0.0/libgcc_eh.a(unwind-dw2-fde-glibc.o)(.text+0x90b): In function `__register_frame_info_bases':
: undefined reference to `pthread_mutex_lock'
Reply With Quote
  #4  
Old 29th September 2005, 08:04 PM
afeick Offline
Registered User
 
Join Date: Sep 2005
Posts: 5
Oh, and I forgot to mention that everything links and runs just fine as long as I drop the '-static' when linking.
Reply With Quote
  #5  
Old 29th September 2005, 11:00 PM
mr700 Offline
Registered User
 
Join Date: Nov 2003
Location: Bulgaria, Sofia
Age: 37
Posts: 32
A quick guess - look at /lib/obsolete/linuxthreads, linux threads were obsoleted and your code seems to use them. Either add them to the library path or just migrate your code to use native threads (the better idea).
__________________
Registered Linux user #291323
Reply With Quote
  #6  
Old 30th September 2005, 01:08 AM
RedFedora Offline
Registered User
 
Join Date: May 2004
Posts: 503
I've heard lots about the wonders of the native threads which go along
with kernel 2.6 (and RH's later versions of 2.4). Does anyone know where
I can find a good introduction which covers the differences between older
threads and the new native threads?
__________________
Registered Linux User # 373325
Reply With Quote
  #7  
Old 30th September 2005, 04:48 PM
afeick Offline
Registered User
 
Join Date: Sep 2005
Posts: 5
I'm not really sure, even after looking at it. We develop cross-platform, so we've always just used POSIX thread calls.


Actually, it just seems I can't link statically on this linux setup.

I just tried a simple "Hello World" linked as -static, and it won't work:


test.c :

#include <stdio.h>
int main (void)
{
printf("Hello World!\n");
return 1;
}


>$ gcc -o -static test test.c
test(.rodata+0x0): multiple definition of `_fp_hw'
/usr/lib/gcc/i386-redhat-linux/4.0.0/../../../crt1.o(.rodata+0x0): first defined here
test(.data+0x4): In function `__data_start':
: multiple definition of `__dso_handle'
/usr/lib/gcc/i386-redhat-linux/4.0.0/crtbegin.o(.data+0x0): first defined here
test(.init+0x0): In function `_init':
: multiple definition of `_init'
/usr/lib/gcc/i386-redhat-linux/4.0.0/../../../crti.o(.init+0x0): first defined here
test(.text+0x0): In function `_start':
: multiple definition of `_start'
/usr/lib/gcc/i386-redhat-linux/4.0.0/../../../crt1.o(.text+0x0): first defined here
test(.fini+0x0): In function `_fini':
: multiple definition of `_fini'
/usr/lib/gcc/i386-redhat-linux/4.0.0/../../../crti.o(.fini+0x0): first defined here
test(.got.plt+0x0): multiple definition of `_GLOBAL_OFFSET_TABLE_'
/usr/lib/gcc/i386-redhat-linux/4.0.0/../../../crt1.o(.got.plt+0x0): first defined here
test(.rodata+0x4): multiple definition of `_IO_stdin_used'
/usr/lib/gcc/i386-redhat-linux/4.0.0/../../../crt1.o(.rodata+0x4): first defined here
test(.data+0x0): In function `__data_start':
: multiple definition of `__data_start'
/usr/lib/gcc/i386-redhat-linux/4.0.0/../../../crt1.o(.data+0x0): first defined here
/tmp/ccCnqNZp.o(.text+0x0): In function `main':
test.c: multiple definition of `main'
test(.text+0xa4): first defined here
/usr/lib/gcc/i386-redhat-linux/4.0.0/../../../crt1.o(.dynamic+0x0): multiple definition of `_DYNAMIC'
test(.dynamic+0x0): first defined here
collect2: ld returned 1 exit status

Last edited by afeick; 30th September 2005 at 05:05 PM.
Reply With Quote
  #8  
Old 30th September 2005, 06:05 PM
mr700 Offline
Registered User
 
Join Date: Nov 2003
Location: Bulgaria, Sofia
Age: 37
Posts: 32
Arrow NPTL Info

NPTL Info: http://people.redhat.com/drepper/nptl-design.pdf, http://people.redhat.com/drepper/glibcthreads.html and http://people.redhat.com/drepper/assumekernel.html.
Also, from http://pauillac.inria.fr/~xleroy/linuxthreads/faq.html :
Quote:
Also note that LinuxThreads is no longer developed and has been replaced by NPTL, the Native POSIX Threads Library for Linux, which fixes many shortcomings of LinuxThreads and offers better performance.
PS: 'gcc -o -static test test.c' is not working, 'gcc -static -o test test.c' does
PS2: http://kerneltrap.org/node/422 - one more interesting link. Why do I add this 1 week later? Well... I was wondering where the h** it was... shame on me
__________________
Registered Linux user #291323

Last edited by mr700; 6th October 2005 at 06:10 PM.
Reply With Quote
  #9  
Old 30th September 2005, 08:04 PM
afeick Offline
Registered User
 
Join Date: Sep 2005
Posts: 5
Quote:
Originally Posted by mr700
PS: 'gcc -o -static test test.c' is not working, 'gcc -static -o test test.c' does

DOH! Yeah, I should've seen that, it was just an odd error since I happened to use the name 'test'.

It still doesn't solve my original problem, and I don't think it has anything to do with linuuxthreads. We've only ever used POSIX thread calls, so from what I can tell the compiler should just use NPTL and I shouldn't have to worry.
Reply With Quote
  #10  
Old 6th October 2005, 06:21 PM
mr700 Offline
Registered User
 
Join Date: Nov 2003
Location: Bulgaria, Sofia
Age: 37
Posts: 32
Question

Quote:
Originally Posted by afeick
...
Actually, it just seems I can't link statically on this linux setup.

I just tried a simple "Hello World" linked as -static, and it won't work:

test.c :

#include <stdio.h>
int main (void)
{
printf("Hello World!\n");
return 1;
}

>$ gcc -o -static test test.c
test(.rodata+0x0): multiple definition of `_fp_hw'
/usr/lib/gcc/i386-redhat-linux/4.0.0/../../../crt1.o(.rodata+0x0): first defined here
...
I can't reproduce it with FC4:
Code:
[pts/3 mr700@laptop:~/tmp]$ cat <<EOF > b.c
> #include <stdio.h>
> int main (void)
> {
>   printf("Hello World!\n");
>   return 1;
> }
> EOF
[pts/3 mr700@laptop:~/tmp]$ gcc -static -o b b.c
[pts/3 mr700@laptop:~/tmp]$ ls -al b
-rwxrwxr-x  1 mr700 mr700 487100 Oct  6 20:12 b
[pts/3 mr700@laptop:~/tmp]$ ldd b
        not a dynamic executable
[pts/3 mr700@laptop:~/tmp]$ ./b
Hello World!
[pts/3 mr700@laptop:~/tmp]$ uname -a
Linux laptop.*** 2.6.13-1.1526_FC4.jwltest.18 #1 Fri Sep 30 13:46:46 EDT 2005 i686 athlon i386 GNU/Linux
gcc version 4.0.1 20050727 (Red Hat 4.0.1-5), rpmverify your gcc and devel libs.
__________________
Registered Linux user #291323
Reply With Quote
  #11  
Old 4th November 2005, 01:18 PM
leedixon Offline
Registered User
 
Join Date: Nov 2005
Posts: 5
This post is a bit old, but in case someone runs across it, the answer should be that the linking order was wrong:

Try changing from "... -lrt -lpthread" to "-lpthread -lrt"
Library order TOTALLY matters when linking statically.
Reply With Quote
Reply

Tags
lib, linking, pthread, static

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
gcc 4.1 static linking deeloke Fedora Core 5 - Dev 0 30th April 2007 03:25 PM
Pthread issues TerjeG Using Fedora 1 18th February 2007 07:45 PM
pthread aggravation... Pazuzu Using Fedora 0 21st December 2006 05:21 PM
pthread id and process id ckmun81 Using Fedora 0 20th November 2006 02:32 AM
Static linking issue with glibc sivaram_swdw Using Fedora 2 27th July 2005 12:30 PM


Current GMT-time: 19:58 (Tuesday, 21-10-2014)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat
Kalabagh Instagram Photos - Sabanagrande Travel Photos - Ghormach Travel Photos