lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Peter Shook wrote:
> Ben Sizer wrote:
>>  The compilation stage works just fine,
>> but the linking stage fails. Here's the command that my makefile
>> emits:
>>
>> gcc -lcrypt -o progname lua/lib/liblua.a lua/lib/liblualib.a first.o
>> second.o (...etc etc...)
>
> Try this:
>
>   gcc -lcrypt -o progname first.o second.o -Llua/lib -llua -llualib
>
> You need to list your object files first and your libs last because
> gcc only remembers the functions that are undefined in the object
> file, and then tries to find them in the libs.  If you specify the
> libs first, it doesn't remember any of those functions and that why
> it's not working for you.  Here is the relevant section from the gcc
> man page:
>
> -l library
>
> Search the library named library when linking.  (The second
> alternative with the library as a separate argument is only for
> POSIX compliance and is not recommended.)
>
> 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.

Yeah, I'd been reading this page, but I just misread this bit, as it's a
bit counter-intuitive. It also confused me in that I have a long list of
.o files in my Makefile that have numerous cross-dependencies yet GCC
handles them all just fine without any specific ordering required.
Anyway, you were right and it works now, so thanks.

--
Ben Sizer
http://pages.eidosnet.co.uk/kylotan