LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-07-2012, 06:58 PM   #1
Refractor
Member
 
Registered: Oct 2008
Location: Rousse, Bulgaria
Distribution: Slackware
Posts: 89

Rep: Reputation: 24
Question Linking against glibc installed in a non-standard location with confiugre


Greetings,
I need to build libarchive, linked to libraries in a non-standard location.
The setup is the following: Archlinux multilib with GCC 4.7.0
Already built the following 32-bit only libraries:
Code:
acl 2.2.51
attr 2.4.46
bzip2 1.0.6
expat 2.1.0
glibc 2.15
openssl 1.0.1c
sqlite 3.7.12.1
vim 7.3
xz 5.0.3
zlib 1.2.7
Using the following variable:
Code:
$CHROOT=/home/axtroz/source/Smartix/chroot
$CHROOT is the place where the 32-bit only libraries and tools are installed. Now to build libarchive:
Code:
./configure CPPFLAGS="-m32 -I$CHROOT/usr/include" LDFLAGS="-L$CHROOT/usr/lib -L$CHROOT/lib" LIBS="-llzma" --without-nettle --build=i686-pc-linux-gnu --host=i686-pc-linux-gnu
-llzma is there because the configure script doesn't link with it if not specified and build fails with undefined references to the lzma functions.
This fails with:
Code:
configure:3722: checking whether the C compiler works
configure:3744: gcc  -m32 -I/home/axtroz/source/Smartix/chroot/usr/include -L/home/axtroz/source/Smartix/chroot/usr/lib -L/home/axtroz/source/Smartix/chroot/lib conftest.c -llzma >&5
/usr/bin/ld: skipping incompatible /lib/libc.so.6 when searching for /lib/libc.so.6
/usr/bin/ld: cannot find /lib/libc.so.6
/usr/bin/ld: skipping incompatible /usr/lib/libc_nonshared.a when searching for /usr/lib/libc_nonshared.a
/usr/bin/ld: cannot find /usr/lib/libc_nonshared.a
collect2: error: ld returned 1 exit status
configure:3748: $? = 1
configure:3786: result: no
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME "libarchive"
| #define PACKAGE_TARNAME "libarchive"
| #define PACKAGE_VERSION "3.0.4"
| #define PACKAGE_STRING "libarchive 3.0.4"
| #define PACKAGE_BUGREPORT "libarchive-discuss@googlegroups.com"
| #define PACKAGE_URL ""
| #define PACKAGE "libarchive"
| #define VERSION "3.0.4"
| #define LIBARCHIVE_VERSION_STRING "3.0.4"
| #define LIBARCHIVE_VERSION_NUMBER "3000004"
| #define BSDCPIO_VERSION_STRING "3.0.4"
| #define BSDTAR_VERSION_STRING "3.0.4"
| /* end confdefs.h.  */
| 
| int
| main ()
| {
| 
|   ;
|   return 0;
| }
configure:3791: error: in `/home/axtroz/source/Smartix/projects/libarchive/libarchive-3.0.4':
configure:3793: error: C compiler cannot create executables
If I remove the LDFLAGS libarchive builds against the currently installed libraries on the system, but I need it linked to the ones installed in $CHROOT.
Thank you for your time!

Last edited by Refractor; 06-07-2012 at 07:16 PM. Reason: Major re-edit on the thread.
 
Old 06-08-2012, 11:15 AM   #2
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Instead, you could try LDFLAGS="-rpath-link=$CHROOT/usr/lib:$CHROOT/lib". You might need to prefix it with -Wl,, if the compiler is called for linking. Also, why is there a "$" in $CHROOT=...?
Kevin Barry
 
Old 06-08-2012, 01:44 PM   #3
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by ta0kira View Post
Instead, you could try LDFLAGS="-rpath-link=$CHROOT/usr/lib:$CHROOT/lib". You might need to prefix it with -Wl,, if the compiler is called for linking. Also, why is there a "$" in $CHROOT=...?
Kevin Barry

Well, with 'glibc' the known tricks might not work - I once devoted quite a time to building literally hundreds of targets with "my own" 'glibc'.

The pitfalls are:

1) standard utilities (like 'cp', 'mv', 'awk') rely on 'glibc', so if LD_LIBARY_PATH is set to point to "private" 'glibc' before 'configure' is invoked, the standard utilities may stop working;

2) 'gcc' itself uses a number of libraries which in their turn depend on 'glibc' - the same gotcha;

3) the same applies to 'binutils'.

My approach was to build at least the standard routines and 'binutils' statically linked and then use them building the rest.
 
Old 06-08-2012, 05:19 PM   #4
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
What about --with-sysroot="$CHROOT"? I just did ./configure --help on one of my projects and that showed up.
Kevin Barry
 
Old 06-08-2012, 05:33 PM   #5
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by ta0kira View Post
What about --with-sysroot="$CHROOT"? I just did ./configure --help on one of my projects and that showed up.
Kevin Barry
I haven't tried this yet. But, anyway, this means one has to build yet another 'gcc' first - doesn't it ?
 
Old 06-08-2012, 06:11 PM   #6
Refractor
Member
 
Registered: Oct 2008
Location: Rousse, Bulgaria
Distribution: Slackware
Posts: 89

Original Poster
Rep: Reputation: 24
ta0kira, the '$' in the variable initialisation is a typo
I did try the --with-chroot option to no avail, I tried to manually edit the generated makefile with default settings without success, so next up is the static versions of GCC, binutils, coreutils etc...
Thanks for the suggestions, both of you!
 
Old 06-08-2012, 07:02 PM   #7
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Quote:
Originally Posted by Sergei Steshenko View Post
I haven't tried this yet. But, anyway, this means one has to build yet another 'gcc' first - doesn't it ?
I think that's something separate. The help says:
Code:
  --with-sysroot=DIR Search for dependent libraries within DIR
                        (or the compiler's sysroot if not specified).
Kevin Barry
 
Old 06-08-2012, 07:05 PM   #8
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by Refractor View Post
ta0kira, the '$' in the variable initialisation is a typo
I did try the --with-chroot option to no avail, I tried to manually edit the generated makefile with default settings without success, so next up is the static versions of GCC, binutils, coreutils etc...
Thanks for the suggestions, both of you!
The order is rather coreutils ( + grep, find, awk, etc), binutils, gcc. I haven't tried to build static gcc, and I don't know whether this is possible. I vaguely remember gcc build documentation saying something about cross-gcc, and gcc using non-default glibc is cross-gcc. Again, IIRC.
 
1 members found this post helpful.
Old 06-11-2012, 08:33 AM   #9
Refractor
Member
 
Registered: Oct 2008
Location: Rousse, Bulgaria
Distribution: Slackware
Posts: 89

Original Poster
Rep: Reputation: 24
Hello again,
I've built binutils and gcc for target i686-pc-linux-gnu, then built glibc with those (had to apply a couple of patches taken from linuxfromscratch.org's development book).
Now when trying to compile a simple test program other issues arise:
Code:
[axtroz@Arch64 test]$ cat > test.c << EOF
> #include <stdio.h>
> int main(int argc, char** argv) {
> printf("It works!\n");
> return 0;
> }
> EOF
[axtroz@Arch64 test]$ echo $PATH
/home/axtroz/32bit/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/bin/core_perl
[axtroz@Arch64 test]$ i686-pc-linux-gnu-gcc -I$HOME/32bit/include test.c -o test
/home/axtroz/32bit/lib/gcc/i686-pc-linux-gnu/4.7.0/../../../../i686-pc-linux-gnu/bin/ld: cannot find crt1.o: No such file or directory
/home/axtroz/32bit/lib/gcc/i686-pc-linux-gnu/4.7.0/../../../../i686-pc-linux-gnu/bin/ld: cannot find crti.o: No such file or directory
/home/axtroz/32bit/lib/gcc/i686-pc-linux-gnu/4.7.0/../../../../i686-pc-linux-gnu/bin/ld: cannot find -lc
/home/axtroz/32bit/lib/gcc/i686-pc-linux-gnu/4.7.0/../../../../i686-pc-linux-gnu/bin/ld: cannot find crtn.o: No such file or directory
collect2: error: ld returned 1 exit status
[axtroz@Arch64 test]$ i686-pc-linux-gnu-gcc -I$HOME/32bit/include -L$HOME/32bit/lib test.c -o test
/home/axtroz/32bit/lib/gcc/i686-pc-linux-gnu/4.7.0/../../../../i686-pc-linux-gnu/bin/ld: cannot find crt1.o: No such file or directory
/home/axtroz/32bit/lib/gcc/i686-pc-linux-gnu/4.7.0/../../../../i686-pc-linux-gnu/bin/ld: cannot find crti.o: No such file or directory
collect2: error: ld returned 1 exit status
[axtroz@Arch64 test]$ ls $HOME/32bit/lib | grep crt
crt1.o
crti.o
crtn.o
gcrt1.o
Mcrt1.o
Scrt1.o
It seems to find crtn.o, but not crt1.o and crti.o, while all of them share the same directory.
EDIT:
I've managed to put everything together the following way, but now the resulting binary isn't executable:
Code:
[axtroz@Arch64 test]$ i686-pc-linux-gnu-ld test.o $HOME/32bit/lib/{crtn.o,crt1.o,crti.o} -L$HOME/32bit/lib -lc -o test
[axtroz@Arch64 test]$ file test
test: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.0.0, not stripped
[axtroz@Arch64 test]$ ldd test
/home/axtroz/32bit/bin/ldd: line 126: ./test: No such file or directory
[axtroz@Arch64 test]$ i686-pc-linux-gnu-nm test
08049438 d _DYNAMIC
08049504 d _GLOBAL_OFFSET_TABLE_
080483ac R _IO_stdin_used
08049520 A __bss_start
0804951c D __data_start
         w __gmon_start__
08049438 d __init_array_end
08049438 d __init_array_start
08048380 T __libc_csu_fini
08048310 T __libc_csu_init
         U __libc_start_main@@GLIBC_2.0
080482dc T __x86.get_pc_thunk.bx
08049520 A _edata
08049520 A _end
0804838c T _fini
080483a6 R _fp_hw
0804825c T _init
080482e0 T _start
0804951c W data_start
080482c0 T main
         U puts@@GLIBC_2.0
Any thoughts?
As always, thanks for your time!

Last edited by Refractor; 06-11-2012 at 08:52 AM. Reason: Made some progress on the problem, or at least I think so :)
 
Old 06-11-2012, 10:09 AM   #10
Refractor
Member
 
Registered: Oct 2008
Location: Rousse, Bulgaria
Distribution: Slackware
Posts: 89

Original Poster
Rep: Reputation: 24
After some more reading I figured out that it tries to link against /lib/ld-linux.so.2 which is my system's linker and not my custom glibc's. It is like that because of a hardcoded path in the GCC sourcecode. So now I know that first I need to change the path before building gcc. Bottom line is one needs to follow the instructions from the LFS book, chapter 5.3 to 5.8.
 
Old 06-11-2012, 02:15 PM   #11
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by Refractor View Post
After some more reading I figured out that it tries to link against /lib/ld-linux.so.2 which is my system's linker and not my custom glibc's. It is like that because of a hardcoded path in the GCC sourcecode. So now I know that first I need to change the path before building gcc. Bottom line is one needs to follow the instructions from the LFS book, chapter 5.3 to 5.8.
I forgot to mention that I had also built a statically linked shell, and it was 'dash'. The purpose, as for other, is to have a tool not depending on system 'glibc' dynamically.
 
  


Reply


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
Linking against other glibc version md_lasalle Programming 3 10-03-2007 03:57 PM
Linking headers in non-standerd location Fredstar Programming 2 07-15-2006 09:46 PM
building glibc 2.3.5 for static linking. rekhakp Linux - Software 0 04-26-2005 01:17 PM
Location of standard icons in Mandrake 10 Meriadoc Linux - Newbie 4 06-24-2004 04:06 AM
Linking with different versions of glibc. dimm_coder Programming 2 11-25-2003 07:25 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:39 PM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration