[Kernel-meetup] Different behavior of gcc on Ubuntu

Bhavin Gandhi bhavin192 at yahoo.com
Sun Dec 10 05:41:35 PST 2017


Hi,

I was working on a project ecb-des[1] which uses libcrypt. When compiled
on Ubuntu [gcc (Ubuntu 7.2.0-8ubuntu3) 7.2.0] with
$ gcc -lcrypt ecb-des.c

it throws the error message[2],
but when compiled with
$ gcc ecb-des.c -lcrypt

it gets compiled.
According to gcc docs[3] (as I have understood it) the second way is the
correct one.
But on other distributions both of the ways work, tried on Debian 9 [gcc
(Debian 6.3.0-18) 6.3.0 20170516] and Fedora 27 [gcc (GCC) 7.2.1
20170915 (Red Hat 7.2.1-2)]
After searching found no explanation about this different in GCC from
Ubuntu. The same behavior is there on all the GCC versions present in
Ubuntu 14.04, 16.04, 17.10.
Most of the Ubuntu forum posts suggest the same way to link libraries[4]
It would be great if I get any pointer about this difference, so that I
can figure out the reason.


[1] https://github.com/geeksocket/ecb-des
[2] https://paste.opensuse.org/view/simple/17752627
[3] "It makes a difference where in the command you write this option;
the linker searches and processes libraries and object files in the
order they are specified. Thus, ‘foo.o -lz bar.o’ searches library ‘z’
after file foo.o but before bar.o. If bar.o refers to functions in ‘z’,
those functions may not be loaded."
https://gcc.gnu.org/onlinedocs/gcc-7.2.0/gcc/Link-Options.html#Link-Options
[4] https://ubuntuforums.org/showthread.php?t=1896659

- Bhavin Gandhi




-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://lists.reserved-bit.com/pipermail/kernel-meetup-reserved-bit.com/attachments/20171210/2674c4d3/attachment.sig>


More information about the Kernel-meetup mailing list