Skip to content
Tcl Source Code View Ticket
Login

View Ticket

Tcl fails to compile on FreeBSD 2.2.x

Closed / Out of Date443170ffffffffffffffffffffffffffffffffffCreated 25 years agoUpdated 22 years ago
Descriptionplain2001-07-20 19:18:32
Tcl fails to compile on our FreeBSD 2.2.5, 2.2.6, and 2.2.7 machines.  The error printed is:

cc  tclAppInit.o -L/n/bmrca/users/lim/src/mash-code/tcl8.3/unix -ltcl83 -lm -lc
 -Wl,-rpath,/usr/local/lib -o tclsh
ld: /usr/local/lib: malformed input file (not rel or archive)
*** Error code 1

Stop.

The message is kind of confusing.  The problem is that ld does not support the -rpath option.  
After watching configure and examining tcl.m4, these machines have dlfcn.h but do not have ELF.

Here is a patch to fix this problem:

--- tcl.m4.old  Fri Jul 20 10:51:31 2001
+++ tcl.m4.new  Fri Jul 20 11:50:21 2001
@@ -853,18 +853,20 @@
                DL_OBJS="tclLoadDl.o"
                DL_LIBS=""
                LDFLAGS=""
-               LD_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}'
                AC_MSG_CHECKING(for ELF)
                AC_EGREP_CPP(yes, [
 #ifdef __ELF__
        yes
 #endif
-               ],
+               ], [
                    AC_MSG_RESULT(yes)
-                   SHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}\$\{DBGX\}.so',
+                    LD_SEARCH_FLAGS='-Wl,-rpath,${LIB_RUNTIME_DIR}'
+                   SHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}\$\{DBGX\}.so'
+                ], [
                    AC_MSG_RESULT(no)
+                    LD_SEARCH_FLAGS='-Wl,-L${LIB_RUNTIME_DIR}'
                    SHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}\$\{DBGX\}.so.1.0'
-               )
+               ])
            ], [
                SHLIB_CFLAGS=""
                SHLIB_LD="echo tclLdAout $CC \{$SHLIB_CFLAGS\} | `pwd`/tclsh -r"
lloydlimplain2001-08-01 04:08:15
Logged In: YES 
user_id=99220

The above patch works fine when dynamic linking is used. 
However, when --disable-shared is used and static linking is
used to link in the tcl library, the link fails with:

ld: No reference to __DYNAMIC
*** Error code 1

Stop.

This can be reproduced by compiling a very small test
program that calls some Tcl routine and linking it as
follows:

gcc -Wall program.o -Ltcl8.3.3/unix -ltcl83 -lm -static -o
program

This problem can be solved by switching to a.out format. 
Here is a new patch that will work with static linking:

--- tcl.m4.old  Tue Jul 31 09:15:51 2001
+++ tcl.m4      Tue Jul 31 09:18:31 2001
@@ -842,7 +842,7 @@
            LDFLAGS="-Wl,-Bexport"
            LD_SEARCH_FLAGS=""
            ;;
-       NetBSD-*|FreeBSD-[[1-2]].*|OpenBSD-*)
+       NetBSD-*|OpenBSD-*)
            # Not available on all versions:  check for
include file.
            AC_CHECK_HEADER(dlfcn.h, [
                # NetBSD/SPARC needs -fPIC, -fpic will not
do.
@@ -876,6 +876,22 @@
                LD_SEARCH_FLAGS='-L${LIB_RUNTIME_DIR}'
               
SHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}\$\{DBGX\}.a'
            ])
+
+           # FreeBSD doesn't handle version numbers with
dots.
+
+          
UNSHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}\$\{DBGX\}.a'
+           TCL_LIB_VERSIONS_OK=nodots
+           ;;
+       FreeBSD-[[1-2]].*)
+           SHLIB_CFLAGS=""
+           SHLIB_LD="echo tclLdAout $CC \{$SHLIB_CFLAGS\} |
`pwd`/tclsh -r"
+           SHLIB_LD_LIBS='${LIBS}'
+           SHLIB_SUFFIX=".a"
+           DL_OBJS="tclLoadAout.o"
+           DL_LIBS=""
+           LDFLAGS=""
+           LD_SEARCH_FLAGS='-L${LIB_RUNTIME_DIR}'
+           SHARED_LIB_SUFFIX='${TCL_TRIM_DOTS}\$\{DBGX\}.a'
 
            # FreeBSD doesn't handle version numbers with
dots.
andreas_kupries Ticket [443170ffff]: 1 change [History diff]2001-08-01 04:20:24
lloydlimplain2001-08-28 06:08:28
Logged In: YES 
user_id=99220

I've just discovered that both of these patches have
problems.

As noted, the first patch works for dynamic linking but
doesn't work for static linking.  The second patch works for
static linking but doesn't fully work for dynamic linking.

I need to work together with an experienced FreeBSD person
to resolve the problems.  Please contact me directly if you
can help.  (I will be out of the country from Sep 1-23,
2001.)
mdejongplain2002-02-13 12:22:04
Logged In: YES 
user_id=90858

Assigning to acacio to see if he can have a stab
at this FreeBSD issue.
dgpplain2003-10-03 06:16:19
Logged In: YES 
user_id=80530

Is this still valid?
hobbs Closed ticket [443170ffff]. [History diff]2005-05-31 09:16:12
Log in (anonymous is fine) to add a comment.