library not found for -lrt - c

I am compiling a Makefile that needs -lrt library. My compiler is gcc-8 and I am currently working on a OSX Mojave OS.
I run from terminal using the make command, and I get the following error:
ld: library not found for -lrt
collect2: error: ld returned 1 exit status
make: *** [eflomal] Error 1
I have already tried to remove -lrt from LDFLAGS but in that case I get other errors:
/usr/local/Cellar/gcc/8.3.0/bin/gcc-8 -lm -lgomp -fopenmp eflomal.o -o eflomal
Undefined symbols for architecture x86_64:
"___kmpc_critical", referenced from:
_.omp_outlined..57 in eflomal.o
_.omp_outlined..61 in eflomal.o
"___kmpc_end_critical", referenced from:
_.omp_outlined..57 in eflomal.o
_.omp_outlined..61 in eflomal.o
"___kmpc_for_static_fini", referenced from:
_.omp_outlined. in eflomal.o
_.omp_outlined..57 in eflomal.o
_.omp_outlined..61 in eflomal.o
"___kmpc_for_static_init_4", referenced from:
_.omp_outlined. in eflomal.o
_.omp_outlined..57 in eflomal.o
_.omp_outlined..61 in eflomal.o
"___kmpc_fork_call", referenced from:
_main in eflomal.o
_align in eflomal.o
ld: symbol(s) not found for architecture x86_64
The Makefile header is the following:
export CXX=/usr/local/Cellar/gcc/8.3.0/bin/g++-8
export CC=/usr/local/Cellar/gcc/8.3.0/bin/gcc-8
CFLAGS=-Ofast -march=native -Wall --std=gnu99 -Wno-unused-function -g -fopenmp
# This is more suitable for debugging:
#CFLAGS=-Og -Wall --std=gnu99 -Wno-unused-function -g -fopenmp
#LDFLAGS=-lm -lrt -lgomp -fopenmp
LDFLAGS=-lm -lgomp -fopenmp -lrt
The first two lines are needed to use gcc compiler instead of clang (default on OSX).
Any idea on how to fix the problem?

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:

Jansson on Xcode

I am trying to test Jansson on Xcode 7.3.1. I installed according to the instructions, then used cMake when that didn't work, which also didn't work. I think Xcode is having trouble finding the Jansson library. I have modified the project header and library paths in many different ways, after extensive suggestions from searching out this problem. Xcode is able to find the header. Note also that I am able to install Jansson and run it in Eclipse. Any insight would be appreciated.
Here is the error log from Xcode:
Ld /Users/corrychapman/Library/Developer/Xcode/DerivedData/JanssonDev-dispcmnteuwiedaiazlbkwtztfcu/Build/Products/Debug/JanssonDev normal x86_64
cd /Users/corrychapman/Desktop/jansson-2.11/JanssonDev
export MACOSX_DEPLOYMENT_TARGET=10.11
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -L/Users/corrychapman/Library/Developer/Xcode/DerivedData/JanssonDev-dispcmnteuwiedaiazlbkwtztfcu/Build/Products/Debug -L/usr/local/lib -L/Users/corrychapman/Desktop/jansson-2.11/JanssonDev -F/Users/corrychapman/Library/Developer/Xcode/DerivedData/JanssonDev-dispcmnteuwiedaiazlbkwtztfcu/Build/Products/Debug -filelist /Users/corrychapman/Library/Developer/Xcode/DerivedData/JanssonDev-dispcmnteuwiedaiazlbkwtztfcu/Build/Intermediates/JanssonDev.build/Debug/JanssonDev.build/Objects-normal/x86_64/JanssonDev.LinkFileList -mmacosx-version-min=10.11 -Xlinker -no_deduplicate -Xlinker -dependency_info -Xlinker /Users/corrychapman/Library/Developer/Xcode/DerivedData/JanssonDev-dispcmnteuwiedaiazlbkwtztfcu/Build/Intermediates/JanssonDev.build/Debug/JanssonDev.build/Objects-normal/x86_64/JanssonDev_dependency_info.dat -o /Users/corrychapman/Library/Developer/Xcode/DerivedData/JanssonDev-dispcmnteuwiedaiazlbkwtztfcu/Build/Products/Debug/JanssonDev
Undefined symbols for architecture x86_64:
"_json_array_get", referenced from:
_main in main.o
"_json_array_size", referenced from:
_main in main.o
"_json_delete", referenced from:
_json_decref in main.o
"_json_loads", referenced from:
_main in main.o
"_json_object_get", referenced from:
_main in main.o
"_json_string_value", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Found it. Build Settings -> Linking -> Other Linker Flags: -ljansson

Trying to make a simple Makefile fails

I have 3 files, main.c, lists.c, and lists.h.
Im trying to write a Makefile with all the files are in the same directory:
maman21: lists.c lists.h main.c
gcc -g -Wall -ansi main.c -o maman21 -lm
going to the folder through terminal and using make shows me this message:
gcc -g -Wall -ansi main.c -o maman21 -lm
Undefined symbols for architecture x86_64: "_linkedListWay",
referenced from:
_main in main-C9dUT4.o "_reallocWay", referenced from:
_main in main-C9dUT4.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: *** [maman21] Error 1
reallocWay and linkedListWay are to functions I'm using in the file.
Thank you for your help.
You've failed to include the lists.c file in the compiler invocation so it doesn't get built.
It should be:
CFLAGS=-g -Wall -ansi
LDLIBS=-lm
maman21: main.o lists.o
main.o: main.c
lists.o: lists.c lists.h
The above uses implicit Makefile rules, it "knows" how to convert a C file to an object (.o) file.
Also, is it normal for Clang to be called gcc?

"Symbols not found for Architecture x86_64" for a MEX file that uses the CPLEX API in C

I'm currently writing a MEX file in MATLAB that uses the CPLEX API in C to solve linear programming problems. Unfortunately, I run into a "symbol(s) not found for architecture x86_64" problem when I attempt to compile and I have no idea of how to solve it.
Some basic information:
I can compile yprime.c and other MEX files that do not use the CPLEX API
I am using MATLAB 2011b on Mac OSX 10.7.2
I am using the GCC 4.2 package included in XCode 4.2.
I already applied the XCode 4.2 Patch for MATLAB
I would greatly appreciate any advice people may have. I'm including a verbose error report below.
-> mexopts.sh sourced from directory (DIR = $PREF_DIR)
FILE = /Users/berk/.matlab/R2011b/mexopts.sh
----------------------------------------------------------------
-> MATLAB = /Applications/MATLAB_R2011b.app
-> CC = llvm-gcc-4.2
-> CC flags:
CFLAGS = -fno-common -no-cpp-precomp -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.6.sdk -mmacosx-version-min=10.5 -fexceptions -Wall
CDEBUGFLAGS = -g
COPTIMFLAGS = -O2 -DNDEBUG
CLIBS = -L/Applications/MATLAB_R2011b.app/bin/maci64 -lmx -lmex -lmat -lstdc++
arguments = -DMX_COMPAT_32
-> CXX = llvm-g++-4.2
-> CXX flags:
CXXFLAGS = -fno-common -no-cpp-precomp -fexceptions -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.6.sdk -mmacosx-version-min=10.5
CXXDEBUGFLAGS = -g
CXXOPTIMFLAGS = -O2 -DNDEBUG
CXXLIBS = -L/Applications/MATLAB_R2011b.app/bin/maci64 -lmx -lmex -lmat -lstdc++
arguments = -DMX_COMPAT_32
-> FC = gfortran
-> FC flags:
FFLAGS = -fexceptions -m64 -fbackslash
FDEBUGFLAGS = -g
FOPTIMFLAGS = -O
FLIBS = -L/Applications/MATLAB_R2011b.app/bin/maci64 -lmx -lmex -lmat -L -lgfortran -L -lgfortranbegin
arguments = -DMX_COMPAT_32
-> LD = llvm-gcc-4.2
-> Link flags:
LDFLAGS = -Wl,-twolevel_namespace -undefined error -arch x86_64 -Wl,-syslibroot,/Developer/SDKs/MacOSX10.6.sdk -mmacosx-version-min=10.5 -bundle -Wl,-exported_symbols_list,/Applications/MATLAB_R2011b.app/extern/lib/maci64/mexFunction.map
LDDEBUGFLAGS = -g
LDOPTIMFLAGS = -O
LDEXTENSION = .mexmaci64
arguments =
-> LDCXX =
-> Link flags:
LDCXXFLAGS =
LDCXXDEBUGFLAGS =
LDCXXOPTIMFLAGS =
LDCXXEXTENSION =
arguments =
----------------------------------------------------------------
-> llvm-gcc-4.2 -c -I/Users/berk/Applications/IBM/ILOG/CPLEX_Studio_Academic123/cplex/include/ilcplex/ -I/Applications/MATLAB_R2011b.app/extern/include -I/Applications/MATLAB_R2011b.app/simulink/include -DMATLAB_MEX_FILE -fno-common -no-cpp-precomp -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.6.sdk -mmacosx-version-min=10.5 -fexceptions -Wall -DMX_COMPAT_32 -O2 -DNDEBUG "addcutsmx.c"
addcutsmx.c:488:4: warning: "/*" within comment
addcutsmx.c:37: warning: 'free_and_null' declared 'static' but never defined
addcutsmx.c:38: warning: 'usage' declared 'static' but never defined
-> llvm-gcc-4.2 -O -Wl,-twolevel_namespace -undefined error -arch x86_64 -Wl,-syslibroot,/Developer/SDKs/MacOSX10.6.sdk -mmacosx-version-min=10.5 -bundle -Wl,-exported_symbols_list,/Applications/MATLAB_R2011b.app/extern/lib/maci64/mexFunction.map -o "addcutsmx.mexmaci64" addcutsmx.o -L/Applications/MATLAB_R2011b.app/bin/maci64 -lmx -lmex -lmat -lstdc++
Undefined symbols for architecture x86_64:
"_CPXLopenCPLEX", referenced from:
_mexFunction in addcutsmx.o
"_CPXLcreateprob", referenced from:
_mexFunction in addcutsmx.o
"_CPXLchgobjsen", referenced from:
_mexFunction in addcutsmx.o
"_CPXLnewcols", referenced from:
_mexFunction in addcutsmx.o
"_CPXLaddrows", referenced from:
_mexFunction in addcutsmx.o
"_CPXLlpopt", referenced from:
_mexFunction in addcutsmx.o
"_CPXLsolution", referenced from:
_mexFunction in addcutsmx.o
"_CPXLgetbase", referenced from:
_mexFunction in addcutsmx.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
mex: link of ' "addcutsmx.mexmaci64"' failed.
Error using mex (line 206)
Unable to complete successfully.
You seem to be missing -lcplex or the relevant linking instruction for cplex on your system.
The User manual says the correct include and linking parameters are in readme.html of your cplex distribution, along with sample projects and makefiles.
From Using Cplex with Matlab it says you have specify the full library linking path and include path. Depending on what you are doing you may need to also specify -lilocplex to mex.
E.g. mex -I/cplex_include_fullpath -L/cplex_library_fullpath -lcplex file.c

installing Postgis 1.5.2 with PostGres 9.0.3 fails

on Mac OS X Snow Leopard, I get the following error on make
gcc -g -O2 -fno-common -DPIC -Wall -Wmissing-prototypes stringbuffer.o shpopen.o dbfopen.o safileio.o getopt.o shp2pgsql-core.o shp2pgsql-cli.o ../liblwgeom/liblwgeom.a -o shp2pgsql -liconv -lm
Undefined symbols:
"_libiconv_open", referenced from:
_utf8 in shp2pgsql-core.o
"_libiconv_close", referenced from:
_utf8 in shp2pgsql-core.o
_utf8 in shp2pgsql-core.o
"_libiconv", referenced from:
_utf8 in shp2pgsql-core.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make[1]: *** [shp2pgsql] Error 1
make: *** [loaderdumper] Error 2
What is the solution?
It seems there's some problem with libconv. Either it isn'l installed or it isn't correctly linked. Try installing it first.

Resources