Compiling mpfr 4.0.2 on AIX fails to configure TLS support - aix

I'm trying to compile mpfr on AIX and get an error finding TLS support. My end goal is to have a working gcc (9.3) with libstdc++ support for threads and TLS.
I tried compiling with both an existing gcc on the machine (which is 8.3 and doesn't have TLS support, as it seems) and using the built-in xlC (V12.1) on the machine.
I compiled GMP-6.2.0:
(gcc attempt): ./configure --enable-shared --enable-static CFLAGS=-fPIC CXXFLAGS=-fPIC --prefix=$OUTDIR --host=powerpc-ibm-aix7.1.0.0
(xlc attempt): ./configure --enable-shared --enable-static CC=xlc CXX=xlc CFLAGS=-qPIC CXXFLAGS=-qPIC --prefix=$OUTDIR --host=powerpc-ibm-aix7.1.0.0
gmake all
gmake check
gmake install
In both cases gmp successfully tests and installs.
Trying to configure mpfr-4.0.2 results in
(gcc attempt): ./configure --enable-shared --enable-static CFLAGS=-fPIC CXXFLAGS=-fPIC --with-gmp=$OUTDIR --prefix=$OUTDIR --host=powerpc-ibm-aix7.1.0.0
(xlc attempt): ./configure --enable-shared --enable-static CC=xlc CXX=xlc CFLAGS="-qPIC -qtls" CXXFLAGS="-qPIC -qtls" --with-gmp=$OUTDIR --prefix=$OUTDIR --host=powerpc-ibm-aix7.1.0.0
results in the following error in config.log
(gcc attempt):
configure:16567: checking for TLS support
configure:16595: gcc -o conftest -fPIC -I{OUTDIR}/include -I./src -L{OUTDIR}/lib conftest.c >&5
ld: 0711-317 ERROR: Undefined symbol: __tls_get_addr
(xlc attempt):
configure:16567: checking for TLS support
configure:16595: xlc -o conftest -qPIC -qtls -I{OUTDIR}/include -I./src -L{OUTDIR}/lib conftest.c >&5
ld: 0711-317 ERROR: Undefined symbol: .__tls_get_addr
I've tried a dozen different flags and configurations but mostly I don't think I'm in the correct direction - every dependency seems circular. I believe compiling with xlc is the correct idea here, but I just can't figure how to get it properly support TLS.
I also thought that I can ignore this and continue, and later compile libstdc++ again with support for TLS - but that also brought me to a dead end.
Edit:
Taking more actions on using xlc: I tried compiling the generated conftest.c (https://gist.github.com/NitzanEgozy/265e54e3353aefc79558c860b543a98f) manually:
$ xlc -o conftest -qPIC -qtls -I$OUTDIR/include -I./src -L$OUTDIR/lib conftest.c -bnoquiet
(ld): halt 4
(ld): setfflag 4
(ld): savename conftest
(ld): filelist 6 1
(ld): i /lib/crt0.o
(ld): i conftest.o
(ld): lib /usr/vac/lib/libxlopt.a
(ld): lib /usr/vac/lib/libxlipa.a
(ld): lib /usr/vac/lib/libxl.a
(ld): lib /usr/lib/libc.a
LIBRARY: Shared object libc.a[shr.o]: 3301 symbols imported.
LIBRARY: Shared object libc.a[meth.o]: 2 symbols imported.
LIBRARY: Shared object libc.a[posix_aio.o]: 20 symbols imported.
LIBRARY: Shared object libc.a[aio.o]: 18 symbols imported.
LIBRARY: Shared object libc.a[pse.o]: 8 symbols imported.
LIBRARY: Shared object libc.a[dl.o]: 4 symbols imported.
LIBRARY: Shared object libc.a[pty.o]: 1 symbols imported.
LIBRARY: Shared object libc.a[cthread.o]: 25 symbols imported.
FILELIST: Number of previously inserted files processed: 6
(ld): resolve
RESOLVE: 33 of 7029 symbols were kept.
(ld): addgl /usr/lib/glink.o
ADDGL: Glink code added for 2 symbols.
(ld): er full
ld: 0711-318 ERROR: Undefined symbols were found.
The following symbols are in error:
Symbol Inpndx TY CL Source-File(Object-File) OR Import-File{Shared-object}
RLD: Address Section Rld-type Referencing Symbol
----------------------------------------------------------------------------------------------
.__tls_get_addr [30] ER PR conftest.c(conftest.o)
00000010 .text R_RBA [16] .main
Removing -qtls throws The '__thread' keyword is not supported on the target platform. The keyword is ignored.

AFAIK if native TLS is not available gcc emulates it using pthread keys, and i think gcc does not even support native TLS on aix. adding "-pthread" flag to the configuration will enable the appropriate threading support.
the current gcc from the ibm aixtoolbox has the appropriate default threading model enabled, hope this helps a little bit.
root#aixbuildhostng: /root # gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/opt/freeware/libexec/gcc/powerpc-ibm-aix7.1.0.0/8.3.0/lto-wrapper
Target: powerpc-ibm-aix7.1.0.0
Configured with: ../gcc-8.3.0/configure --prefix=/opt/freeware --mandir=/opt/freeware/man --infodir=/opt/freeware/info --with-local-prefix=/opt/freeware --with-as=/usr/bin/as --with-ld=/usr/bin/ld --enable-languages=c,c++,fortran,objc,obj-c++ --enable-version-specific-runtime-libs --disable-nls --enable-decimal-float=dpd --with-cloog=no --with-ppl=no --disable-libstdcxx-pch --enable-__cxa_atexit --host=powerpc-ibm-aix7.1.0.0
Thread model: aix
gcc version 8.3.0 (GCC)
mpfr 4.0.2 is also available as an rpm package:
root#aixbuildhostng: /root # yum search mpfr
Loaded plugins: aliases, allowdowngrade, basearchonly, changelog, downloadonly, fastestmirror, filter-data, keys, list-data, local, merge-conf, post-transaction-actions, priorities, protectbase, ps, remove-with-leaves, rpm-warm-cache,
: show-leaves, tmprepo, tsflags, verify, versionlock
Loading mirror speeds from cached hostfile
0 packages excluded due to repository protections
============================================================================================================= N/S Matched: mpfr =============================================================================================================
mpfr-devel.ppc : Development tools A C library for mpfr library
mpfr.ppc : A C library for multiple-precision floating-point computations
ad bootstrapping gcc via xlc...this quite a sophisticated task, i never managed to make this work.
https://gcc.gnu.org/install/specific.html#x-ibm-aix

Related

Include error when building TensorFlow from source with a different GCC than the system one

I have been trying to build TensorFlow 2.0 from the master branch on a Red Hat Linux Enterprise edition cluster.
The default GCC available is 4.8.5, and it is not possible to compile TensorFlow with it because it uses explicit
std=c++14
flag which is not available in GCC 4.8.5
Hence, I started using gcc/8.3.0 using a modulefile, which is configured as follows :
(tensorflow2.0-master) -bash-4.2$ module show gcc/8.3.0/gcc-4.8.5
-------------------------------------------------------------------
/gpfslocalsup/pub/modules-idris/modulefiles/linux-rhel7-x86_64/gcc/8.3.0/gcc-4.8.5:
module-whatis The GNU Compiler Collection includes front ends for C, C++, Objective-C, Fortran, Ada, and Go, as well as libraries for these languages.
conflict gcc
prepend-path PATH /gpfslocalsup/spack_soft/gcc/8.3.0/gcc-4.8.5-opnwtdjumg2hxo4ljvnx77ugb6afmvj3/bin
prepend-path MANPATH /gpfslocalsup/spack_soft/gcc/8.3.0/gcc-4.8.5-opnwtdjumg2hxo4ljvnx77ugb6afmvj3/share/man
prepend-path LD_LIBRARY_PATH /gpfslocalsup/spack_soft/gcc/8.3.0/gcc-4.8.5-opnwtdjumg2hxo4ljvnx77ugb6afmvj3/lib
prepend-path LIBRARY_PATH /gpfslocalsup/spack_soft/gcc/8.3.0/gcc-4.8.5-opnwtdjumg2hxo4ljvnx77ugb6afmvj3/lib
prepend-path LD_LIBRARY_PATH /gpfslocalsup/spack_soft/gcc/8.3.0/gcc-4.8.5-opnwtdjumg2hxo4ljvnx77ugb6afmvj3/lib64
prepend-path LIBRARY_PATH /gpfslocalsup/spack_soft/gcc/8.3.0/gcc-4.8.5-opnwtdjumg2hxo4ljvnx77ugb6afmvj3/lib64
prepend-path CPATH /gpfslocalsup/spack_soft/gcc/8.3.0/gcc-4.8.5-opnwtdjumg2hxo4ljvnx77ugb6afmvj3/include
prepend-path CMAKE_PREFIX_PATH /gpfslocalsup/spack_soft/gcc/8.3.0/gcc-4.8.5-opnwtdjumg2hxo4ljvnx77ugb6afmvj3/
setenv CC /gpfslocalsup/spack_soft/gcc/8.3.0/gcc-4.8.5-opnwtdjumg2hxo4ljvnx77ugb6afmvj3/bin/gcc
setenv CXX /gpfslocalsup/spack_soft/gcc/8.3.0/gcc-4.8.5-opnwtdjumg2hxo4ljvnx77ugb6afmvj3/bin/g++
setenv FC /gpfslocalsup/spack_soft/gcc/8.3.0/gcc-4.8.5-opnwtdjumg2hxo4ljvnx77ugb6afmvj3/bin/gfortran
setenv F77 /gpfslocalsup/spack_soft/gcc/8.3.0/gcc-4.8.5-opnwtdjumg2hxo4ljvnx77ugb6afmvj3/bin/gfortran
setenv F90 /gpfslocalsup/spack_soft/gcc/8.3.0/gcc-4.8.5-opnwtdjumg2hxo4ljvnx77ugb6afmvj3/bin/gfortran
-------------------------------------------------------------------
To compile TensorFlow, I first compiled bazel-0.29.1 and for that I modified the
tools/cpp/cc_toolchain_config.bzl
file as follows :
I replaced all occourances of /usr/bin/gcc, /usr/bin/gcov, /usr/bin/nm, /usr/bin/ar, /usr/bin/cpp with the binaries in PATH as shown above.
I added the include path as shown above, to the list of cxx_builtin_include_directory present in the file.
After that I proceeded to build TensorFlow.
The command used was :
CC=/gpfslocalsup/spack_soft/gcc/8.3.0/gcc-4.8.5-opnwtdjumg2hxo4ljvnx77ugb6afmvj3/bin/gcc bazel --output_user_root=/tmp/ujjwal-builds build --config=opt --config=cuda --config=mkl --config=numa //tensorflow/tools/pip_package:build_pip_package --verbose_failures
This ended up giving me the following error :
INFO: Analyzed target //tensorflow/tools/pip_package:build_pip_package (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
ERROR: /tmp/ujjwal-builds/7d993f307acf01aa765c32a6dcabd368/external/gif/BUILD.bazel:8:1: undeclared inclusion(s) in rule '#gif//:gif':
this rule is missing dependency declarations for the following files included by 'external/gif/gif_err.c':
'/gpfslocalsup/spack_soft/gcc/8.3.0/gcc-4.8.5-opnwtdjumg2hxo4ljvnx77ugb6afmvj3/lib/gcc/x86_64-pc-linux-gnu/8.3.0/include/stddef.h'
'/gpfslocalsup/spack_soft/gcc/8.3.0/gcc-4.8.5-opnwtdjumg2hxo4ljvnx77ugb6afmvj3/lib/gcc/x86_64-pc-linux-gnu/8.3.0/include/stdarg.h'
'/gpfslocalsup/spack_soft/gcc/8.3.0/gcc-4.8.5-opnwtdjumg2hxo4ljvnx77ugb6afmvj3/lib/gcc/x86_64-pc-linux-gnu/8.3.0/include/stdbool.h'
'/gpfslocalsup/spack_soft/gcc/8.3.0/gcc-4.8.5-opnwtdjumg2hxo4ljvnx77ugb6afmvj3/lib/gcc/x86_64-pc-linux-gnu/8.3.0/include/stdint.h'
Target //tensorflow/tools/pip_package:build_pip_package failed to build
INFO: Elapsed time: 2.152s, Critical Path: 1.63s
INFO: 7 processes: 7 local.
FAILED: Build did NOT complete successfully
I have tried to search for solutions online but there are no satisfactory solutions. Can anyone please help me with what is going on here as it is important for me.
If it helps, I have attached the output of gcc and g++ include paths below :
gcc -E -xc++ - -v
Reading specs from /gpfs7kro/gpfslocalsup/spack_soft/gcc/8.3.0/gcc-4.8.5-opnwtdjumg2hxo4ljvnx77ugb6afmvj3/bin/../lib/gcc/x86_64-pc-linux-gnu/8.3.0/specs
COLLECT_GCC=gcc
Target: x86_64-pc-linux-gnu
Configured with: /gpfs7kw/linkhome/idris/softmgr/softmgr01/spack/var/spack/stage/gcc-8.3.0-opnwtdjumg2hxo4ljvnx77ugb6afmvj3/spack-src/configure --prefix=/gpfslocalsup/spack_soft/gcc/8.3.0/gcc-4.8.5-opnwtdjumg2hxo4ljvnx77ugb6afmvj3 --disable-multilib --enable-languages=c,c++,fortran --with-mpfr=/gpfslocalsup/spack_soft/mpfr/3.1.6/gcc-4.8.5-vwx7snyrzymeg5n6f7dg5tbpgk35do3k --with-gmp=/gpfslocalsup/spack_soft/gmp/6.1.2/gcc-4.8.5-5odxtlxihbfjtj4dxo52oz5f7r6ir6jk --enable-lto --with-quad --with-system-zlib --with-mpc=/gpfslocalsup/spack_soft/mpc/1.1.0/gcc-4.8.5-pogagquauxex67doa7v2mkas2gcs5xut --with-isl=/gpfslocalsup/spack_soft/isl/0.18/gcc-4.8.5-3wslknueis6r2nx3tasaizgda2ianxfa
Thread model: posix
gcc version 8.3.0 (GCC)
COLLECT_GCC_OPTIONS='-E' '-v' '-mtune=generic' '-march=x86-64'
/gpfs7kro/gpfslocalsup/spack_soft/gcc/8.3.0/gcc-4.8.5-opnwtdjumg2hxo4ljvnx77ugb6afmvj3/bin/../libexec/gcc/x86_64-pc-linux-gnu/8.3.0/cc1plus -E -quiet -v -iprefix /gpfs7kro/gpfslocalsup/spack_soft/gcc/8.3.0/gcc-4.8.5-opnwtdjumg2hxo4ljvnx77ugb6afmvj3/bin/../lib/gcc/x86_64-pc-linux-gnu/8.3.0/ -D_GNU_SOURCE - -mtune=generic -march=x86-64
ignoring nonexistent directory "/gpfs7kro/gpfslocalsup/spack_soft/gcc/8.3.0/gcc-4.8.5-opnwtdjumg2hxo4ljvnx77ugb6afmvj3/bin/../lib/gcc/x86_64-pc-linux-gnu/8.3.0/../../../../x86_64-pc-linux-gnu/include"
ignoring duplicate directory "/gpfs7kro/gpfslocalsup/spack_soft/gcc/8.3.0/gcc-4.8.5-opnwtdjumg2hxo4ljvnx77ugb6afmvj3/bin/../lib/gcc/../../lib/gcc/x86_64-pc-linux-gnu/8.3.0/../../../../include/c++/8.3.0"
ignoring duplicate directory "/gpfs7kro/gpfslocalsup/spack_soft/gcc/8.3.0/gcc-4.8.5-opnwtdjumg2hxo4ljvnx77ugb6afmvj3/bin/../lib/gcc/../../lib/gcc/x86_64-pc-linux-gnu/8.3.0/../../../../include/c++/8.3.0/x86_64-pc-linux-gnu"
ignoring duplicate directory "/gpfs7kro/gpfslocalsup/spack_soft/gcc/8.3.0/gcc-4.8.5-opnwtdjumg2hxo4ljvnx77ugb6afmvj3/bin/../lib/gcc/../../lib/gcc/x86_64-pc-linux-gnu/8.3.0/../../../../include/c++/8.3.0/backward"
ignoring duplicate directory "/gpfs7kro/gpfslocalsup/spack_soft/gcc/8.3.0/gcc-4.8.5-opnwtdjumg2hxo4ljvnx77ugb6afmvj3/bin/../lib/gcc/../../lib/gcc/x86_64-pc-linux-gnu/8.3.0/include"
ignoring duplicate directory "/gpfs7kro/gpfslocalsup/spack_soft/gcc/8.3.0/gcc-4.8.5-opnwtdjumg2hxo4ljvnx77ugb6afmvj3/bin/../lib/gcc/../../lib/gcc/x86_64-pc-linux-gnu/8.3.0/include-fixed"
ignoring nonexistent directory "/gpfs7kro/gpfslocalsup/spack_soft/gcc/8.3.0/gcc-4.8.5-opnwtdjumg2hxo4ljvnx77ugb6afmvj3/bin/../lib/gcc/../../lib/gcc/x86_64-pc-linux-gnu/8.3.0/../../../../x86_64-pc-linux-gnu/include"
ignoring duplicate directory "/gpfslocalsup/spack_soft/gcc/8.3.0/gcc-4.8.5-opnwtdjumg2hxo4ljvnx77ugb6afmvj3/include"
as it is a non-system directory that duplicates a system directory
#include "..." search starts here:
#include <...> search starts here:
/gpfslocalsys/intel/parallel_studio_xe_2019_update5_cluster_edition/compilers_and_libraries_2019.5.281/linux/mkl/include
/gpfs7kro/gpfslocalsup/spack_soft/gcc/8.3.0/gcc-4.8.5-opnwtdjumg2hxo4ljvnx77ugb6afmvj3/bin/../lib/gcc/x86_64-pc-linux-gnu/8.3.0/../../../../include/c++/8.3.0
/gpfs7kro/gpfslocalsup/spack_soft/gcc/8.3.0/gcc-4.8.5-opnwtdjumg2hxo4ljvnx77ugb6afmvj3/bin/../lib/gcc/x86_64-pc-linux-gnu/8.3.0/../../../../include/c++/8.3.0/x86_64-pc-linux-gnu
/gpfs7kro/gpfslocalsup/spack_soft/gcc/8.3.0/gcc-4.8.5-opnwtdjumg2hxo4ljvnx77ugb6afmvj3/bin/../lib/gcc/x86_64-pc-linux-gnu/8.3.0/../../../../include/c++/8.3.0/backward
/gpfs7kro/gpfslocalsup/spack_soft/gcc/8.3.0/gcc-4.8.5-opnwtdjumg2hxo4ljvnx77ugb6afmvj3/bin/../lib/gcc/x86_64-pc-linux-gnu/8.3.0/include
/gpfs7kro/gpfslocalsup/spack_soft/gcc/8.3.0/gcc-4.8.5-opnwtdjumg2hxo4ljvnx77ugb6afmvj3/bin/../lib/gcc/x86_64-pc-linux-gnu/8.3.0/include-fixed
/usr/local/include
/gpfs7kro/gpfslocalsup/spack_soft/gcc/8.3.0/gcc-4.8.5-opnwtdjumg2hxo4ljvnx77ugb6afmvj3/bin/../lib/gcc/../../include
/usr/include
End of search list.
You could try using this PR from within spack for this : https://github.com/spack/spack/pull/14681

How to add linker option to CMake bootstrap?

I'm building CMake 3.12.4 from the release tarball on AIX. CMake is failing to link on the machine:
ld: 0711-781 ERROR: TOC overflow. TOC size: 65632 Maximum size: 65536
The error is detailed in the IBM technotes at ld: 0711-781 ERROR: TOC overflow. I want to add -bbigtoc linker option for the cmake recipe.
CMake's bootstrap does not appear to accept linker options for LDFLAGS as shown below.
How do I add a linker flag to the bootstrap process?
Here are the options CMake bootstrap accepts:
$ ./bootstrap --help
Usage: ./bootstrap [<options>...] [-- <cmake-options>...]
Options: [defaults in brackets after descriptions]
Configuration:
--help print this message
--version only print version information
--verbose display more information
--parallel=n bootstrap cmake in parallel, where n is
number of nodes [1]
--enable-ccache Enable ccache when building cmake
--init=FILE load FILE as script to populate cache
--system-libs use all system-installed third-party libraries
(for use only by package maintainers)
--no-system-libs use all cmake-provided third-party libraries
(default)
--system-curl use system-installed curl library
--no-system-curl use cmake-provided curl library (default)
--system-expat use system-installed expat library
--no-system-expat use cmake-provided expat library (default)
--system-jsoncpp use system-installed jsoncpp library
--no-system-jsoncpp use cmake-provided jsoncpp library (default)
--system-zlib use system-installed zlib library
--no-system-zlib use cmake-provided zlib library (default)
--system-bzip2 use system-installed bzip2 library
--no-system-bzip2 use cmake-provided bzip2 library (default)
--system-liblzma use system-installed liblzma library
--no-system-liblzma use cmake-provided liblzma library (default)
--system-libarchive use system-installed libarchive library
--no-system-libarchive use cmake-provided libarchive library (default)
--system-librhash use system-installed librhash library
--no-system-librhash use cmake-provided librhash library (default)
--system-libuv use system-installed libuv library
--no-system-libuv use cmake-provided libuv library (default)
--qt-gui build the Qt-based GUI (requires Qt >= 4.2)
--no-qt-gui do not build the Qt-based GUI (default)
--qt-qmake=<qmake> use <qmake> as the qmake executable to find Qt
--sphinx-info build Info manual with Sphinx
--sphinx-man build man pages with Sphinx
--sphinx-html build html help with Sphinx
--sphinx-qthelp build qch help with Sphinx
--sphinx-build=<sb> use <sb> as the sphinx-build executable
--sphinx-flags=<flags> pass <flags> to sphinx-build executable
Directory and file names:
--prefix=PREFIX install files in tree rooted at PREFIX
[/usr/local]
--bindir=DIR install binaries in PREFIX/DIR
[bin]
--datadir=DIR install data files in PREFIX/DIR
[share/cmake-3.12]
--docdir=DIR install documentation files in PREFIX/DIR
[doc/cmake-3.12]
--mandir=DIR install man pages files in PREFIX/DIR/manN
[man]
--xdgdatadir=DIR install XDG specific files in PREFIX/DIR
[share]
Here is the CMake link error:
cmake_build$ make VERBOSE=1
...
[ 91%] Linking CXX executable ../bin/cmake
cd /home/noloader/cmake_build/Source && /home/noloader/cmake_build/Boots
trap.cmk/cmake -E cmake_link_script CMakeFiles/cmake.dir/link.txt --verbose=1
/usr/bin/g++ -pthread -Wl,-bnoipath -Wl,-brtl -Wl,-bexpall CMakeFiles/cmake.dir
/cmakemain.cxx.o CMakeFiles/cmake.dir/cmcmd.cxx.o -o ../bin/cmake -Wl,-blibpath
:/opt/freeware/lib/gcc/powerpc-ibm-aix7.1.0.0/4.8.1/pthread:/opt/freeware/lib/pt
hread:/opt/freeware/lib/gcc/powerpc-ibm-aix7.1.0.0/4.8.1:/opt/freeware/lib:/usr/
lib:/lib libCMakeLib.a libCMakeServerLib.a libCMakeLib.a kwsys/libcmsys.a ../Uti
lities/cmexpat/libcmexpat.a ../Utilities/cmlibarchive/libarchive/libcmlibarchive
.a ../Utilities/cmliblzma/libcmliblzma.a ../Utilities/cmbzip2/libcmbzip2.a ../Ut
ilities/cmcompress/libcmcompress.a ../Utilities/cmcurl/lib/libcmcurl.a ../Utilit
ies/cmzlib/libcmzlib.a -lld ../Utilities/cmjsoncpp/libcmjsoncpp.a ../Utilities/c
mlibuv/libcmlibuv.a -lperfstat ../Utilities/cmlibrhash/libcmlibrhash.a
ld: 0711-781 ERROR: TOC overflow. TOC size: 65632 Maximum size: 65536
collect2: error: ld returned 12 exit status
make: 1254-004 The error code from the last command is 1.
Something like this:
export CFLAGS=...
export CXXFLAGS=...
export LDFLAGS='... -Wl,-bbigtoc'
./bootstrap ... --verbose
make VERBOSE=1 all
Also you might want to read this: http://lzsiga.users.sourceforge.net/aix-linking.html#Q0025

Error when linking GSL with -static

I have written a programm in c++. Linking and runiing is working, as long as I don't use the "-static" option for g++. But I have to run it from an Antergos USB-Live Stick with default settings and there is no GSL included. In the manual of GSL they recommend
$ g++ -c main.cpp
$ g++ -static main.o -lgsl -lgslcblas -lm -lnlopt
But for this code I receive an error message:
/usr/bin/ld: cannot find -lgsl
/usr/bin/ld: cannot find -lgslcblas
collect2: Fehler: ld gab 1 als End-Status zurück
I tried it as this question, but it didn't work for me. When I run
$ g++ -O2 -o test main.cpp -lgsl -lgslcblas -lnlopt -lm
$ lld test
it prints
linux-vdso.so.1 (0x00007fffa5b95000)
libgsl.so.19 => /usr/lib/libgsl.so.19 (0x00007f8748c9a000)
libgslcblas.so.0 => /usr/lib/libgslcblas.so.0 (0x00007f8748a5d000)
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00007f87486d5000)
libm.so.6 => /usr/lib/libm.so.6 (0x00007f87483d1000)
libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x00007f87481ba000)
libc.so.6 => /usr/lib/libc.so.6 (0x00007f8747e1c000)
/lib64/ld-linux-x86-64.so.2 (0x00007f87490fe000)
So I tried to create a symlink, but I do have also "libgsl.so"
$ ls /usr/lib/libgsl
libgslcblas.so libgslcblas.so.0.0.0 libgsl.so.19
libgslcblas.so.0 libgsl.so libgsl.so.19.3.0
Am I doing something stupid? Thank your for your help.
When you pass -lgsl, by default you request the linker to
find and link either the shared library libgsl.so or the static
library libgsl.a and to prefer the shared library, if both are found
in the same search directory. The linker will search, first, in any
directories you have specified with the -L/path/to/search options,
in the order you specified, and then in its default search directories
(/usr/lib, etc.). Likewise for -lgslcblas.
But when you pass the linkage option -static to gcc/g++, it prevents
linking with any shared libraries. Shared libraries, libgsl.so, libgslcblas.so
will be ignored. Static libraries libgsl.a, libgslblas.a, must be
found, in some or other of the search directories, for the linkage to
succeed.
The linker is saying:
/usr/bin/ld: cannot find -lgsl
/usr/bin/ld: cannot find -lgslcblas
because it can't find those static libraries - presumably because you
haven't installed them.
You do not say what linux distro you are working on, but if the package
that provides libgsl and libgslcblas is called, say, libgsl[suffix]
then there will be a corresponding package called libgsl-dev, libgsl-devel,
or similar. This will be the development version of the package,
for the use of people who want to develop software that links with libgsl
or libgslcblas. The development package will require the libgsl package as a dependency
- so it will install the same stuff - and will in addition contain the
library's header files and the static version of the library.
So you need to install the libgsl development package for your distro.
For Ubuntu, for example, that is libgsl-dev:
Later
I gather that your distro, Arch Linux, does not do separate dev packages. You
need to build the static libraries from source. To do that you will need
at least to have installed:
GNU Make
GNU autotools (autoconf, automake, libtool)
GCC (C compiler)
texinfo
Then to make a default build:
Get the gsl source package from https://savannah.gnu.org/git/?group=gsl
either by cloning the git repo or downloading a current tar.gz tarball
and extracting it.
cd into the package directory.
run ./autogen.sh. This will succeed provided the GNU autotools prerequisites
are fulfilled.
run ./configure --enable-maintainer-mode (as ./autogen.sh will have prompted you).
This will succeed provided that the package dependencies are satisfied
and environment sanity checks pass.
run make
If make completes without errors - which will take a matter of minutes -
then, as root, run make install.
If all is well, this will install your missing static libraries:
/usr/local/lib/libgsl.a
/usr/local/lib/libgslcblas.a
You should not need to modify your linkage command for the linker to find
them: /usr/local/lib is a default linker search path.

Unable to link against Boost.Python on OS X

I am trying to build a really trivial example with Boost.Python. I have installed boost and boost-python with homebrew. I am using python 3.4.3 and boost 1.59. My OS is El Capitan.
Boost.Python was installed with python3 like this:
brew install boost-python --with-python3
I have 3 files:
/* greet.hpp */
#ifndef BOOSTPYTHONHELLOWORLD_GREET_HPP
#define BOOSTPYTHONHELLOWORLD_GREET_HPP
char const* greet();
#endif //BOOSTPYTHONHELLOWORLD_GREET_HPP
/* greet.cpp */
#include "greet.hpp"
char const* greet()
{
return "Hello world";
}
/* greet_ext.cpp */
#include "greet.hpp"
#include <boost/python.hpp>
BOOST_PYTHON_MODULE(greet_ext)
{
using namespace boost::python;
def("greet", greet);
}
My CMakeLists.txt file looks like this:
cmake_minimum_required(VERSION 3.3)
project(BoostPythonHelloWorld)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(PYTHON_LIBRARY "/usr/local/Cellar/python3/3.4.3/Frameworks/Python.framework/Versions/3.4/lib/libpython3.4m.dylib")
set(PYTHON_INCLUDE_DIR "/usr/local/Cellar/python3/3.4.3/Frameworks/Python.framework/Versions/3.4/include/python3.4m")
FIND_PACKAGE(PythonLibs 3.4 REQUIRED)
FIND_PACKAGE(Boost COMPONENTS python)
if(NOT WIN32)
add_definitions(-DBOOST_ALL_DYN_LINK=1)
add_definitions(-DBOOST_TEST_DYN_LINK)
endif()
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS} ${PYTHON_INCLUDE_DIRS})
add_library(greet SHARED greet.cpp)
add_library(greet_ext SHARED greet_ext.cpp)
target_link_libraries(greet_ext greet)
target_link_libraries(greet_ext ${PYTHON_LIBRARIES})
target_link_libraries(greet_ext ${Boost_LIBRARIES})
set_target_properties(greet_ext PROPERTIES PREFIX "")
When I run CMake it finds all the correct python libraries (because I specified them manually as you can see in the file above).
During build I get the following link error:
Scanning dependencies of target greet
[ 25%] Building CXX object CMakeFiles/greet.dir/greet.cpp.o
[ 50%] Linking CXX shared library libgreet.dylib
[ 50%] Built target greet
Scanning dependencies of target greet_ext
[ 75%] Building CXX object CMakeFiles/greet_ext.dir/greet_ext.cpp.o
[100%] Linking CXX shared library greet_ext.dylib
Undefined symbols for architecture x86_64:
"boost::python::detail::init_module(PyModuleDef&, void (*)())", referenced from:
_PyInit_greet_ext in greet_ext.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [greet_ext.dylib] Error 1
make[1]: *** [CMakeFiles/greet_ext.dir/all] Error 2
make: *** [all] Error 2
Anyone have any idea why this is happening?
EDIT
If I link against Python 2.7 it works, which means boost-python was built against python 2.7 instead of 3.4, even though I specified the --with-python3 options..
So, the questions is, how to build boost-python against python 3.4?
The solution I am currently using is to reinstall boost-python without python 2.7 support.
The steps I took were:
Uninstall boost-python if already installed: brew uninstall boost-python.
Install boost-python with python3 support but without python 2.7 support: brew install boost-python --with-python3 --without-python.
In order to use boost-python with python 3 you need to change this in your CMakeLists.txt:
FIND_PACKAGE(Boost COMPONENTS python)
to this:
FIND_PACKAGE(Boost COMPONENTS python3)
That way you can recompile boost with python 2 support and still use python 3.
I'd suggest installing boost-python3 via brew.
You still need to give the minor version number as well and possibly the library path. The following worked for me:
BOOST_LIBRARYDIR=/usr/local/Cellar/boost-python3/1.67.0/lib cmake ..
with CMakeLists.txt (located in ..) containing
FIND_PACKAGE(Boost COMPONENTS python36)
(for Boost 1.67.0 and Python 3.6, obviously).

Compile C++ code to run on ESXi 3.5

I'm trying to compile a simple c++ program to run inside ESXi 3.5 console window. It seems I'm linking with wrong libraries... Is there a setup described somewhere - which version of G++ and libraries do I have to be using in order to do so?
Here's how I resolved the issue. I did following to compile:
Compiled using gcc under ubuntu
Ran ldd on executable
Copied all libraries that showed up as dependencies to subfolder ESXi-3.5-lib. In my case they were:
ld-linux.so.2
libc.so.6
libgcc_s.so.1
libm.so.6
libstdc++.so.5
Added following switches to gcc:
-nodefaultlibs (to not attempt to link with default libs)
-lc (prevented link error in some crt library)
-fno-stack-protector (prevented another error, some other function was missing)
Following was my final build command:
g++ file1.cpp file2.cpp file3.cpp -o output-biinary-file-name \
ESXi-3.5-lib/ld-linux.so.2 ESXi-3.5-lib/libc.so.6 ESXi-3.5-lib/libgcc_s.so.1\
ESXi-3.5-lib/libm.so.6 ESXi-3.5-lib/libstdc++.so.5 \
-nodefaultlibs -lc -m32 -fno-stack-protector