Build of guile-2.0.11 on macOS Sierra fails: Undefined symbols for architecture x86_64 - c

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),

Related

dieharder compilation failure on Apple Silicon: 'ld: symbol(s) not found for architecture arm64'

Attempting to compile dieharder from source on an M1 Max (macOS 12 + Xcode 13.3.1 + command line tools) and running into an error:
...
/bin/sh ../libtool --tag=CC --mode=link gcc -std=c99 -Wall -pedantic -I/usr/local/include -I/opt/local/include -L/opt/local/lib -o dieharder dieharder-add_ui_rngs.o dieharder-add_ui_tests.o dieharder-choose_rng.o dieharder-dieharder.o dieharder-dieharder_exit.o dieharder-help.o dieharder-list_rngs.o dieharder-list_tests.o dieharder-output.o dieharder-output_rnds.o dieharder-parsecl.o dieharder-rdieharder.o dieharder-run_all_tests.o dieharder-run_test.o dieharder-set_globals.o dieharder-testbits.o dieharder-time_rng.o dieharder-user_template.o ../libdieharder/libdieharder.la -lgsl -lgslcblas -lm -lgsl -lgslcblas
libtool: link: gcc -std=c99 -Wall -pedantic -I/usr/local/include -I/opt/local/include -o dieharder dieharder-add_ui_rngs.o dieharder-add_ui_tests.o dieharder-choose_rng.o dieharder-dieharder.o dieharder-dieharder_exit.o dieharder-help.o dieharder-list_rngs.o dieharder-list_tests.o dieharder-output.o dieharder-output_rnds.o dieharder-parsecl.o dieharder-rdieharder.o dieharder-run_all_tests.o dieharder-run_test.o dieharder-set_globals.o dieharder-testbits.o dieharder-time_rng.o dieharder-user_template.o -L/opt/local/lib ../libdieharder/.libs/libdieharder.a -lm -lgsl -lgslcblas
Undefined symbols for architecture arm64:
"_insert", referenced from:
_dab_filltree in libdieharder.a(libdieharder_la-dab_filltree.o)
_main_filltree in libdieharder.a(libdieharder_la-dab_filltree.o)
"_insertBit", referenced from:
_dab_filltree2 in libdieharder.a(libdieharder_la-dab_filltree2.o)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
...
I got to this failure with a MacPorts installed gsl and by executing the following:
$ mkdir dieharder; cd dieharder
$ wget --no-check-certificate https://webhome.phy.duke.edu/~rgb/General/dieharder/dieharder-3.31.1.tgz
$ tar xf dieharder-3.31.1.tgz
$ cd dieharder-3.31.1
$ sudo port install gsl
$ ./configure LDFLAGS=-L/opt/local/lib CPPFLAGS=-I/opt/local/include CFLAGS=-I/opt/local/include --disable-shared
...
$ make
...
I reproduced the failure with Homebrew:
$ brew install gsl
$ make distclean
$ ./configure LDFLAGS=-L/opt/homebrew/lib CPPFLAGS=-I/opt/homebrew/include CFLAGS=-I/opt/homebrew/include --disable-shared
...
$ make
...
/bin/sh ../libtool --tag=CC --mode=link gcc -std=c99 -Wall -pedantic -I/usr/local/include -I/opt/homebrew/include -L/opt/homebrew/lib -o dieharder dieharder-add_ui_rngs.o dieharder-add_ui_tests.o dieharder-choose_rng.o dieharder-dieharder.o dieharder-dieharder_exit.o dieharder-help.o dieharder-list_rngs.o dieharder-list_tests.o dieharder-output.o dieharder-output_rnds.o dieharder-parsecl.o dieharder-rdieharder.o dieharder-run_all_tests.o dieharder-run_test.o dieharder-set_globals.o dieharder-testbits.o dieharder-time_rng.o dieharder-user_template.o ../libdieharder/libdieharder.la -lgsl -lgslcblas -lm -lgsl -lgslcblas
libtool: link: gcc -std=c99 -Wall -pedantic -I/usr/local/include -I/opt/homebrew/include -o dieharder dieharder-add_ui_rngs.o dieharder-add_ui_tests.o dieharder-choose_rng.o dieharder-dieharder.o dieharder-dieharder_exit.o dieharder-help.o dieharder-list_rngs.o dieharder-list_tests.o dieharder-output.o dieharder-output_rnds.o dieharder-parsecl.o dieharder-rdieharder.o dieharder-run_all_tests.o dieharder-run_test.o dieharder-set_globals.o dieharder-testbits.o dieharder-time_rng.o dieharder-user_template.o -L/opt/homebrew/lib ../libdieharder/.libs/libdieharder.a -lm -lgsl -lgslcblas
Undefined symbols for architecture arm64:
"_insert", referenced from:
_dab_filltree in libdieharder.a(libdieharder_la-dab_filltree.o)
_main_filltree in libdieharder.a(libdieharder_la-dab_filltree.o)
"_insertBit", referenced from:
_dab_filltree2 in libdieharder.a(libdieharder_la-dab_filltree2.o)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [dieharder] Error 1
make: *** [dieharder.time] Error 2
Anyone know what might be going on here and how to properly configure this to complete compilation on and for Apple Silicon systems?
It turns out that the insert functions are not exported public for the ARM compilation of the library:
Undefined symbols for architecture arm64:
"_insert", referenced from:
_dab_filltree in libdieharder.a(libdieharder_la-dab_filltree.o)
_main_filltree in libdieharder.a(libdieharder_la-dab_filltree.o)
"_insertBit", referenced from:
_dab_filltree2 in libdieharder.a(libdieharder_la-dab_filltree2.o)
See: https://github.com/eddelbuettel/dieharder/pull/1/files
After adding static to those four lines dieharder compiles fine.
Screenshot of changes required:

Error while trying to create shared library

I am trying to create the shared library (.so) so that I can call it using .External command from R for the lassoshooting package:
https://cran.r-project.org/web/packages/lassoshooting/
Basically, I have downloaded the package source from the above website. However, when I go the the correct directory (.../lassoshooting/src) and use the command
R CMD SHLIB -o ccd_r.so ccd_r.c
I get the following error:
clang -dynamiclib -Wl,-headerpad_max_install_names -undefined
dynamic_lookup -single_module -multiply_defined suppress
-L/Library/Frameworks/R.framework/Resources/lib -L/usr/local/lib -o ccd_r.so ccd_r.o -L/Library/Frameworks/R.framework/Resources/lib
-lRblas -L/usr/local/lib/gcc/x86_64-apple-darwin13.0.0/4.8.2 -lgfortran -lquadmath -lm -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
ld: warning: directory not found for option '-L/usr/local/lib/gcc/x86_64-apple-darwin13.0.0/4.8.2'
ld: library not found for -lgfortran
clang: error: linker command failed with exit code 1 (use -v to see invocation) make: *** [ccd_r.so] Error 1
Why is this happening?

How to build Gotoblas2 on Opensuse 12.2

While building GotoBlas2 on my x86_64 by using the default make file, I encounter the following build error:
gcc -O2 -DEXPRECISION -m128bit-long-double -Wall -m64
-DF_INTERFACE_GFORT -fPIC -DSMP_SERVER -DMAX_CPU_NUMBER=8 -DASMNAME= -DASMFNAME=_ -DNAME=_ -DCNAME= -DCHAR_NAME=\"_\" -DCHAR_CNAME=\"\" -I.. -w -o linktest linktest.c ../libgoto2_nehalemp-r1.13.so -L/usr/lib64/gcc/x86_64-suse-linux/4.7 -L/usr/lib64/gcc/x86_64-suse-linux/4.7/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib64/gcc/x86_64-suse-linux/4.7/../../../../x86_64-suse-linux/lib
-L/usr/lib64/gcc/x86_64-suse-linux/4.7/../../.. -l -l -lgfortran -lm -lquadmath -lm -lc && echo OK. /usr/lib64/gcc/x86_64-suse-linux/4.7/../../../../x86_64-suse-linux/bin/ld:
cannot find -l-l collect2: error: ld returned 1 exit status make[1]:
* [../libgoto2_nehalemp-r1.13.so] Error 1 make[1]: Leaving directory `/home/ken/bin/build/GotoBLAS2/exports' make: * [shared] Error 2
In an attempt to remedy the problem I searched my package manager for a library to satisfy -l-l, looking for things like libl, liblex, libflex, etc but I can't find anything to satisfy the link.
Any ideas?
To fix this, edit line 298 in f_check to
"print MAKEFILE "FEXTRALIB=$linker_L -lgfortran -lm -lquadmath -lm $linker_a\n";"

Compiling and Linking a C-Program for a 32-bit Architecture

So I'm working through an assignment for Stanford's CS107 course and I can't get past compiling the unfinished program (project files and the original makefile can be found on the course page, I'm working on assignment 4 RSS.)
After much research, I think the problem is I'm using gcc on a 64-bit architecture (Mac OS 10.6) and the pre-compiled library code under assn-4-rss-news-search-lib/linux is for a 32-bit architecture. I tried setting gcc to use i386 and -m36, but nothings working and I'm kind of just guessing.
So here's the output I get when I run make:
gcc -g -Wall -std=gnu99 -Wno-unused-function -c -o rss-news-search.o rss-news-search.c
gcc rss-news-search.o -g -Wall -std=gnu99 -Wno-unused-function -g -lnsl -lrssnews -L/Users/derp/Documents/OCW/CS107/Work/programming4/assn-4-rss-news-search-lib/linux -o rss-news-search
ld: library not found for -lnsl
collect2: ld returned 1 exit status
make: *** [rss-news-search] Error 1
Here's the output I get when I remove -lnsl where architecture differences are mentioned:
gcc -g -Wall -std=gnu99 -Wno-unused-function -c -o rss-news-search.o rss-news-search.c
gcc rss-news-search.o -g -Wall -std=gnu99 -Wno-unused-function -g -lrssnews -L/Users/derp/Documents/OCW/CS107/Work/programming4/assn-4-rss-news-search-lib/linux -o rss-news-search
ld: warning: in /Users/derp/Documents/OCW/CS107/Work/programming4/assn-4-rss-news-search-lib/linux/librssnews.a, file was built for unsupported file format which is not the architecture being linked (x86_64)
Undefined symbols:
"_URLConnectionDispose", referenced from:
_ProcessFeed in rss-news-search.o
_ParseArticle in rss-news-search.o
... several more undefined symbols mentioned ...
ld: symbol(s) not found
collect2: ld returned 1 exit status
make: *** [rss-news-search] Error 1
So I'm asking for any ideas on what I could do to resolve this. I've been at it for hours tweaking settings and Google'ing around to no avail.
In case someone like me will be looking for answer after all this time passed...
Problem is easy solved by installing wubi version of 32bit Ubuntu. It works fine on 64bit system. You only need to edit makefile so it knows where to look for the libraries provided.
I'm pretty sure that using a precompiled library for linux on macos, whatever the bitness, won't work (well, it is probably possible to cross-compile on MacOS for Linux and perhaps possible to run Linux executable in a compatibility box on MacOS, but that's quite different than what you are trying to do).
libnsl is a standard library on Linux (it provides some networking related functions)

Linking using g++ fails searching for -lstdc++

I'm trying to use someone else's Makefile to complile a very simple c++ library. The makefile is as follows:
JNIFLAGS=-O2 -pthread -I/usr/lib/jvm/java-6-sun/include -I/usr/lib/jvm/java-6-sun/include/linux
all:
rm -f ../dist/libUtils.so
g++ $(JNIFLAGS) -c -m32 -o com_markets_utils_dates_NativeTime.o com_markets_utils_dates_NativeTime.cpp
g++ $(JNIFLAGS) -c -m32 -o DateUtil.o DateUtil.cpp
g++ -pthread -m32 -shared -fPIC -o ../dist/libUtils.so DateUtil.cpp
g++ -pthread -m32 -shared -fPIC -o ../dist/libNativeTime.so DateUtil.o com_markets_utils_dates_NativeTime.o
This compiles fine, but the linker complains:
...
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.4.1/libstdc++.so when searching for -lstdc++
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.4.1/libstdc++.a when searching for -lstdc++
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.4.1/libstdc++.so when searching for -lstdc++
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.4.1/libstdc++.a when searching for -lstdc++
/usr/bin/ld: cannot find -lstdc++
collect2: ld returned 1 exit status
make: *** [all] Error 1
FYI, I am on Ubuntu 9.10 64bit.
Posting for future reference, a solution I found was to install g++-multilib. I had the same incompatible problem relating to -lstdc++ on g++ version 4.6.1
On further probing: g++-multilib is a dummy package which installed g++4.6-multilib which in turn installed the appropriate libstdc++.so under the /usr/lib/gcc/x86_64-linux-gnu/4.6/32 folder.
Answering my own question:
Ths solution seems to be a bit of a hack, you need to create a symlink for the 32 bit version of the library (after installing the packages mentioned in #nos's answer):
$ sudo ln -s /usr/lib32/libstdc++.so.6 /usr/lib32/libstdc++.so
Once you've done this, the linker will automagically find the correct library to use.
It seems you're compiling a 32 bit library on a 64 bit machine, however a 32 bit version of libstdc++ is not present.
Try apt-get install ia32-libs libc6-i386 libc6-dev-i386 lib32gcc1 lib32stdc++6
(btw. you're producing a .so , you should specify -fPIC when compiling your .cpp files as well)

Resources