C++/R: clang: error: linker command failed with exit code 1 (use -v to see invocation) - c++

I am trying to install and run a this project. It is written in C++ and R. I follow the instructions and when I type the make command, I get this error:
R CMD SHLIB src/C/util.c src/C/factor_model_util.c src/C/pagerank.c src/C/hierarchical.c src/C/factor_model_multicontext.c src/C/factor_model_util2.cpp -o lib/c_funcs.so
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 lib/c_funcs.so src/C/util.o src/C/factor_model_util.o src/C/pagerank.o src/C/hierarchical.o src/C/factor_model_multicontext.o src/C/factor_model_util2.o -L/Library/Frameworks/R.framework/Resources/lib -lRlapack -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 -Wall -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[1]: *** [lib/c_funcs.so] Error 1
make: *** [c_funcs] Error 1
Here is my "clang --version" results:
Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn)
Target: x86_64-apple-darwin14.3.0
Thread model: posix
Does anyone know what should I do? I saw the answers about xcode projects, but here I am only trying to use make for compiling.
Thanks

I had a very similar issue, and solved it by installing the newer gfortran 4.8.2. For some reason the main page links to version 4.3.2, which causes this issue (I believe because R binaries are actually built with a newer gfortran).

Related

Mac running OpenMP, "clang: error: unsupported option '-fopenmp'"

I am new to OpenMP, and my professor gives us a project to do. There are only three files in the folder: a C++ source code a0.cpp, a header a0.h, and a Makefile. When I want to run the code in my terminal, it says:
clang: error: unsupported option '-fopenmp'
clang: error: unsupported option '-fopenmp'
make: *** [a0] Error 1
I am using a Macbook, and I do not know how to fix this. Can you help me? Thanks.
After installing libomp with homebrew using:
brew install libomp
I was able to compile an OpenMP program with this:
clang -Xpreprocessor -fopenmp -I/usr/local/include -L/usr/local/lib -lomp main.c -o main
If you are using C++, you'd likely want:
clang++ -Xpreprocessor -fopenmp -I/usr/local/include -L/usr/local/lib -lomp main.cpp -o main

Linking with LLVM LLD does not work [macos]

The following compile command with clang6.0:
LDFLAGS="-L/usr/local/opt/myllvm6.0rc1/lib -fuse-ld=lld"
CPPFLAGS="-I/usr/local/opt/myllvm6.0rc1/include -I/usr/local/opt/myllvm6.0rc1/include/c++/v1/";
clang++ -fsanitize=address $LDFLAGS $CPPFLAGS -g -v main.cpp
gives:
"/usr/local/opt/myllvm6.0rc1/bin/ld64.lld" -demangle -lto_library /usr/local/opt/myllvm6.0rc1/lib/libLTO.dylib -no_deduplicate -dynamic -arch x86_64 -macosx_version_min 10.11.0 -o a.out -L/usr/local/opt/myllvm6.0rc1/lib /var/folders/14/rc46ppds1ms2kj_mvdcxlc040000gn/T/main-113675.o -lc++ /usr/local/opt/myllvm6.0rc1/lib/clang/6.0.0/lib/darwin/libclang_rt.asan_osx_dynamic.dylib -rpath #executable_path -rpath /usr/local/opt/myllvm6.0rc1/lib/clang/6.0.0/lib/darwin -lSystem /usr/local/opt/myllvm6.0rc1/lib/clang/6.0.0/lib/darwin/libclang_rt.osx.a
warning: ignoring unknown argument: -no_deduplicate
warning: -sdk_version is required when emitting min version load command. Setting sdk version to match provided min version
Unable to find library for -lto_library
clang-6.0: error: linker command failed with exit code 1 (use -v to see invocation)
I dont understand why it cant load the /usr/local/opt/myllvm6.0rc1/lib/libLTO.dylib (it exists at this location!)
Any idea?
You are using -fuse-ld=lld which is what the LLD documentation says to do and as you can see ld64.lld is being run. However, the flag -no_deduplicate is not an lld flag; it is an OSX ld flag. The ld64.lld man page is here:
https://manpages.ubuntu.com/manpages/disco/man1/ld.lld.1.html

llvm toy example error

I am trying to run the make file of the toy example given here, but it gives me the following error:
g++ -o parser parser.o codegen.o main.o tokens.o corefn.o native.o `llvm-config
--libs` `llvm-config --ldflags` -lpthread -ldl -L/usr/bin -lz -lncurses -rdynamic
/usr/bin/ld: cannot find -lz
/usr/bin/ld: cannot find -lncurses
collect2: error: ld returned 1 exit status
Makefile:31: recipe for target 'parser' failed
make: *** [parser] Error 1
The software I am using is:
clang version 3.8.0-2ubuntu4 (tags/RELEASE_380/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Ubuntu is a virtual machine running on Windows 8.1.
Any comment will be appreciated.

SystemC on Mac error with Makefile

I need to start working on a project with SystemC. I managed to compile SystemC according to this instructions: how to use and install SystemC in terminal mac OS X?
Afterwards I adjusted the SYSTEMC_HOME variable in Makefile.config to "SYSTEMC_HOME?=~/Work/Other/systemc-2.3.1"
The problem occurs when i try to compile and run any of the provided examples.
The error I get is:
ld: unknown option: -rpath=/Users/admin/Work/Other/systemc-2.3.1/lib
clang: error: linker command failed with exit code 1
(use -void to see invocation)
The command I run is:
make -f Makefile run
And the whole output from the console:
simple_fifo admin$ make -f Makefile run
clang++ -fcolor-diagnostics -g -Wall -pedantic -Wno-long-long -Werror -L. -L.. -L /Users/admin/Work/Other/systemc-2.3.1/lib -Wl,-rpath=/Users/admin/Work/Other/systemc-2.3.1/lib -o simple_fifo.x simple_fifo.o -lsystemc -lm 2>&1 | c++filt
ld: unknown option: -rpath=/Users/admin/Work/Other/systemc-2.3.1/lib
clang: error: linker command failed with exit code 1 (use -void to see invocation)
make: *** [simple_fifo.x] Error 1
Any hints on what to look for would be highly appreciated.
= is a GNU linker feature, not Clang.
Edit examples/sysc/Makefile.rules and replace:
LDFLAG_RPATH ?= -Wl,-rpath=
with
LDFLAG_RPATH ?= -Wl,-rpath,

Compile error with RcppArmadillo and R 3.1.3 and Mac Yosemite

I have recently installed R 3.1.3. I am using a Mac with Yosemite system and my Xcode is of version 6.2.
After I source the CPP file using sourceCpp("try.cpp"), I get the following error. My try.cpp file has
#include <RcppArmadillo.h>
#include <math.h>
The error is below in R
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 -lquadmath
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [sourceCpp_15736.so] Error 1
clang++ -arch x86_64 -ftemplate-depth-256 -I/Library/Frameworks/R.framework/Resources/include -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include -I"/Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/3.1/Resources/library/RcppArmadillo/include" -fPIC -mtune=core2 -O3 -c CAR.cpp -o CAR.o
clang++ -arch x86_64 -ftemplate-depth-256 -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 sourceCpp_15736.so CAR.o -L/Library/Frameworks/R.framework/Resources/lib -lRlapack -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
Error in sourceCpp("~/RA2015/Code/BYMCAR/CAR.cpp") :
Error 1 occurred building shared library.
WARNING: The tools required to build C++ code for R were not found.
Please install Command Line Tools for XCode (or equivalent).
I have installed the command line tools for Xcode, my gfortran version is 4.9.0
But when I type
gfortran --version
It has the following error:
gfortran: warning: couldn’t understand kern.osversion ‘14.1.0
When I use R 3.1.2, I did not encounter this problem before!
Any help is appreciated!
After some finding I find a solution online.
If you have same problem with me, just type
curl -O http://r.research.att.com/libs/gfortran-4.8.2-darwin13.tar.bz2
sudo tar fvxz gfortran-4.8.2-darwin13.tar.bz2 -C /
on the terminal and sourceCpp can run smoothly.
A detailed explanation can be found at [http://www.thecoatlessprofessor.com/programming/rcpp-rcpparmadillo-and-os-x-mavericks-lgfortran-and-lquadmath-error]