Understanding error from ld "archive member is not mach-o or llvm bitcode file" - macos

I'm getting the following error when trying to link a code on a Mac (Montery). First let me say that up until a recent upgrade to Xcode the code built fine. GCC is 10, OpenMPI and it's a Fortran code. Now there are multiple executables which build and one libaray. The library compiles fine and is archived via ar (ar -ruvs). For example, here's a compile and build line for a code.
mpif90 -O2 -g -fexternal-blas -fbacktrace -fcheck=all,no-array-temps -fallow-argument-mismatch -I../../LIBSTELL/Release -I/opt/local/include -I. -c ../Sources/boozer_coords.f
mpif90 -shared -Wl,-no_compact_unwind -O2 -g -fexternal-blas -fbacktrace -fcheck=all,no-array-temps -fallow-argument-mismatch -I../../LIBSTELL/Release -I/opt/local/include -o xbooz_xform booz_jac.o read_wout_booz.o foranl.o allocate_boozer.o transpmn.o boozer_xform.o setup_booz.o write_boozmn.o harfun.o trigfunc.o booz_params.o vcoords.o boozer.o free_mem_boozer.o boozer_coords.o booz_persistent.o ../../LIBSTELL/Release/libstell.a -L/usr/lib -L/opt/local/lib -lopenblas -lscalapack -L/opt/local/lib -lnetcdf -lnetcdff -L/opt/local/lib -lfftw3 -L/opt/local/lib -lhdf5hl_fortran -lhdf5_hl -lhdf5_fortran -lhdf5 -lz -ldl -lm
This works fine and produces an executable. However, there is another code which links to this code. For that reason archives are made of the compiled code.
mpif90 -ffree-form -ffree-line-length-none -ffixed-line-length-none -O2 -g -fexternal-blas -fbacktrace -fcheck=all,no-array-temps -fallow-argument-mismatch -I../../LIBSTELL/Release -I../../BOOTSJ/Release -I/opt/local/include -I/opt/local/include -I. -c ../Sources/thrift_main.f90
mpif90 -shared -Wl,-no_compact_unwind -O2 -g -fexternal-blas -fbacktrace -fcheck=all,no-array-temps -fallow-argument-mismatch -I../../LIBSTELL/Release -I/opt/local/include -o xthrift thrift_interface_mod.o thrift_runtime.o thrift_main.o ../../BOOTSJ/Release/libbootsj.a ../../LIBSTELL/Release/libstell.a -L/usr/lib -L/opt/local/lib -lopenblas -lscalapack -L/opt/local/lib -lnetcdf -lnetcdff -L/opt/local/lib -lfftw3 -L/opt/local/lib -lhdf5hl_fortran -lhdf5_hl -lhdf5_fortran -lhdf5 -lz -ldl -lm
ld: in ../../BOOTSJ/Release/libbootsj.a(parambs.mod), archive member 'parambs.mod' with length 2800 is not mach-o or llvm bitcode file '../../BOOTSJ/Release/libbootsj.a' for architecture x86_64
collect2: error: ld returned 1 exit status
I've had limited success trying to understand the source of this error. Here's what the table for the archive looks like.
ar -t ../BOOTSJ/Release/libbootsj.a
__.SYMDEF SORTED
SIMPUN.o
al31.o
allocate_angles.o
allocate_radial.o
bongrid.o
bootsj.o
caprsh2.o
datain.o
deallocate_all.o
denmf.o
do_fft.o
driver.o
fraction.o
grad.o
othersums.o
output.o
parambs.o
positiv.o
read_boozer.o
reorganz.o
smooth1.o
sumit.o
temp.o
tok_fraction.o
trig.o
vmec0.o
woflam.o
parambs.mod
trig.mod
vmec0.mod

OK so I was adding the module files (.mod) to the archive. This was incorrect. Only the Object (.o) files should be in the archive.
If I understand correctly the compiler will use the -I <path> command to look for (.mod) files. So the archive only needs the object files.

Related

"ld: library not found for -lc" in mac big sur

I try to writed a redis module by clone the git project https://github.com/RedisLabs/RedisModulesSDK.git
and type the "Make" command in my mac with big sur version, below message display in the console.
But there is a error "ld: library not found for -lc".
How to fix it. I try the same command in a linux os, it works find.
gcc -g -fPIC -O3 -std=gnu99 -Wall -Wno-unused-function -I../ -c -o util.o util.c
gcc -g -fPIC -O3 -std=gnu99 -Wall -Wno-unused-function -I../ -c -o strings.o strings.c
gcc -g -fPIC -O3 -std=gnu99 -Wall -Wno-unused-function -I../ -c -o sds.o sds.c
gcc -g -fPIC -O3 -std=gnu99 -Wall -Wno-unused-function -I../ -c -o vector.o vector.c
gcc -g -fPIC -O3 -std=gnu99 -Wall -Wno-unused-function -I../ -c -o alloc.o alloc.c
gcc -g -fPIC -O3 -std=gnu99 -Wall -Wno-unused-function -I../ -c -o periodic.o periodic.c
ar rcs librmutil.a util.o strings.o sds.o vector.o alloc.o periodic.o
gcc -I../ -Wall -g -fPIC -lc -lm -std=gnu99 -c -o module.o module.c
clang: warning: -lc: 'linker' input unused [-Wunused-command-line-argument]
clang: warning: -lm: 'linker' input unused [-Wunused-command-line-argument]
ld -o module.so module.o -bundle -undefined dynamic_lookup -v -L../rmutil -lrmutil -lc
#(#)PROGRAM:ld PROJECT:ld64-609.8
BUILD 15:07:46 Dec 18 2020
configured to support archs: armv6 armv7 armv7s arm64 arm64e arm64_32 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em
Library search paths:
../rmutil
/usr/lib
/usr/local/lib
Framework search paths:
/Library/Frameworks/
/System/Library/Frameworks/
ld: library not found for -lc
make[1]: *** [module.so] Error 1
make: *** [module.so] Error 2
To prevent this error on 11.x+: ld: library not found for -lc
the path /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib needs to be added with -L
https://github.com/macports/macports-ports/commit/0a780d32e0ae3997ed2f2d611cee604d1476cdb5

no profiling data created while compiling with gcc

I want to use the gprof profiling option in order to speed up my code. I am compiling with gcc. The problem is that there is not output file created 'gmon.out' or so. Here is a sample of the Makefile I am using:
CC = gcc
LD = gcc
#LIBGSL = -L/usr/local/lib -lgsl -lgslcblas
#LIBGSL = -L/usr/lib/x86_64-linux-gnu -lgsl -lgslcblas -lm
#LIBGSL = -L/home/dupont/gsl/gsl-2.4/lib -lgsl -lgslcblas -lm
LIBGSL = -L/n1/soft/64bit/lib -lgsl -lgslcblas -lm
CFLAGSRELEASE = -g -fopenmp -O -Wall -c -pg -I/n1/hhsoft/64bit/include
LFLAGSRELEASE = -g -pg -lm -Wl,--rpath -Wl,/usr/local/lib $(LIBGSL)
CFLAGSDEBUG = -g -p -pg -Wall
LFLAGSDEBUG = -lm
CFLAGSDEBUG = -g -p -pg -Wall -W # -DDEBUG_OUTPUT
LFLAGSDEBUG = -lm -p -pg -Wl,--rpath -Wl,/usr/local/lib $(LIBGSL)
LIBS= -L/home/dupont/folder/soft/pgplot -lm -lcpgplot /home/dupont/folder/soft/pgplot/libpgplot.a -L/usr/X11R6/lib -lX11
CFLAGS = $(CFLAGSRELEASE)
LFLAGS = $(LFLAGSRELEASE)
I don't know much about makefile, do you have any idea of what the problem could be...?
https://sourceware.org/binutils/docs-2.31/gprof/Executing.html
Your program will write the profile data into a file called gmon.out just before exiting
So there's nothing wrong if make produces your program but not gmon.out.
(anyway, you should remove -p, and ensure you use -pg both for compilation and link).

Can't link static lib for android NDK, cygwin gcc

I have PROJ4 library, succesfully compiled under cygwin and installed to /usr/local.
I'm trying to compile as:
$ arm-linux-androideabi-gcc -o conftest -mthumb temp.c -lproj -L/usr/local/lib -lproj -lz -lm -ldl
C:/dev/Android/android-ndk-r7c/android-8-toolchain/bin/../lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/bin/ld.exe: cannot find -lproj
collect2: ld returned 1 exit status
What am I doing wrong?
Try
$ arm-linux-androideabi-gcc -o conftest -mthumb temp.c /usr/local/lib/libproj.a -lz -lm -ldl
Well, the problem is that android-gcc doesn't understand cygwin path, so we need to use windows path:
$ arm-linux-androideabi-gcc -o conftest -mthumb temp.c -lproj -Lc:/path/to/lib -lproj -lz -lm -ldl

Gnu Octave build error under MinGW/MSYS

I'm trying to build Gnu Octave for Windows.I built all the main dependencies without having much problem.And configuring process went well.But when I tried to run make(After few source modifications to get over some errors),It triggers tons of errors like
./.libs/liboctinterp.a(liboctinterp_la-octave.o): In function `safe_source_file':
C:\MinGW\sources\octave-3.6.2\src/octave.cc:312: undefined reference to `___cxa_begin_catch'
At the line
libtool: link: gcc -g -O2 -pthread -DHAVE_CONFIG_H -mieee-fp -Wall -W -Wshadow -Wformat -Wpointer-arith -Wmissing-prototypes -Wstrict-prototypes -Wwrite-strings -Wcast-align -Wcast-qual -g -O2 -pthread -pthread -g -O2 -pthread -o .libs/octave.exe main.o ./.libs/liboctinterp.a /mingw/sources/octave-3.6.2~~/liboctave/.libs/liboctave.a -L=c:/mingw/bin/../lib/gcc/mingw32/4.7.0 -L=c:/mingw/bin/../lib/gcc -L=c:/mingw/bin/../lib/gcc/mingw32/4.7.0/../../../../mingw32/lib -L=c:/mingw/bin/../lib/gcc/mingw32/4.7.0/../../.. -lfltk_gl -lfltk -lole32 -luuid -lcomctl32 -LC:/MinGW/lib /mingw/lib/libfontconfig.dll.a -L=C:/MinGW/lib /mingw/lib/libfreetype.dll.a -lz -lbz2 /mingw/lib/libexpat.dll.a -lopengl32 -lglu32 ../liboctave/.libs/liboctave.a /mingw/sources/octave-3.6.2~~/libcruft/.libs/libcruft.a /mingw/lib/libarpack.a /mingw/lib/libfftw3.a -lreadline -ltermcap /mingw/lib/libpcre.dll.a ../libcruft/.libs/libcruft.a -llapack -lblas -lgfortran -lquadmath -liberty -lgdi32 -lws2_32 -luser32 -lkernel32 -pthread -L/mingw/lib
I dumped the make log to a file and the file is about 39MB!! Just full of errors like above.
I'm very much thankful if someone can help me to get over this.

R package installation is successful on all machines but one

We are a team working on an R package containing C/C++ code. The package can successfully be installed on all the machines but one. These all run the same version of Mac OS X. I have provided the log files for the installation of the package on my computer (success) and a colleague's computer (error). The package depends on the Rcpp package and the GSL library, both of which were successfully installed on both machines.
My Computer
WARNING: ignoring environment value of R_HOME
* installing to library '/Users/dejayn/R/x86_64-apple-darwin10.8.0-library/2.15'
* installing *source* package 'mrenci' ...
** libs
*** arch - x86_64
/opt/local/bin/g++-mp-4.5 -I/opt/local/lib/R/include -I/opt/local/lib/R/include/x86_64 -DNDEBUG -fopenmp -fopenmp -I/opt/local/include -I"/Users/dejayn/R/x86_64-apple-darwin10.8.0-library/2.15/Rcpp/include" -fPIC -pipe -O2 -m64 -c MRMRTree.cc -o MRMRTree.o
/opt/local/bin/g++-mp-4.5 -I/opt/local/lib/R/include -I/opt/local/lib/R/include/x86_64 -DNDEBUG -fopenmp -fopenmp -I/opt/local/include -I"/Users/dejayn/R/x86_64-apple-darwin10.8.0-library/2.15/Rcpp/include" -fPIC -pipe -O2 -m64 -c Matrix.cc -o Matrix.o
/opt/local/bin/g++-mp-4.5 -I/opt/local/lib/R/include -I/opt/local/lib/R/include/x86_64 -DNDEBUG -fopenmp -fopenmp -I/opt/local/include -I"/Users/dejayn/R/x86_64-apple-darwin10.8.0-library/2.15/Rcpp/include" -fPIC -pipe -O2 -m64 -c MiMBuilder.cc -o MiMBuilder.o
/opt/local/bin/g++-mp-4.5 -I/opt/local/lib/R/include -I/opt/local/lib/R/include/x86_64 -DNDEBUG -fopenmp -fopenmp -I/opt/local/include -I"/Users/dejayn/R/x86_64-apple-darwin10.8.0-library/2.15/Rcpp/include" -fPIC -pipe -O2 -m64 -c SymmetricMatrix.cc -o SymmetricMatrix.o
/opt/local/bin/g++-mp-4.5 -I/opt/local/lib/R/include -I/opt/local/lib/R/include/x86_64 -DNDEBUG -fopenmp -fopenmp -I/opt/local/include -I"/Users/dejayn/R/x86_64-apple-darwin10.8.0-library/2.15/Rcpp/include" -fPIC -pipe -O2 -m64 -c adaptor.cc -o adaptor.o
/opt/local/bin/g++-mp-4.5 -I/opt/local/lib/R/include -I/opt/local/lib/R/include/x86_64 -DNDEBUG -fopenmp -fopenmp -I/opt/local/include -I"/Users/dejayn/R/x86_64-apple-darwin10.8.0-library/2.15/Rcpp/include" -fPIC -pipe -O2 -m64 -c memory.cc -o memory.o
/opt/local/bin/g++-mp-4.5 -I/opt/local/lib/R/include -I/opt/local/lib/R/include/x86_64 -DNDEBUG -fopenmp -fopenmp -I/opt/local/include -I"/Users/dejayn/R/x86_64-apple-darwin10.8.0-library/2.15/Rcpp/include" -fPIC -pipe -O2 -m64 -c tools.cc -o tools.o
/opt/local/bin/g++-mp-4.5 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/opt/local/lib -o mrenci.so MRMRTree.o Matrix.o MiMBuilder.o SymmetricMatrix.o adaptor.o memory.o tools.o /Users/dejayn/R/x86_64-apple-darwin10.8.0-library/2.15/Rcpp/lib/x86_64/libRcpp.a -fopenmp -fopenmp -L/opt/local/lib/R/lib/x86_64 -lR
installing to /Users/dejayn/R/x86_64-apple-darwin10.8.0-library/2.15/mrenci/libs/x86_64
** R
** preparing package for lazy loading
** testing if installed package can be loaded
* DONE (mrenci)
Colleague's Computer
WARNING: ignoring environment value of R_HOME
* installing to library '/Library/Frameworks/R.framework/Versions/2.15/Resources/library'
* installing *source* package 'mrenci' ...
** libs
*** arch - x86_64
g++ -arch x86_64 -I/Library/Frameworks/R.framework/Resources/include -I/Library/Frameworks/R.framework/Resources/include/x86_64 -DNDEBUG  -fopenmp -I/usr/local/include -I"/Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include"   -fPIC  -g -O2  -c MRMRTree.cc -o MRMRTree.o
MRMRTree.cc: In member function 'double* const MRMRTree::bootstrap(unsigned int)':
MRMRTree.cc:73: warning: iteration variable 'i' is unsigned
g++ -arch x86_64 -I/Library/Frameworks/R.framework/Resources/include -I/Library/Frameworks/R.framework/Resources/include/x86_64 -DNDEBUG  -fopenmp -I/usr/local/include -I"/Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include"   -fPIC  -g -O2  -c Matrix.cc -o Matrix.o
g++ -arch x86_64 -I/Library/Frameworks/R.framework/Resources/include -I/Library/Frameworks/R.framework/Resources/include/x86_64 -DNDEBUG  -fopenmp -I/usr/local/include -I"/Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include"   -fPIC  -g -O2  -c MiMBuilder.cc -o MiMBuilder.o
MiMBuilder.cc: In member function 'Matrix* const MiMBuilder::createMiM(unsigned int*, unsigned int, unsigned int*, unsigned int)':
MiMBuilder.cc:102: warning: iteration variable 'i' is unsigned
g++ -arch x86_64 -I/Library/Frameworks/R.framework/Resources/include -I/Library/Frameworks/R.framework/Resources/include/x86_64 -DNDEBUG  -fopenmp -I/usr/local/include -I"/Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include"   -fPIC  -g -O2  -c SymmetricMatrix.cc -o SymmetricMatrix.o
g++ -arch x86_64 -I/Library/Frameworks/R.framework/Resources/include -I/Library/Frameworks/R.framework/Resources/include/x86_64 -DNDEBUG  -fopenmp -I/usr/local/include -I"/Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include"   -fPIC  -g -O2  -c adaptor.cc -o adaptor.o
g++ -arch x86_64 -I/Library/Frameworks/R.framework/Resources/include -I/Library/Frameworks/R.framework/Resources/include/x86_64 -DNDEBUG  -fopenmp -I/usr/local/include -I"/Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include"   -fPIC  -g -O2  -c memory.cc -o memory.o
g++ -arch x86_64 -I/Library/Frameworks/R.framework/Resources/include -I/Library/Frameworks/R.framework/Resources/include/x86_64 -DNDEBUG  -fopenmp -I/usr/local/include -I"/Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include"   -fPIC  -g -O2  -c tools.cc -o tools.o
g++ -arch x86_64 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/usr/local/lib -o mrenci.so MRMRTree.o Matrix.o MiMBuilder.o SymmetricMatrix.o adaptor.o memory.o tools.o /Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/lib/x86_64/libRcpp.a -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
installing to /Library/Frameworks/R.framework/Versions/2.15/Resources/library/mrenci/libs/x86_64
** R
** preparing package for lazy loading
** testing if installed package can be loaded
Error in dyn.load(file, DLLpath = DLLpath, ...) :
 unable to load shared object '/Library/Frameworks/R.framework/Versions/2.15/Resources/library/mrenci/libs/x86_64/mrenci.so':
 dlopen(/Library/Frameworks/R.framework/Versions/2.15/Resources/library/mrenci/libs/x86_64/mrenci.so, 6): Symbol not found: _GOMP_critical_name_end
 Referenced from: /Library/Frameworks/R.framework/Versions/2.15/Resources/library/mrenci/libs/x86_64/mrenci.so
 Expected in: flat namespace
in /Library/Frameworks/R.framework/Versions/2.15/Resources/library/mrenci/libs/x86_64/mrenci.so
Error: loading failed
Execution halted
ERROR: loading failed
* removing '/Library/Frameworks/R.framework/Versions/2.15/Resources/library/mrenci'
At first, the installation on my colleague's computer would result in the compilation of the package for both architectures, upon which g++ complained about an unknown -arch argument. This issue, however, appears to have been mitigated by forcing the targeting of a single architecture x86_64. It is also worth noting that as a result of these errors, all computers now have several versions of R and g++. Is this an issue with the linker? Does the same compiler need to be used for both R and its packages? In the case of my computer, I never explicitly asked for g++-mp-4.5 to be used rather than the default g++ (version 4.2), so I figured R automatically detects it.
In case this is of any help, here is what my Makevars contains:
PKG_LIBS=`$(R_HOME)/bin/Rscript -e "Rcpp:::LdFlags()"` $(SHLIB_OPENMP_CFLAGS) -fopenmp
PKG_CPPFLAGS=$(SHLIB_OPENMP_CXXFLAGS) -fopenmp
PKG_CFLAGS=$(SHLIB_OPENMP_CFLAGS) -fopenmp
The $(SHLIB_OPENMP_*FLAGS) flags seem to be defined only on my computer; -fopenmp flags were explicitly added for the package to work on all the machines.
Has anyone experienced similar issues? Any help would be appreciated.
I changed my colleague's ~/.R/Makevars to conform to my configs
LDFLAGS=-L/opt/local/lib
CC=/opt/local/bin/gcc-mp-4.5 -std=gnu99
CXX=/opt/local/bin/g++-mp-4.5
CPP=/opt/local/bin/gcc-mp-4.5 -std=gnu99 -E
CXXCPP=/opt/local/bin/g++-mp-4.5 -E
CFLAGS=-pipe -O2 -m64
CXXFLAGS=-pipe -O2 -m64
SHLIB_CXXLD=/opt/local/bin/g++-mp-4.5
SHLIB_CXXLDFLAGS=-dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress
SHLIB_LD=/opt/local/bin/gcc-mp-4.5 -std=gnu99
SHLIB_LDFLAGS=-dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress
Additionally, the --no-multiarch argument was used when issuing the installation command. And it now works on his computer.
The problem was because the use of openMP was hardwired (no checks) inside the code and clang did not support openMP at the same I asked the question. My colleague's R was installed using the default (Xcode) compiler when we were trying to use gcc via Mac Ports.

Resources