1

I build 32-bit application on 64-bit Linux (RH6).
I check how linker searches libraries during linkage and see that it gets found a right 32-bit library libz but drops it, goes to seach further and gets found 64-bit version of it:
3885956: trying file=/lib/libz.so.1 3885956: search cache=/etc/ld.so.cache 3885956: trying file=/lib64/libz.so.1
After all linker says:
/usr/bin/ld: skipping incompatible /usr/lib64/libz.so when searching for -lz /usr/bin/ld: cannot find -lz collect2: ld returned 1 exit status
Could somebody explain me why linker does this and how to force it to get 32-bit library?
Thsnks.

PS. I use -m32 option but it does not help in this case.

UPDATE! It seems the investigation is transferred to another field - Electric Make. If I run emake (origina targeting case) it fails. If I copy-paste-execute command which emake is failed on then build is finished successfully.
So difference in contexts is suspected.
Have no idea how to investigate

UPDATE2
It is strange enough. Electric Make just drops common libraies like /usr/lib from search path (LD_LIBRARY_PATH) which it is called with and uses only paths which are in Clearcase file system. If it does not find necessary library there it gets ld's cache and searches there. Being met 64-bit libz.so (geos first in cache file) it stops searching and returns with error.

OlegG
  • 975
  • 3
  • 10
  • 30
  • Show your exact command line. – n. m. could be an AI Dec 24 '14 at 15:24
  • 1
    "I check how linker searches [...]" how did you do that? It looks like what `ld.so` might do, not `ld`. My guess would be that you are missing the -devel package in 32bit. – Marc Glisse Dec 24 '14 at 16:55
  • Just make sure that the gcc PATH is correct. Check this post http://stackoverflow.com/questions/3501878/force-gcc-to-compile-32-bit-programs-on-64-bit-platform – tan Dec 24 '14 at 16:58
  • Unless you're using an older version of gcc, the `-m32` option is deprecated. IIRC, it was deprecated exactly because of the problems of keeping straight where libs and headers were for 32 and 64. It's now recommended that you have sperate installations configured for each target you want to support. – Tyler Dec 24 '14 at 17:39
  • @MarcGlisse: you're right, I investigated log of ld.so, not ld. This could be a tip. Thx! The 32-bit libz.so does exist. I've checked it. – OlegG Dec 25 '14 at 07:51
  • @Tyler Citation needed. The [Option Summary](https://gcc.gnu.org/onlinedocs/gcc/Option-Summary.html) does show some command-line options are deprecated (e.g. `-std=c9x` for C), but there isn't anything mentioning deprecation in the description of `-m32`. –  Dec 25 '14 at 09:48
  • Just to make sure, it does say "trying file=/lib/libz.so.1", but does /lib/libz.so.1 actually exist? It doesn't say that it *found* /lib/libz.so.1. –  Dec 25 '14 at 09:51
  • @hvd: yes, I ensured that necessary libz.so is existing (including symlinks checking) – OlegG Dec 25 '14 at 10:07

2 Answers2

0

Gcc will look for lib files in particular order:

  1. Path follows -L option

  2. Path in environment variable LD_LIBRARY_PATH

  3. Path in file /etc/ld.so.conf

  4. /lib and /usr/lib

So try to use -L to tell compiler search for libz.so in the folder contain the 32bit version first.

Qmick Zh
  • 555
  • 3
  • 8
  • As you can see from log fragment in my post, linker gets found 32-bit libz.so in proper place (first line beginning from word "trying"). But then it does ignore it and use 64-bit one. It gets found 32-bit lib exactly because LD_LIBRARY_PATH contains path /lib and 64-bit lib becasue /etc/ld.so.cache (which ld uses next) contains path /lib64 with a 64-bit versions. – OlegG Dec 25 '14 at 07:44
0

Probably you have not installed the 32-bit version of the library. Try to find a packet zlib.i586 or something similar.

Another possible source of the problem, may be an "appropriate" symlink at the /lib directory. I have faced situations where the /lib/libfoo.so was a symbolink link of /lib64/libfoo.so or even worst a hard copy. Using the ldd tool you can retrieve the actual architecture of library. A 32-bit library will depend on /lib/ld-linux.so whereas a 64-bit on /lib64/ld-linux-x86-64.so.

Manos
  • 2,136
  • 17
  • 28
  • Linker gets found a 32-bit libz.so but does ignore it by some reasons. – OlegG Dec 25 '14 at 07:49
  • I checked both libraries libz.so using the 'file' command and ensured they have correct corresponding versions – OlegG Dec 25 '14 at 10:10