LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Debian (https://www.linuxquestions.org/questions/debian-26/)
-   -   statical linking (https://www.linuxquestions.org/questions/debian-26/statical-linking-943505/)

olego 05-06-2012 07:28 AM

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.

olego 05-06-2012 07:48 AM

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


sag47 05-06-2012 07:56 AM

Try taking away the trailing forward-slash. The paths in the output you provided appear to be invalid.
Code:

gcc ... -L ../Lib ...

olego 05-06-2012 08:01 AM

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.

olego 05-06-2012 08:03 AM

Quote:

Originally Posted by sag47 (Post 4671577)
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.

pan64 05-06-2012 08:48 AM

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.

olego 05-07-2012 12:54 AM

Quote:

Originally Posted by pan64 (Post 4671599)
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.


pan64 05-07-2012 10:08 AM

oh, yes, one more thing: just move -lm to the end of the command, this should be the last one

olego 05-10-2012 06:16 AM

Quote:

Originally Posted by pan64 (Post 4672485)
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!


All times are GMT -5. The time now is 07:51 AM.