tpoechtrager / cctools-port

Apple cctools port for Linux and *BSD

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

build error on OSX

CBSears opened this issue · comments

I'm trying a simple build on OSX because I need to hack on ld.
I'm using OSX 10.14.2 with Apple LLVM version 10.0.0 (clang-1000.11.45.5)
Basically, latest and greatest.

git clone https://github.com/tpoechtrager/cctools-port.git
cd cctools-port/cctools
./configure --target=x86_64
make

grind grind grind

...
/bin/sh ../libtool --tag=CC --mode=link clang -D__DARWIN_UNIX03 -I../include -I../include/foreign -I../libstuff -Wall -Wno-long-long -Wno-import -Wno-format -Wno-deprecated -Wno-unused-variable -Wno-unused-private-field -Wno-unused-function -Wno-invalid-offsetof -Wno-int-conversion -Wno-char-subscripts -Wno-shift-negative-value -D__LITTLE_ENDIAN__=1 -O3 -isystem /usr/local/include -isystem /usr/pkg/include -L/usr/local/lib -L/usr/pkg/lib -o ar ar-append.o ar-ar.o ar-archive.o ar-contents.o ar-delete.o ar-extract.o ar-misc.o ar-move.o ar-print.o ar-replace.o ../libstuff/libstuff.la
libtool: link: clang -D__DARWIN_UNIX03 -I../include -I../include/foreign -I../libstuff -Wall -Wno-long-long -Wno-import -Wno-format -Wno-deprecated -Wno-unused-variable -Wno-unused-private-field -Wno-unused-function -Wno-invalid-offsetof -Wno-int-conversion -Wno-char-subscripts -Wno-shift-negative-value -D__LITTLE_ENDIAN__=1 -O3 -isystem /usr/local/include -isystem /usr/pkg/include -o ar ar-append.o ar-ar.o ar-archive.o ar-contents.o ar-delete.o ar-extract.o ar-misc.o ar-move.o ar-print.o ar-replace.o -L/usr/local/lib -L/usr/pkg/lib ../libstuff/.libs/libstuff.a
ld: warning: directory not found for option '-L/usr/pkg/lib'
ld: warning: ignoring file ../libstuff/.libs/libstuff.a, file was built for archive which is not the architecture being linked (x86_64): ../libstuff/.libs/libstuff.a
> Undefined symbols for architecture x86_64:
"_add_execute_list", referenced from:
_main in ar-ar.o
"_add_execute_list_with_prefix", referenced from:
_main in ar-ar.o
"_execute_list", referenced from:
_main in ar-ar.o
"_get_unix_standard_mode", referenced from:
_main in ar-ar.o
"_reset_execute_list", referenced from:
_main in ar-ar.o

ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Any ideas?

Don't build with --target. Not needed. The resulting LD will support all archs.

I tried that first and got: Undefined symbols for architecture x86_64

grind grind grind

/bin/sh ../libtool --tag=CC --mode=link clang -D__DARWIN_UNIX03 -I../include -I../include/foreign -I../libstuff -Wall -Wno-long-long -Wno-import -Wno-format -Wno-deprecated -Wno-unused-variable -Wno-unused-private-field -Wno-unused-function -Wno-invalid-offsetof -Wno-int-conversion -Wno-char-subscripts -Wno-shift-negative-value -D__LITTLE_ENDIAN__=1 -O3 -isystem /usr/local/include -isystem /usr/pkg/include -L/usr/local/lib -L/usr/pkg/lib -o ar ar-append.o ar-ar.o ar-archive.o ar-contents.o ar-delete.o ar-extract.o ar-misc.o ar-move.o ar-print.o ar-replace.o ../libstuff/libstuff.la
libtool: link: clang -D__DARWIN_UNIX03 -I../include -I../include/foreign -I../libstuff -Wall -Wno-long-long -Wno-import -Wno-format -Wno-deprecated -Wno-unused-variable -Wno-unused-private-field -Wno-unused-function -Wno-invalid-offsetof -Wno-int-conversion -Wno-char-subscripts -Wno-shift-negative-value -D__LITTLE_ENDIAN__=1 -O3 -isystem /usr/local/include -isystem /usr/pkg/include -o ar ar-append.o ar-ar.o ar-archive.o ar-contents.o ar-delete.o ar-extract.o ar-misc.o ar-move.o ar-print.o ar-replace.o -L/usr/local/lib -L/usr/pkg/lib ../libstuff/.libs/libstuff.a
ld: warning: directory not found for option '-L/usr/pkg/lib'
ld: warning: ignoring file ../libstuff/.libs/libstuff.a, file was built for archive which is not the architecture being linked (x86_64): ../libstuff/.libs/libstuff.a
Undefined symbols for architecture x86_64:
"_add_execute_list", referenced from:
_main in ar-ar.o
"_add_execute_list_with_prefix", referenced from:
_main in ar-ar.o
"_execute_list", referenced from:
_main in ar-ar.o
"_get_unix_standard_mode", referenced from:
_main in ar-ar.o
"_reset_execute_list", referenced from:
_main in ar-ar.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

That was why I set the target to x86_64.

First, I should emphasize that I'm trying to build this on OSX 10.14.2. Your github main page says Apple cctools port for Linux, *BSD and Windows (Cygwin) which doesn't list OSX but then lists Mac OS X and x86_64 as a supported host. I'm doing this because while the cctools are open sourced from Apple, Apple doesn't really give a build environment.

So I guess the important point is that the build is compiling files (ar/ar-append.c for example) and linking their objects with an archive, ./libstuff/.libs/libstuff.a, and then complaining about a mismatch.

/bin/sh ../libtool --tag=CC --mode=link clang -D__DARWIN_UNIX03 -I../include -I../include/foreign -I../libstuff -Wall -Wno-long-long -Wno-import -Wno-format -Wno-deprecated -Wno-unused-variable -Wno-unused-private-field -Wno-unused-function -Wno-invalid-offsetof -Wno-int-conversion -Wno-char-subscripts -Wno-shift-negative-value -D__LITTLE_ENDIAN__=1 -O3 -isystem /usr/local/include -isystem /usr/pkg/include -L/usr/local/lib -L/usr/pkg/lib -o ar ar-append.o ar-ar.o ar-archive.o ar-contents.o ar-delete.o ar-extract.o ar-misc.o ar-move.o ar-print.o ar-replace.o ../libstuff/libstuff.la
libtool: link: clang -D__DARWIN_UNIX03 -I../include -I../include/foreign -I../libstuff -Wall -Wno-long-long -Wno-import -Wno-format -Wno-deprecated -Wno-unused-variable -Wno-unused-private-field -Wno-unused-function -Wno-invalid-offsetof -Wno-int-conversion -Wno-char-subscripts -Wno-shift-negative-value -D__LITTLE_ENDIAN__=1 -O3 -isystem /usr/local/include -isystem /usr/pkg/include -o ar ar-append.o ar-ar.o ar-archive.o ar-contents.o ar-delete.o ar-extract.o ar-misc.o ar-move.o ar-print.o ar-replace.o -L/usr/local/lib -L/usr/pkg/lib ../libstuff/.libs/libstuff.a
ld: warning: directory not found for option '-L/usr/pkg/lib'
ld: warning: ignoring file ../libstuff/.libs/libstuff.a, file was built for archive which is not the architecture being linked (x86_64): ../libstuff/.libs/libstuff.a
Undefined symbols for architecture x86_64:
"_add_execute_list", referenced from:
_main in ar-ar.o

Looking at libstuff.a with objdump -a ./libstuff/.libs/libstuff.a

In archive ./libstuff/.libs/libstuff.a:

libstuff_la-allocate.o: file format mach-o-x86-64
rw-r--r-- 0/0 2292 Dec 31 16:00 1969 libstuff_la-allocate.o

...

Looking at file ar/ar-append.o:

ar/ar-append.o: Mach-O 64-bit object x86_64

Neither of these helped:

make clean
./configure --target=x86_64-apple-darwin11

make clean
./configure

There is no directory /usr/pkg on my system:

ls /usr/pkg
ls: /usr/pkg: No such file or directory

Searching for the message "file was built for archive which is not the architecture being linked" I saw this:

MoarVM/MoarVM#334 (comment)

When I run configure, it recognizes darwin and selects clang as the compiler. AR is set to merely ar, but that first finds the gnu version in my path instead of the one that goes with clang. When we change the search path around to the first ar is Apple's, everything works.

However, trying Configure.pl --toolchain gnu still chose clang instead of gcc. I don't particularly care which one it uses (at least right now) as long as the other tools come from the right set. I know that I can individually set the paths with args to Configure.pl, but I wouldn't expect to have to do that. I bet most people don't even know what ar is or why they'd set one over the other.

Indeed, the ar being used is /usr/local/bin/ar@ -> ../Cellar/binutils/2.31.1_2/bin/ar rather than /usr/bin/ar And looking at config.log:

configure:5879: checking for ar
configure:5895: found /usr/local/bin/ar

Try renaming /usr/bin/local/ar while building cctools-port. I don't know a better solution at the moment.

Well, since the problem seemed PATH related, I tried:

make clean
export PATH=/usr/bin:/bin:/usr/sbin:/sbin
./configure
make

This builds ar, as, misc but then fails on libobjc2 because the Makefile in that directory hadn't been built. Dunno why. So I moved ld64 earlier in SUBDIRS and then ld got built and ld is what I need:

SUBDIRS = libstuff ar as misc ld64 libobjc2 otool man