lua-users home
lua-l archive

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


> But when linked with ld, the library *is* statically linked.  That is,
> it does not call for any other libraries to be loaded when it is, and
> does not mention where to get its external symbols.

Right, I didn't realise that.

> The right thing to do when building shared libraries is to include
> appropriate -lfoo dependencies such that as many dependencies as
> possible are satisfied at link time.

In other words, use gcc as the linker (then it takes care of the
system-dependent details like -lc and -lgcc).

> It's convenient to build C-based libraries with gcc, as that gets the
> dependencies on libc and libgcc implicitly.  But it's also good to mark
> the other dependencies.  For example liblualib.so should be linked with
> -llua to find those dependencies.

Right.

> There are some systems where this is necessary---I think some versions
> of Solaris required libraries to have no unresolved external
> dependencies.  I know this is true for the snow ABI on mipsel-linux,
> where unresolved symbols are not possible in shared objects.
> Mentioning all your dependent libraries when building shared objects is
> good practice in general, as it plays nicely with things like symbol
> versioning, and can get the runtime linker to do the distasteful job of
> tracing all library dependencies for you.

Lua team, are you listening? (Although that part of the makefile is
supposed to work only on Linux, it seems better to get it to work on as
many OSes as possible).

This is done by the following patch for the Makefile:

---snip---
diff -Naur lua-5.0.1/Makefile lua-5.0.1patched/Makefile
--- lua-5.0.1/Makefile	2003-04-11 02:34:38.000000000 +0200
+++ lua-5.0.1patched/Makefile	2004-01-30 18:55:51.000000000
+0100
@@ -38,8 +38,8 @@

 # shared libraries (for Linux)
 so:
-	ld -o lib/liblua.so.$V -shared src/*.o
-	ld -o lib/liblualib.so.$V -shared src/lib/*.o
+	$(CC) $(MYCFLAGS) -o lib/liblua.so.$V -shared src/*.o
+	$(CC) $(MYCFLAGS) -o lib/liblualib.so.$V -shared src/lib/*.o -lm -ldl -llua
 	cd lib; ln -fs liblua.so.$V liblua.so; ln -fs
liblualib.so.$V liblualib.so

 # binaries using shared libraries
---snip---

The patch also links liblualib with libdl and libm, which are also used on
Linux.

-- 
http://www.mupsych.org/~rrt/ | maximiste, n.  pessimiste (Roux)