I'm using automake to build my project. I have some third-party (open source) libraries as git submodules in my project that I want to individually build and link. Here's an edited (names changed) version of my Makefile.am:
lib_LTLIBRARIES = libfoo.la libbar.la
libbar_la_SOURCES = ../submodules/bar/bar.c
libfoo_la_LIBADD = libbar.la
libfoo_la_SOURCES = \
some_source.c \
some_other_source.c
libfoo_la_CFLAGS = $(CFLAGS)
libfoo_la_LDFLAGS = $(LIBS)
if OS_LINUX
libfoo_la_SOURCES += \
linux/some_source.c \
linux/some_other_source.c
libfoo_la_CFLAGS += $(PTHREAD_CFLAGS)
libfoo_la_LDFLAGS += $(PTHREAD_LIBS)
endif
if OS_WINDOWS_MSYS
libfoo_la_SOURCES += \
nt/some_source.c \
nt/some_other_source.c
libfoo_la_LDFLAGS += -no-undefined
endif
bin_PROGRAMS = main
main_SOURCES = main.c
main_LDADD = libfoo.la
autoreconf, configure and make run normally but make install fails with
/usr/bin/ld: cannot find -lbar
collect2: error: ld returned 1 exit status
It seems autoconf is trying to use libbar as a global, installed library instead of a local one? LDADD on the main target works fine though.
autoreconf -V outputs
autoreconf (GNU Autoconf) 2.71
Copyright (C) 2021 Free Software Foundation, Inc.
License GPLv3+/Autoconf: GNU GPL version 3 or later
<https://gnu.org/licenses/gpl.html>, <https://gnu.org/licenses/exceptions.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by David J. MacKenzie and Akim Demaille.
EDIT: I am on Linux. Don't mind the windows parts.
I tried to reproduce this on https://github.com/ndim/stackoverflow-q70584133 by basically copying the Makefile.am you have given and adding a few very basic source files.
I found that building on Linux for Linux (Fedora 35, autoconf 2.69-37, automake 1.16.2-5, libtool 2.4.6-42) worked fine. Also running the make installed result:
[user#host stackoverflow-q70584133]$ mkdir _b-host && cd _b-host
[user#host _b-host]$ ../configure --prefix=$PWD/_i
[user#host _b-host]$ make && make install && ./_i/bin/main
[...]
main: x86_64-pc-linux-gnu
foo_func
bar_func
foo_host_func: Linux 331524 = 0x50f04 = 5.15.4 (5.15.4)
[user#host _b-host]$ _
So if you have problems building on and for Linux, something else must be off.
I presume you have run make distclean and then re-run autoreconf and configure to make sure your buildsystem and source tree and build tree are in a well defined state.
However, building on Fedora 35 for Windows (both 32 and 64bit) failed for me when building libbar.la without -no-undefined:
/bin/sh ../libtool --tag=CC --mode=link i686-w64-mingw32-gcc -g -O2 -o libbar.la -rpath /home/user/stackoverflow-q70584133/_b-w32/_i/lib ../bar/libbar_la-bar.lo
libtool: warning: undefined symbols not allowed in i686-w64-mingw32 shared libraries; building static only
libtool: link: i686-w64-mingw32-ar cru .libs/libbar.a ../bar/libbar_la-bar.o
libtool: link: i686-w64-mingw32-ranlib .libs/libbar.a
libtool: link: ( cd ".libs" && rm -f "libbar.la" && ln -s "../libbar.la" "libbar.la" )
/bin/sh ../libtool --tag=CC --mode=link i686-w64-mingw32-gcc -g -O2 -no-undefined -o libfoo.la -rpath /home/user/stackoverflow-q70584133/_b-w32/_i/lib foo/libfoo_la-foo.lo foo/libfoo_la-foo-nt.lo libbar.la
*** Warning: This system cannot link to static lib archive libbar.la.
*** I have the capability to make that library automatically link in when
*** you link to this library. But I can only do this if you have a
*** shared version of the library, which you do not appear to have.
libtool: link: i686-w64-mingw32-gcc -shared foo/.libs/libfoo_la-foo.o foo/.libs/libfoo_la-foo-nt.o -g -O2 -o .libs/libfoo-0.dll -Wl,--enable-auto-image-base -Xlinker --out-implib -Xlinker .libs/libfoo.dll.a
/usr/lib/gcc/i686-w64-mingw32/11.2.1/../../../../i686-w64-mingw32/bin/ld: foo/.libs/libfoo_la-foo.o: in function `foo_func':
/home/user/stackoverflow-q70584133/_b-w32/src/../../src/foo/foo.c:10: undefined reference to `bar_func'
collect2: error: ld returned 1 exit status
make[1]: *** [Makefile:521: libfoo.la] Error 1
Adding a line to Makefile.am like
libbar_la_LDFLAGS += -no-undefined
fixed the linking for Windows problem and made the whole thing build and run (built on Linux, run on Linux using wine):
[user#host stackoverflow-q70584133]$ mkdir _b-w64 && cd _b-w64
[user#host _b-w64]$ ../configure --host=x86_64-w64-mingw32 --prefix=$PWD/_i
[user#host _b-w64]$ make && make install && ./_i/bin/main.exe
[...]
main: x86_64-w64-mingw32
foo_func
bar_func
foo_host_func: Windows 0x0a00 = 10.0
[user#host _b-w64]$ _
(And BTW, LIBS and _LIBS type variables should probably be added to a _LIBADD or _LDADD variable, not to a _LDFLAGS variable.)
UPDATE
Building on Debian 10 (autoconf 2.69-11, automake 1:1.16.1-4, libtool 2.4.6-9), does produce a linker error when main_LDADD is missing libbar.la and src/main.c calls the bar_func() function from libbar (uncomment the #define in src/main.c to reproduce):
[user#host _b-host]$ make
[...]
/bin/bash ../libtool --tag=CC --mode=link gcc -g -O2 -o main main-main.o libfoo.la
libtool: link: gcc -g -O2 -o .libs/main main-main.o ./.libs/libfoo.so -pthread -Wl,-rpath -Wl,/home/user/stackoverflow-q70584133/_b-host/_i/lib
/usr/bin/ld: main-main.o: undefined reference to symbol 'bar_func'
/usr/bin/ld: //home/user/stackoverflow-q70584133/_b-host/src/.libs/libbar.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make[1]: *** [Makefile:525: main] Error 1
make[1]: Leaving directory '/home/user/stackoverflow-q70584133/_b-host/src'
make: *** [Makefile:390: all-recursive] Error 1
[user#host _b-host]$ _
However, after removing the direct calls to libbar's bar_func() from src/main.c, the make command will work again, as does make install:
[user#host _b-host]$ make install && ./_i/bin/main
main: x86_64-pc-linux-gnu
foo_func
bar_func
foo_host_func: Linux 267216 = 0x413d0 = 4.19.208
[user#host _b-host]$ _
This suggests that calling a function from libbar from a linking unit without explicitly linking that unit against libbar is an error, and that does make sense.
So I still cannot reproduce OP's report of make working but make install failing. OP is using newer autoconf (2.71) than I do (2.69). Perhaps OP is using different automake/libtool versions as well with different set of bugs (dpkg -l autoconf automake libtool, rpm -q autoconf automake libtool, etc.)?
Related
I'm working on a Linux project in C consisting of two different open source applications. "Project A" (libduo) creates an archive used for linking a couple test programs and creates the library like this:
/usr/bin/ar rv libduo.a duo.o http_parser.o https.o match.o parson.o urlenc.o
/usr/bin/ar: creating libduo.a
a - duo.o
a - http_parser.o
a - https.o
a - match.o
a - parson.o
a - urlenc.o
ranlib libduo.a
One of the libduo test programs is built like this:
gcc -g -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -I. -I. -DDUODIR=\"/usr/local/duo/libduo/etc\" -DHAVE_CONFIG_H -c test-duologin.c
gcc -o test-duologin test-duologin.o -L. -lduo -lssl -lcrypto
"Project B" is an OpenLDAP module which I've built with -lduo and a few options to tell it where to find things:
(cd .libs && rm -f pw-apr1.la && ln -s ../pw-apr1.la pw-apr1.la)
../../../libtool --mode=compile gcc -g -O2 -Wall -I../../../include -I../../../include -I../../../servers/slapd -I../../../contrib/slapd-modules/passwd/libduo -c pw-duo.c
gcc -g -O2 -Wall -I../../../include -I../../../include -I../../../servers/slapd -I../../../contrib/slapd-modules/passwd/libduo -c pw-duo.c -fPIC -DPIC -o .libs/pw-duo.o
gcc -g -O2 -Wall -I../../../include -I../../../include -I../../../servers/slapd -I../../../contrib/slapd-modules/passwd/libduo -c pw-duo.c -o pw-duo.o >/dev/null 2>&1
../../../libtool --mode=link gcc -g -O2 -Wall -version-info 0:0:0 \
-rpath /usr/local/libexec/openldap -module -o pw-duo.la pw-duo.lo libduo.a -lduo
*** Warning: Linking the shared library pw-duo.la against the
*** static library libduo.a is not portable!
cc -shared .libs/pw-duo.o libduo.a -lduo -Wl,-soname -Wl,pw-duo.so.0 -o .libs/pw-duo.so.0.0.0
/usr/bin/ld: libduo.a(duo.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
libduo.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
Makefile:51: recipe for target 'pw-duo.la' failed
make: *** [pw-duo.la] Error 1
The Makefile I'm using is the same one distributed with the OpenLDAP project. I've just added a section in the Makefile to build my module, using the same options for the other modules already there but adding -lduo to my section along with the paths to the libduo includes and libduo.a.
As make suggests above, I've recompiled by adding -fPIC after the -Wall option but it the same error was repeated. As a last resort, I tried adding -static to the module build but make was having none of that either:
*** Warning: Linking the shared library pw-duo.la against the
*** static library libduo.a is not portable!
This is the first time I've tried to build a C application against a lib not in the standard Linux locations so not exactly sure what's going on. I suspect libduo is built intended to be statically linked into everything, but the OpenLDAP modules are designed to use shared libraries. Can anyone elucidate?
Update: with help of comments below and this link I created a shared library from the .o files and distributed/built against that.
I am not an experienced programmer/developer/software engineer, but I need to get this older version of guile-2.0.11 built "by hand" rather than using home-brew (which installs the latest version of guile). I downloaded the tarball for guile-2.0.11 from the GitHub repository, extracted it and ran the shell script autogen.sh. This produced a configure executable which ran to completion and generated a Makefile. When I run make, the build continues until I get the this error:
Undefined symbols for architecture x86_64:
"_clock_getcpuclockid", referenced from:
_scm_init_stime in libguile_2.0_la-stime.o
"_ffi_call", referenced from:
_scm_i_foreign_call in libguile_2.0_la-foreign.o
and 16 more "ffi" similar messages. Then the error messages finishes
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[3]: *** [libguile-2.0.la] Error 1
make[2]: *** [all] Error 2
make[1]: *** [all-recursive] Error 1
The linker apparently can't find these symbols. The explicit link command is quite extensive..it shows all the options, include and library paths if I use "make V=1". Here is the beginning, showing the options and paths:
Applications/Xcode.app/Contents/Developer/usr/bin/make all-am
/bin/sh ../libtool --tag=CC --mode=link gcc - I/usr/local/opt/gettext/include -I/usr/local/include - I/usr/local/opt/readline/include - I/usr/local/Cellar/gettext/0.19.8.1/include -D_THREAD_SAFE -Wall - Wmissing-prototypes -Wdeclaration-after-statement -Wpointer-arith -Wswitch- enum -fno-strict-aliasing -fwrapv -fvisibility=hidden - I/usr/local/Cellar/bdw-gc/7.6.0/include -g -O2 -L/usr/local/Cellar/bdw- gc/7.6.0/lib -lgc -L/usr/local/opt/libffi/lib -liconv - L/usr/local/opt/gettext/lib -lintl -R/usr/local/opt/gettext/lib -Wl,- framework -Wl,CoreFoundation -L/usr/local/lib -lunistring -R/usr/local/lib -version-info 29:2:7 -export-dynamic -no-undefined -L/usr/local/opt/gettext/lib -L/usr/local/lib -L/usr/local/opt/readline/lib -L/usr/local/Cellar/gettext/0.19.8.1/lib -o libguile-2.0.la -rpath /usr/local/lib
Then there is libtool.
libtool: link: gcc -dynamiclib -o .libs/libguile-2.0.22.dylib .libs/libguile_2.0_la-alist.o .libs/libguile_2.0_la-arbiters.o .libs/libguile_2.0_la-array-handle.o
and many many more xxxx.o
then
-Wl,-force_load,../lib/.libs/libgnu.a -L/usr/local/Cellar/bdw- gc/7.6.0/lib -lgc -L/usr/local/opt/libffi/lib -L/usr/local/opt/gettext/lib -L/usr/local/lib -L/usr/local/opt/readline/lib - L/usr/local/Cellar/gettext/0.19.8.1/lib -lintl -lunistring -liconv -lgmp - lltdl -lm -g -O2 -Wl,-framework -Wl,CoreFoundation -install_name /usr/local/lib/libguile-2.0.22.dylib -compatibility_version 30 - current_version 30.2 -Wl,-single_module
The up-to-date version of ffilib is in the symlink /usr/local/opt/libffi/lib which is in the ld path, so I would think that the linker could find it. Any help would be greatly appreciated.
This problem is really two problems: (1) the undefined symbol "_clock_getcpuclockid" and (2) all the "ffi" undefined symbols. The answer to the second problem is here and the answer to the first problem is here. There may be other solutions but these resulted in the installation of guile-2.0.11 on my macOS Sierra (10.12.5),
I am having trouble linking to the libpng library.
The build seems unable to define references to Libpng calls.
I think the problem is in my Libpng install.
I am runing in the Mingw environment on a Win7 laptop
My build environment is as follows:
My path starts with C:\MinGW\bin;C:\MinGW\msys\1.0\bin;C:\MinGW\git\cmd;C:\Program Files
C:\Users\Bob\Home\png23d>g++ --version
g++ (GCC) 5.3.0
I have built and installed libpng-1.6.28 which creates the following:
C:\MinGW\bin>
libpng-config
libpng16-config
libpng16.dll
C:\MinGW\include\libpng
png.h
pngconf.h
pnglibconf.h
C:\MinGW\include\libpng16
png.h
pngconf.h
pnglibconf.h
C:\MinGW\lib\pkgconfig
C:\MinGW\lib>
libpng.a
libpng.dll.a
libpng16.a
libpng16.dll.a
a symbolic link `libpng' to `libpng16'
a symbolic link `libpng.pc' to `libpng16.pc'
a symbolic link `libpng.a' to `libpng16.a'
a symbolic link `libpng-config' to `libpng16-config
when I try to build a program "png23d" I get the following
C:\Users\Bob\Home\png23d>make
g++ -DUSE_LIBPNG -lpng png23d.o option.o bitmap.o mesh.o mesh_gen.o mesh_index.o mesh_simplify.o out_pgm.o out_rscad.o out_pscad.o out_stl.o -o png23d
bitmap.o:bitmap.c:(.text+0x102): undefined reference to `png_sig_cmp'
bitmap.o:bitmap.c:(.text+0x142): undefined reference to `png_create_read_struct'
.
.
.
bitmap.o:bitmap.c:(.text+0x418): undefined reference to `png_read_end'
bitmap.o:bitmap.c:(.text+0x466): undefined reference to `png_destroy_read_struct'
collect2.exe: error: ld returned 1 exit status
<builtin>: recipe for target 'png23d' failed
make: *** [png23d] Error 1
I am almost sure its the -lpng that is not working.... I am just don't know how to fix it.
I am guessing that it is a symbolic link problem and I know I did not create one during the libpng build.
If I am right what do I need to link it to.
I tried changing -lpng to -llpng16. It made no difference.
Thanks from the command prompt that work fine.
just have to figure out how to change the make file.
#!/usr/bin/make
#
# png23d is a program to convert png images into 3d files
#
# Copyright 2011 Vincent Sanders <vince#kyllikki.org>
#
# Released under the MIT License,
# http://www.opensource.org/licenses/mit-license.php
CC = g++
VERSION=100
PREFIX =
WARNFLAGS = -W -Wall -Wundef -Wpointer-arith \
-Wcast-align -Wwrite-strings -Wstrict-prototypes \
-Wmissing-prototypes -Wmissing-declarations -Wredundant-decls \
-Wnested-externs
ifneq ($(GCCVER),2)
WARNFLAGS += -Wno-unused-parameter
endif
OPTFLAGS=-O2
#OPTFLAGS=-O0
CFLAGS+=$(WARNFLAGS) -MMD -DVERSION=$(VERSION) $(OPTFLAGS) -g
LDFLAGS+= -DUSE_LIBPNG -lpng
PNG23D_OBJ=png23d.o option.o bitmap.o mesh.o mesh_gen.o mesh_index.o mesh_simplify.o out_pgm.o out_rscad.o out_pscad.o out_stl.o
.PHONY : all clean
all:png23d
png23d:$(PNG23D_OBJ)
-include $(PNG23D_OBJ:.o=.d)
-include test/Makefile.sub
clean: testclean
${RM} png23d $(PNG23D_OBJ) *.d *~ png23d.png
install:png23d
install -D png23d $(DESTDIR)$(PREFIX)/bin
install-man:png23d.1
install -D png23d.1 $(DESTDIR)$(PREFIX)/share/man/man1
# logo creation
png23d.png:png23d.pov
povray +L/usr/share/povray/include/ -D +Q11 +O$# +UV +UL +A0.2 +FP8 +W400 +H300 $<
Move -lpng to after the object files.
I was trying to build eglibc-2.19 on Ubuntu 14.04 LTS which I downloaded through
apt-get source libc6
I followed the INSTALL instructions but got this error when it ran into nptl
gcc sem_init.c -c -std=gnu99 -fgnu89-inline -fno-stack-protector -O2 -Wall -Winline -Wwrite-strings -fmerge-all-constants -frounding-math -g -Wstrict-prototypes -U_FORTIFY_SOURCE -I../include -I/home/gpanda/wksp/glibc/tmp2/glibc-build/nptl -I/home/gpanda/wksp/glibc/tmp2/glibc-build -I../sysdeps/unix/sysv/linux/x86_64/64/nptl -I../sysdeps/unix/sysv/linux/x86_64/64 -I../nptl/sysdeps/unix/sysv/linux/x86_64 -I../nptl/sysdeps/unix/sysv/linux/x86 -I../sysdeps/unix/sysv/linux/x86 -I../sysdeps/unix/sysv/linux/x86_64 -I../sysdeps/unix/sysv/linux/wordsize-64 -I../nptl/sysdeps/unix/sysv/linux -I../nptl/sysdeps/pthread -I../libpthread/sysdeps/pthread -I../sysdeps/pthread -I../ports/sysdeps/unix/sysv/linux -I../sysdeps/unix/sysv/linux -I../sysdeps/gnu -I../sysdeps/unix/inet -I../nptl/sysdeps/unix/sysv -I../ports/sysdeps/unix/sysv -I../sysdeps/unix/sysv -I../sysdeps/unix/x86_64 -I../nptl/sysdeps/unix -I../ports/sysdeps/unix -I../sysdeps/unix -I../sysdeps/posix -I../libpthread/sysdeps/posix -I../nptl/sysdeps/x86_64/64 -I../sysdeps/x86_64/64 -I../sysdeps/x86_64/fpu/multiarch -I../sysdeps/x86_64/fpu -I../sysdeps/x86/fpu -I../sysdeps/x86_64/multiarch -I../nptl/sysdeps/x86_64 -I../sysdeps/x86_64 -I../sysdeps/x86 -I../sysdeps/ieee754/ldbl-96 -I../sysdeps/ieee754/dbl-64/wordsize-64 -I../sysdeps/ieee754/dbl-64 -I../sysdeps/ieee754/flt-32 -I../sysdeps/wordsize-64 -I../sysdeps/ieee754 -I../sysdeps/generic -I../libpthread/include -I../libpthread -I../nptl -I../ports -I.. -I../libio -I. -I../libpthread/include -D_LIBC_REENTRANT -include ../include/libc-symbols.h -DNOT_IN_libc=1 -DIS_IN_libpthread=1 -DIN_LIB=libpthread -o /home/gpanda/wksp/glibc/tmp2/glibc-build/nptl/sem_init.o -MD -MP -MF /home/gpanda/wksp/glibc/tmp2/glibc-build/nptl/sem_init.o.dt -MT /home/gpanda/wksp/glibc/tmp2/glibc-build/nptl/sem_init.o
In file included from sem_init.c:20:0:
../libpthread/include/semaphore.h:28:0: warning: "SEM_FAILED" redefined [enabled by default]
#define SEM_FAILED ((void *) 0)
^
In file included from ../libpthread/include/semaphore.h:26:0,
from sem_init.c:20:
../nptl/sysdeps/unix/sysv/linux/x86/bits/semaphore.h:33:0: note: this is the location of the previous definition
#define SEM_FAILED ((sem_t *) 0)
^
In file included from sem_init.c:20:0:
../libpthread/include/semaphore.h:30:28: error: conflicting types for ‘sem_t’
typedef struct __semaphore sem_t;
^
In file included from ../libpthread/include/semaphore.h:26:0,
from sem_init.c:20:
../nptl/sysdeps/unix/sysv/linux/x86/bits/semaphore.h:40:3: note: previous declaration of ‘sem_t’ was here
} sem_t;
^
make[2]: *** [/home/gpanda/wksp/glibc/tmp2/glibc-build/nptl/sem_init.o] Error 1
make[2]: Leaving directory `/home/gpanda/wksp/glibc/tmp2/eglibc-2.19/nptl'
make[1]: *** [nptl/subdir_lib] Error 2
make[1]: Leaving directory `/home/gpanda/wksp/glibc/tmp2/eglibc-2.19'
make: *** [all] Error 2
Is this some kind of conflict between libpthread and nptl? How to fix this problem?
Thanks in advance.
Consider LinuxThreads has been superseded by NPTL, so I just removed the add-on libpthread from the eglibc directory, and re-did the configure and make, then everything seems to be ok now.
see LinuxThreads,NPTL
BTW, since I didn't use the standard /usr path as the "--prefix=" option for configure, so I need copy libstdc++.so.6 and libgcc_s.so.1 to my current build path to get "make check" pass.
see glibc Known_testsuite_failures
I got the same error because I ran a plain ./configure --prefix=/opt, so I ran apt-get source -b eglibc instead and I noted the configure flags it used:
(exec 3>&1; exit `( ( ( cd build-tree/i386-libc && CC="i686-linux-gnu-gcc-4.8" CXX="i686-linux-gnu-g++-4.8" AUTOCONF=false MAKEINFO=: /home/sashoalm/Workspace/apt-get-source/libc/eglibc-2.19/configure --host=i686-linux-gnu --build=$configure_build --prefix=/usr --without-cvs --enable-add-ons=libidn,"nptl " --enable-profile --without-selinux --enable-stackguard-randomization --enable-obsolete-rpc --with-pkgversion="Ubuntu EGLIBC 2.19-0ubuntu6.9" --with-bugurl="https://bugs.launchpad.net/ubuntu/+source/eglibc/+bugs" --with-headers=/home/sashoalm/Workspace/apt-get-source/libc/eglibc-2.19/debian/include --enable-kernel=2.6.24 --with-selinux --enable-multi-arch ) 2>&1 3>&-; echo $? >&4) | tee -a build-tree/log-build-i686-linux-gnu-libc >&3) 4>&1`)
The command is rather involved, more complex than usual for apt-get source, since glibc insists on being built from a separate directory. The actual configure flags are:
--host=i686-linux-gnu --build=$configure_build --prefix=/usr --without-cvs --enable-add-ons=libidn,"nptl " --enable-profile --without-selinux --enable-stackguard-randomization --enable-obsolete-rpc --with-pkgversion="Ubuntu EGLIBC 2.19-0ubuntu6.9" --with-bugurl="https://bugs.launchpad.net/ubuntu/+source/eglibc/+bugs" --with-headers=/home/sashoalm/Workspace/apt-get-source/libc/eglibc-2.19/debian/include --enable-kernel=2.6.24 --with-selinux --enable-multi-arch
It works with those arguments of course, since that's what Ubuntu maintainers used to compile the package with.
I don't really know which of those flags prevents the error, but if you use that command, or the exact arguments provided by apt-get source -b eglibc on your Ubuntu system, it should work well enough.
I have been trying to compile xalan-c specifically 1.11 with xerces 3.1.1. with an arm cross-compile toolchain 4.3.3 from CodeSourcery on a ubuntu 14.x 64.
xalan-c has two configure scripts. First the usual ./configure and second ./runConfigure.
Up until now I have been cross-compiling other libs (e.g. libusb-1.0/libusb-0.1/openssl) with
--host../configure --host=arm-none-linux-gnueabi --prefix="/home/user/sysroot-arm-sf/usr/local/"
This time however I believe I need to use ./runConfigure otherwise some environment variables are not set (e.g. how it deals with messages)
I use:
./runConfigure -p linux -x arm-none-linux-gnueabi-g++ -c arm-none-linux-gnueabi-gcc -P "/home/user/sysroot-arm-sf/usr/local/" -C--host=arm-none-linux-gnueabi
instead which I believe to be the equivalent to ./configure . the ./runConfigure is using all default values (except for the c and c++ compiler which it does not recognize, unfortunately)
Generating makefiles with the following options ...
Platform: linux
C Compiler: arm-none-linux-gnueabi-gcc
C++ Compiler: arm-none-linux-gnueabi-g++
Extra compile options:
Extra link options:
Transcoder: default
Localization system: inmem
Locale: en_US
Thread option: pthread
bitsToBuild option: 32
Extra configure options: --prefix=/home/user/sysroot-arm-sf/usr/local/ --host=arm-none-linux-gnueabi
Debug is OFF
I do not recognize the C compiler 'arm-none-linux-gnueabi-gcc'. Continuing anyway ...
I do not recognize the C++ compiler 'arm-none-linux-gnueabi-g++'. Continuing anyway ...
configure: WARNING: If you wanted to set the --build type, don't use --host.
If a cross compiler is detected then cross compile mode will be used.
checking for arm-none-linux-gnueabi-gcc... arm-none-linux-gnueabi-gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... yes
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether arm-none-linux-gnueabi-gcc accepts -g... yes
checking for arm-none-linux-gnueabi-gcc option to accept ANSI C... none needed
checking for arm-none-linux-gnueabi-g++... arm-none-linux-gnueabi-g++
checking whether we are using the GNU C++ compiler... yes
checking whether arm-none-linux-gnueabi-g++ accepts -g... yes
checking for a BSD-compatible install... /usr/bin/install -c
checking for autoconf... autoconf
checking build system type... x86_64-unknown-linux-gnu
checking host system type... arm-none-linux-gnueabi
checking for floor in -lm... yes
checking how to run the C++ preprocessor... arm-none-linux-gnueabi-g++ -E
checking for egrep... grep -E
checking for ANSI C header files... yes
checking for mbstowcs... yes
checking if mbstowcs can count only... cross-compiling default
configure: creating ./config.status
config.status: creating Makefile.incl
config.status: creating Makefile
config.status: creating src/xalanc/Makefile
config.status: creating src/xalanc/Utils/Makefile
config.status: creating src/xalanc/Utils/MsgCreator/Makefile
config.status: creating src/xalanc/Utils/XalanMsgLib/Makefile
config.status: creating samples/Makefile
config.status: creating Tests/Makefile
If the result of the above commands look OK to you, go to the directory
/home/user/xalan-c-1.11/c/ and type "gmake" or "make" to make the XALAN-C system.
Note: You must use GNU make to use the Xalan Makefile.
Then I'll try
make
make -C src/xalanc all
make[1]: Entering directory `/home/user/xalan-c-1.11/c/src/xalanc'
Preparing the directory structure for a build ...
mkdir -p ../../obj
mkdir -p ../../lib
mkdir -p ../../bin
make -C Utils prepare
make[2]: Entering directory `/home/user/xalan-c-1.11/c/src/xalanc/Utils'
mkdir -p ../../../nls
mkdir -p ../../../nls/include
make[2]: Leaving directory `/home/user/xalan-c-1.11/c/src/xalanc/Utils'
make -C Utils locale
make[2]: Entering directory `/home/user/xalan-c-1.11/c/src/xalanc/Utils'
make -C MsgCreator
make[3]: Entering directory `/home/user/xalan-c-1.11/c/src/xalanc/Utils/MsgCreator'
arm-none-linux-gnueabi-g++ -O3 -DNDEBUG -pthread -D_REENTRANT -Wall -fPIC -DLINUX -D_REENTRANT -DXALAN_INMEM_MSG_LOADER -c -I/home/user/xalan-c-1.11/c//src -I/home/user/xalan-c-1.11/c//include -I../../../../nls/include -I/home/user/xerces-c-3.1.1//src/ -I/home/user/xerces-c-3.1.1//include/xercesc -I/home/user/xerces-c-3.1.1//include/ -o ../../../../obj/MsgFileOutputStream.o /home/user/xalan-c-1.11/c//src/xalanc/Utils/MsgCreator/MsgFileOutputStream.cpp
arm-none-linux-gnueabi-g++ -O3 -DNDEBUG -pthread -D_REENTRANT -Wall -fPIC -DLINUX -D_REENTRANT -DXALAN_INMEM_MSG_LOADER -c -I/home/user/xalan-c-1.11/c//src -I/home/user/xalan-c-1.11/c//include -I../../../../nls/include -I/home/user/xerces-c-3.1.1//src/ -I/home/user/xerces-c-3.1.1//include/xercesc -I/home/user/xerces-c-3.1.1//include/ -o ../../../../obj/ICUResHandler.o /home/user/xalan-c-1.11/c//src/xalanc/Utils/MsgCreator/ICUResHandler.cpp
arm-none-linux-gnueabi-g++ -O3 -DNDEBUG -pthread -D_REENTRANT -Wall -fPIC -DLINUX -D_REENTRANT -DXALAN_INMEM_MSG_LOADER -c -I/home/user/xalan-c-1.11/c//src -I/home/user/xalan-c-1.11/c//include -I../../../../nls/include -I/home/user/xerces-c-3.1.1//src/ -I/home/user/xerces-c-3.1.1//include/xercesc -I/home/user/xerces-c-3.1.1//include/ -o ../../../../obj/InMemHandler.o /home/user/xalan-c-1.11/c//src/xalanc/Utils/MsgCreator/InMemHandler.cpp
arm-none-linux-gnueabi-g++ -O3 -DNDEBUG -pthread -D_REENTRANT -Wall -fPIC -DLINUX -D_REENTRANT -DXALAN_INMEM_MSG_LOADER -c -I/home/user/xalan-c-1.11/c//src -I/home/user/xalan-c-1.11/c//include -I../../../../nls/include -I/home/user/xerces-c-3.1.1//src/ -I/home/user/xerces-c-3.1.1//include/xercesc -I/home/user/xerces-c-3.1.1//include/ -o ../../../../obj/MsgCreator.o /home/user/xalan-c-1.11/c//src/xalanc/Utils/MsgCreator/MsgCreator.cpp
arm-none-linux-gnueabi-g++ -O3 -DNDEBUG -pthread -D_REENTRANT -Wall -fPIC -DLINUX -D_REENTRANT -DXALAN_INMEM_MSG_LOADER -c -I/home/user/xalan-c-1.11/c//src -I/home/user/xalan-c-1.11/c//include -I../../../../nls/include -I/home/user/xerces-c-3.1.1//src/ -I/home/user/xerces-c-3.1.1//include/xercesc -I/home/user/xerces-c-3.1.1//include/ -o ../../../../obj/NLSHandler.o /home/user/xalan-c-1.11/c//src/xalanc/Utils/MsgCreator/NLSHandler.cpp
arm-none-linux-gnueabi-g++ -O3 -DNDEBUG -pthread -D_REENTRANT -Wall -fPIC -DLINUX -D_REENTRANT -DXALAN_INMEM_MSG_LOADER -c -I/home/user/xalan-c-1.11/c//src -I/home/user/xalan-c-1.11/c//include -I../../../../nls/include -I/home/user/xerces-c-3.1.1//src/ -I/home/user/xerces-c-3.1.1//include/xercesc -I/home/user/xerces-c-3.1.1//include/ -o ../../../../obj/SAX2Handler.o /home/user/xalan-c-1.11/c//src/xalanc/Utils/MsgCreator/SAX2Handler.cpp
arm-none-linux-gnueabi-g++ -DLINUX -fPIC -pthread -D_REENTRANT -DXALAN_INMEM_MSG_LOADER \
-lm -lpthread ../../../../obj/MsgFileOutputStream.o ../../../../obj/ICUResHandler.o ../../../../obj/InMemHandler.o ../../../../obj/MsgCreator.o ../../../../obj/NLSHandler.o ../../../../obj/SAX2Handler.o -o ../../../../bin/MsgCreator -L/home/user/xerces-c-3.1.1//lib -lxerces-c
make[3]: Leaving directory `/home/user/xalan-c-1.11/c/src/xalanc/Utils/MsgCreator'
../../../bin/MsgCreator /home/user/xalan-c-1.11/c//src/xalanc/NLS/en_US/XalanMsg_en_US.xlf -TYPE inmem -LOCALE en_US
../../../bin/MsgCreator: ../../../bin/MsgCreator: cannot execute binary file
make[2]: *** [../../../nls/include/LocalMsgData.hpp] Error 126
make[2]: Leaving directory `/home/user/xalan-c-1.11/c/src/xalanc/Utils'
make[1]: *** [locale] Error 2
make[1]: Leaving directory `/home/user/xalan-c-1.11/c/src/xalanc'
make: *** [all] Error 2
and it will fail executing
../../../bin/MsgCreator /home/user/xalan-c-1.11/c//src/xalanc/NLS/en_US/XalanMsg_en_US.xlf -TYPE inmem -LOCALE en_US
which is
bin/MsgCreator: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.14, not stripped
a binary for an Arm arch. I though ./runConfigure had used the --host option and was aware this was a cross build. Or maybe this is something xalan-c specific?
It does say
checking whether we are cross compiling... yes
So this looks like a poorly tested makefile, to me.
You could try to debug it, or you could just install qemu so that ARM binaries magically Just Work (assuming they can find their libraries).
I tried the following workaround which apparently worked.
The files in the xalanc bin/ Folder seem to be only used at compile time (at least I guessed so). Xalan generates headerfiles etc. in order to compile the libxalanMsg.so .
It was a long shot but I simply precompile those bin/ files for Ubuntu x86 and copied those files into my cross compile bin folder.
done. (at least for now)
This problem is really tough and weird. Fortunately, I find a way to resolve this problem.
From the error, we can conclude that the build process uses an executable tool named 'MsgCreator'.
Where is it from?
Actually, this tool is an intermediate product of the build process. Xalan generate it and use this tool to do something he wants.
What happens?
You may remember that you are now cross-compiling Xalan, so the target executable platform of MsgCreator may not support your build platform. This case will cause the error you see.
How to solve this problem
Use the local compiler to build a local MsgCreator which means this tool can run on your build platform.
Update the code in …./xalan-c-1.11/c/src/xalanc/Utils/MsgCreator/Malefile.in.
$(XSL_BIN_DIR)/MsgCreator -> $(XSL_BIN_TMP_DIR)/MsgCreator
Export XSL_BIN_TMP_DIR to your local MsgCreator tool path.
export LD_LIBRARY_PATH to add MsgCreator dependency libraries. These libraries can be generated by compiling Xerces-C (the version must greater than 3.0) with your local compiler.
Cross compile Xalan, everything will go well.