LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian
User Name
Password
Debian This forum is for the discussion of Debian Linux.

Notices

Reply
 
Search this Thread
Old 05-06-2012, 07:28 AM   #1
olego
Member
 
Registered: Sep 2008
Location: Kaliningrad, Russia
Distribution: Slackware
Posts: 35

Rep: Reputation: 1
statical linking


Dear all!

I have to build a big software project on my x86 debian machine to run on MIPS (actually mipsel) hardware. I can build dynamical app, but the problem that my embedded platfom has uClibc and my development platform has a normal libc. I can't build uClibc for mipsel because I get a ton of errors in kernel headers. Right now I have no time to fig into uClinc and spend time trying to build it. I can build a "Hello world!" app statically linked and it runs flawlessly. If I build my project dynamically I have no problems. But when I build statically I have many errors that functions not found.

Code:
mipsel-linux-gnu-gcc -static -L /usr/mipsel-linux-gnu/lib -lm -lpthread -L ../Lib/  -o ../Cmds//ETCP Rels//detc0cru.o Rels//detc0m2f.o Rels//detc0mai.o Rels//detc0soc.o Rels//detc0vru.o ../Lib//IsaNwl.o ../Lib//IsaSys.o ../Lib//ISysSoc.o
../Lib//ISysSoc.o: In function `dsysSocGetHostIp':
(.text+0x68): warning: Using 'gethostbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
../Lib//IsaSys.o: In function `dsysThrExit':
(.text+0x611c): undefined reference to `pthread_join'
../Lib//IsaSys.o: In function `dsysThrCreate':
(.text+0x6198): undefined reference to `pthread_attr_init'
../Lib//IsaSys.o: In function `dsysThrCreate':
(.text+0x61b0): undefined reference to `pthread_attr_setstacksize'
../Lib//IsaSys.o: In function `dsysThrCreate':
(.text+0x61cc): undefined reference to `pthread_create'
../Lib//IsaSys.o: In function `dsysThrCreate':
(.text+0x620c): undefined reference to `pthread_attr_destroy'
collect2: ld returned 1 exit status
make: *** [../Cmds//ETCP] Error 1
The same errors I get for "sinf", "cosf" and other funcs from libm.

I have libc.a, libm.a and libpthread.a. So my question - how can I avoid these errors? Why I get these errors? Why does libc.a is found but libm.a and libpthread.a don't? IsaSys.o it's a library actually but with an .o extension. My be I have to turn it to a normal library with .a extension? But it works with dynamic linking without problems. Any help will be highly appreciated.
 
Old 05-06-2012, 07:48 AM   #2
olego
Member
 
Registered: Sep 2008
Location: Kaliningrad, Russia
Distribution: Slackware
Posts: 35

Original Poster
Rep: Reputation: 1
I found an answer to my prev question: for MIPS gcc must get `-pthread' parameter not '-lpthread'.

But I still don't know how to correct math functions which are not found:

Code:
mipsel-linux-gnu-gcc -pthread -static -L /usr/mipsel-linux-gnu/lib -L ../Lib/ -lm  -o ../Cmds//IsaVM Rels//dipl0lnk.o Rels//divm0mai.o ../Lib//IsaKer.o ../Lib//IsaSrv.o ../Lib//IsaIXL.o ../Lib//IsxlHsd.o ../Lib//IsxlEtcp.o ../Lib//IsxlRsi.o ../Lib//IsaNwl.o ../Lib//EtcpCmon.o ../Lib//RsiCmon.o ../Lib//IKvbHsd.o ../Lib//IKvbEtcp.o ../Lib//IsaSys.o ../Lib//ISysSoc.o ../Lib//ISysHbt.o 
../Lib//ISysSoc.o: In function `dsysSocGetHostIp':
(.text+0x68): warning: Using 'gethostbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
../Lib//IsaKer.o: In function `SigGenFblCall':
(.text+0x340c): undefined reference to `sinf'
../Lib//IsaKer.o: In function `usfTan':
(.text+0x33124): undefined reference to `sincos'
../Lib//IsaKer.o: In function `usfSin':
(.text+0x33294): undefined reference to `sinf'
../Lib//IsaKer.o: In function `usfSin':
(.text+0x332d8): undefined reference to `sinf'
../Lib//IsaKer.o: In function `usfCos':
(.text+0x3337c): undefined reference to `cosf'
../Lib//IsaKer.o: In function `usfCos':
(.text+0x333c0): undefined reference to `cosf'
../Lib//IsaKer.o: In function `usfATan':
(.text+0x33464): undefined reference to `atanf'
../Lib//IsaKer.o: In function `usfATan':
(.text+0x334a8): undefined reference to `atanf'
../Lib//IsaKer.o: In function `usfASin':
(.text+0x335d8): undefined reference to `asin'
../Lib//IsaKer.o: In function `usfASin':
(.text+0x33610): undefined reference to `asin'
../Lib//IsaKer.o: In function `usfACos':
(.text+0x3372c): undefined reference to `acos'
../Lib//IsaKer.o: In function `usfACos':
(.text+0x33764): undefined reference to `acos'
../Lib//IsaKer.o: In function `usfTrunc':
(.text+0x33828): undefined reference to `floor'
../Lib//IsaKer.o: In function `usfTrunc':
(.text+0x33850): undefined reference to `floor'
../Lib//IsaKer.o: In function `usfTrunc':
(.text+0x33864): undefined reference to `ceil'
../Lib//IsaKer.o: In function `usfTrunc':
(.text+0x3388c): undefined reference to `ceil'
../Lib//IsaKer.o: In function `usfSqrt':
(.text+0x33998): undefined reference to `sqrt'
../Lib//IsaKer.o: In function `usfSqrt':
(.text+0x339d0): undefined reference to `sqrt'
../Lib//IsaKer.o: In function `usfPow':
(.text+0x33b20): undefined reference to `pow'
../Lib//IsaKer.o: In function `usfLog':
(.text+0x33c54): undefined reference to `log10'
../Lib//IsaKer.o: In function `usfLog':
(.text+0x33c8c): undefined reference to `log10'
collect2: ld returned 1 exit status
make: *** [../Cmds//IsaVM] Error 1
 
Old 05-06-2012, 07:56 AM   #3
sag47
Senior Member
 
Registered: Sep 2009
Location: Philly, PA
Distribution: Kubuntu x64, RHEL, Fedora Core, FreeBSD, Windows x64
Posts: 1,418
Blog Entries: 33

Rep: Reputation: 355Reputation: 355Reputation: 355Reputation: 355
Try taking away the trailing forward-slash. The paths in the output you provided appear to be invalid.
Code:
gcc ... -L ../Lib ...

Last edited by sag47; 05-06-2012 at 08:12 AM.
 
Old 05-06-2012, 08:01 AM   #4
olego
Member
 
Registered: Sep 2008
Location: Kaliningrad, Russia
Distribution: Slackware
Posts: 35

Original Poster
Rep: Reputation: 1
Hi!

I solved my problem by adding "/usr/mipsel-linux-gnu/lib/libm.a" at the end of commandline. Not a nice solution, but at least it works. I really don't understand why does this happen with static linking.
 
Old 05-06-2012, 08:03 AM   #5
olego
Member
 
Registered: Sep 2008
Location: Kaliningrad, Russia
Distribution: Slackware
Posts: 35

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by sag47 View Post
Take away the trailing forward-slash.
Code:
gcc ... -L ../Lib ...
Actually it doesn't matter. "/usr//lib" is not a good style but it works.
 
Old 05-06-2012, 08:48 AM   #6
pan64
Senior Member
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 4,527

Rep: Reputation: 1228Reputation: 1228Reputation: 1228Reputation: 1228Reputation: 1228Reputation: 1228Reputation: 1228Reputation: 1228Reputation: 1228
probably there is a libm.so in /usr/lib and there is no libm.a there.
The other problem can be you wrote -L../Lib (capital) instead of -L../lib. You know which one is the correct path.
 
Old 05-07-2012, 12:54 AM   #7
olego
Member
 
Registered: Sep 2008
Location: Kaliningrad, Russia
Distribution: Slackware
Posts: 35

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by pan64 View Post
probably there is a libm.so in /usr/lib and there is no libm.a there.
The other problem can be you wrote -L../Lib (capital) instead of -L../lib. You know which one is the correct path.
1. No, -L../Lib is a correct path, with the capital letter
2. I use cross compilation, so in my /usr/mipsel-linux-gnu/lib exist two libraries - libm.so and libm.a

Dynamic linking is working, for the static linking I must specify the path to libm.a explicitly. That is the problem. I don't undertsand why doesn't mipsel-linux-gnu-gcc see the static lib.

Code:
oleg@debian-vm:~$ ls -l /usr/mipsel-linux-gnu/lib/lib[cm].*
-rw-r--r-- 1 root root 3795856 Jan 24  2011 /usr/mipsel-linux-gnu/lib/libc.a
-rw-r--r-- 1 root root     301 Jan 25  2011 /usr/mipsel-linux-gnu/lib/libc.so
lrwxrwxrwx 1 root root      14 May  6 00:44 /usr/mipsel-linux-gnu/lib/libc.so.6 -> libc-2.11.2.so
-rw-r--r-- 1 root root 1001338 Jan 24  2011 /usr/mipsel-linux-gnu/lib/libm.a
lrwxrwxrwx 1 root root       9 May  6 00:44 /usr/mipsel-linux-gnu/lib/libm.so -> libm.so.6
lrwxrwxrwx 1 root root      14 May  6 00:44 /usr/mipsel-linux-gnu/lib/libm.so.6 -> libm-2.11.2.so
oleg@debian-vm:~$ mipsel-linux-gnu-gcc --version
mipsel-linux-gnu-gcc (Debian 4.4.5-8) 4.4.5
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
Old 05-07-2012, 10:08 AM   #8
pan64
Senior Member
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 4,527

Rep: Reputation: 1228Reputation: 1228Reputation: 1228Reputation: 1228Reputation: 1228Reputation: 1228Reputation: 1228Reputation: 1228Reputation: 1228
oh, yes, one more thing: just move -lm to the end of the command, this should be the last one
 
1 members found this post helpful.
Old 05-10-2012, 06:16 AM   #9
olego
Member
 
Registered: Sep 2008
Location: Kaliningrad, Russia
Distribution: Slackware
Posts: 35

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by pan64 View Post
oh, yes, one more thing: just move -lm to the end of the command, this should be the last one
Sure it helped. Thank you very much!
 
  


Reply

Tags
gcc, static


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
help with linking in c++ nuliknol Programming 2 07-01-2010 08:05 AM
Static linking vs. dynamic linking? posix_memalign Programming 13 04-18-2010 02:27 PM
linking? kalleanka Programming 4 11-09-2006 09:16 AM
Problem in using both load time linking and runtime linking durgaprasad_j Linux - General 0 08-01-2006 03:49 AM
Linking LS to 'L' uveraser Linux - General 2 05-20-2004 10:24 AM


All times are GMT -5. The time now is 11:19 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration