Difficulties compiling
(1) By anonymous on 2024-02-23 10:54:56 [source]
Hi,
I'm running Tcl version 8.6.13 and would like to run a small web service.
I changed the Makefile like so:
#TCLLIB = /home/drh/tcl/lib/libtcl8.7.a -lm -lz -lpthread -ldl TCLLIB = /usr/local/lib/libtclstub8.6.a -lm -lz -lpthread -ldl TCLINC = /usr/local/include
I don't know where that 'libtcl8.7.a' comes from, so I added the only file that looked somehow similar from 8.6: 'libtclstub8.6.a'.
$ make tclsh mkccode.tcl wapptclsh.c.in >wapptclsh.c gcc -Os -static -I. -I/usr/local/include -o wapptclsh -DSQLITE_ENABLE_DESERIALIZE wapptclsh.c /usr/local/lib/libtclstub8.6.a -lm -lz -lpthread -ldl /usr/bin/ld: cannot find -lm /usr/bin/ld: cannot find -lz /usr/bin/ld: cannot find -lpthread /usr/bin/ld: cannot find -ldl /usr/bin/ld: cannot find -lc collect2: error: ld returned 1 exit status make: *** [Makefile:16: wapptclsh] Error 1
As LD_LIBRARY_PATH had no value, and libraries like thread2.9b1 is installed at /usr/local/lib/thread2.9b1 I did the following:
$ export LD_LIBRARY_PATH=/usr/local/lib $ make gcc -Os -static -I. -I/usr/local/include -o wapptclsh -DSQLITE_ENABLE_DESERIALIZE wapptclsh.c /usr/local/lib/libtclstub8.6.a -lm -lz -lpthread -ldl /usr/bin/ld: cannot find -lm /usr/bin/ld: cannot find -lz /usr/bin/ld: cannot find -lpthread /usr/bin/ld: cannot find -ldl /usr/bin/ld: cannot find -lc collect2: error: ld returned 1 exit status make: *** [Makefile:16: wapptclsh] Error 1
So, how can I compile this? And what are those libraries noted by '-lm', '-lz' '-ldl' and '-lc'? Where to point the Makefile to them or were to get them from?
Thank you.
(2) By Stephan Beal (stephan) on 2024-11-18 13:59:38 in reply to 1 [link] [source]
With my apologies for the much-delayed response: a "system event" caused a number of forum posts to get stuck in the moderation backlog.
And what are those libraries noted by '-lm', '-lz' '-ldl' and '-lc'? Where to point the Makefile to them or were to get them from?
Of those four libraries, -lz is the only one which might require manual installation: it's zlib, which is usually preinstalled on on any modern systems.
-lm (C's math library) and -ldl (for the dlopen() family of routines) are "always" preinstalled. If your compiler can't find those then "something is wrong." That said: -ldl is not needed on all platforms: on some, dlopen() and friends live in -lc (the main C library, against which one is never required to explicitly link).
-lpthread is the pthreads library, which is also typically preinstalled on any modern system.
It's not entirely suspicious that your system cannot find -lz and -lpthread, but your compiler must be able to find -lm or something is horribly wrong with the environment.
That said:
You're using the -static flag, and it's quite possible that static versions of those libraries aren't installed on your OS. Most modern Linux systems cannot build fully-static binaries for reasons beaten to death in articles posted across the internet. For building fully-static binaries you may need to use a specialized Linux distribution: i use Alpine Linux in a VM for exactly that purpose.