Compile error with RcppArmadillo and R 3.1.3 and Mac Yosemite - c++

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]

Related

Rcpp does not compile on Mac OS Monterey, R 4.1.2., clang error

Trying to get Rcpp to work on R 4.1.2 on Mac OS Monterey using an Intel computer.
> library(Rcpp)
> evalCpp("2 + 2")
clang++ -mmacosx-version-min=10.13 -std=gnu++14 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I"/Library/Frameworks/R.framework/Versions/4.1/Resources/library/Rcpp/include" -I"/private/var/folders/jz/977gqfr957g_rlgw1h05152w0000gq/T/Rtmp8hmDZ5/sourceCpp-x86_64-apple-darwin17.0-1.0.8" -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -I/usr/local/include -fPIC -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -c file152f71a55f97c.cpp -o file152f71a55f97c.o
clang++ -mmacosx-version-min=10.13 -std=gnu++14 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -Wl,-rpath,/Library/Frameworks/R.framework/Resources/lib /Library/Frameworks/R.framework/Resources/lib/libc++abi.1.dylib -L/Library/Frameworks/R.framework/Resources/lib -L/usr/local/lib -o sourceCpp_2.so file152f71a55f97c.o -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
Error in sourceCpp(code = code, env = env, rebuild = rebuild, cacheDir = cacheDir, :
Error 1 occurred building shared library.
clang: error: no such file or directory: '/Library/Frameworks/R.framework/Resources/lib/libc++abi.1.dylib'
make: *** [sourceCpp_2.so] Error 1
I have followed Coatless Professor's instructions:
https://thecoatlessprofessor.com/programming/cpp/r-compiler-tools-for-rcpp-on-macos/
I believe Xcode Command Line Tools and gfortran are installed:
$which gcc
/usr/bin/gcc
$which gfortran
/usr/local/bin/gfortran
and I have removed both ~/.R/Makevars and ~/.Renviron.
Any help would be much appreciated -- thanks so much!
There is an old reference to a prior version of the clang compiler present.
In R, please type:
unlink("~/.R/Makevars")
unlink("~/.Renviron")
Please restart R and, then, try:
Rcpp::evalCpp("1+1")

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

How to fix "Unexpected token... for architecture x86_64" error when running makefile

I'm trying to install HLA-LA on my 2016 MacBookPro (running Mojave 10.14.3) but I've been having issues compiling the makefile. I've installed all the dependencies, added the bamtools and boost paths as the README describes, and added CFLAGS to specify c++11. Still, when I run the makefile I get the following error:
$ make all
/usr/local/Cellar/gcc/8.3.0/bin/g++-8 -I/usr/local/Cellar/boost/1.68.0_1/include -I/usr/local/Cellar/bamtools/2.5.1/include/bamtools -I/usr/local/Cellar/bamtools/2.5.1/src -std=c++11 -ggdb -O2 -fopenmp -std=gnu++0x -fstack-protector-all HLA-LA.cpp -c -o ../obj/HLA-LA.o;
/usr/local/Cellar/gcc/8.3.0/bin/g++-8 -I/usr/local/Cellar/boost/1.68.0_1/include -I/usr/local/Cellar/bamtools/2.5.1/include/bamtools -I/usr/local/Cellar/bamtools/2.5.1/src -std=c++11 -ggdb -O2 -fopenmp -std=gnu++0x -fstack-protector-all ../obj/Edge.o ../obj/Graph.o ../obj/GraphAndEdgeIndex.o ../obj/Node.o ../obj/HaplotypePanel.o ../obj/simpleGraphSimulator.o ../obj/LocusCodeAllocation.o ../obj/simulator.o ../obj/readSimulator.o ../obj/trueReadLevels.o ../obj/processBAM.o ../obj/protoSeeds.o ../obj/oneRead.o ../obj/oneReadPair.o ../obj/oneReadPairwithSeedChains.o ../obj/alignerBase.o ../obj/alignmentContext.o ../obj/extensionAligner.o ../obj/BWAmapper.o ../obj/Bowtie2mapper.o ../obj/statistics.o ../obj/VirtualNWUnique.o ../obj/PRGContigBAMAlignment.o ../obj/verboseSeedChain.o ../obj/HLATyper.o ../obj/pathFinder.o ../obj/linearALTs.o ../obj/oneExonPosition.o ../obj/seedChain.o ../obj/Utilities.o ../obj/HLA-LA.o -o ../bin/HLA-LA -L/usr/local/Cellar/boost/1.68.0_1/lib -L/usr/local/Cellar/bamtools/2.5.1/lib64 -L/usr/local/Cellar/zlib/1.2.11/lib -lboost_random -lboost_filesystem -lboost_system -lbamtools -lz -lboost_serialization;
collect2: fatal error: ld terminated with signal 11 [Segmentation fault: 11]
compilation terminated.
ld: unexpected token: !tapi-tbd-v3 file '/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/libSystem.tbd' for architecture x86_64
make: *** [HLA-LA] Error 1
I've seen other people with similar errors, but the recommended fixes havent worked. I've also tried specifying CLT via the path: /Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/lib/ but it doesn't change the outcome at all. I read some thread that suggested it could be an ld issue but I'm not sure how I can fix that? Here are my specs:
macOS: 10.14.3-x86_64
CLT: 10.1.0.0.1.1539992718
Xcode: 10.1

ld: library not found for -lcrypto

I am trying to run the http://iphonedevwiki.net/index.php/Theos/Setup tutorial but stuck on this step:
./make.sh
+ xcrun -sdk macosx g++ -mmacosx-version-min=10.4 -arch i386 -arch x86_64 -I. -I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.4.sdk/usr/include/libxml2 -Ilibplist/include -Ilibplist/libcnary/include -c -std=c++11 -o out/ldid.o ldid.cpp
+ xcrun -sdk macosx g++ -mmacosx-version-min=10.4 -arch i386 -arch x86_64 -I. -I/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.4.sdk/usr/include/libxml2 -Ilibplist/include -Ilibplist/libcnary/include -o out/ldid out/ldid.o out/iterator.o out/list.o out/node.o out/node_iterator.o out/node_list.o out/base64.o out/bplist.o out/bytearray.o out/hashtable.o out/plist.o out/ptrarray.o out/xplist.o -x c lookup2.c -lxml2 -framework Security -lcrypto
clang: warning: libstdc++ is deprecated; move to libc++ with a minimum deployment target of OS X 10.9 [-Wdeprecated]
clang: warning: libstdc++ is deprecated; move to libc++ with a minimum deployment target of OS X 10.9 [-Wdeprecated]
ld: library not found for -lcrypto
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Could you please help?
Check if -lcrypto is installed on your system (on a Linux system, you could try calling ldconfig -p | grep libcrypto, but if you are using macOS, try to find some equivalent)
Make sure your g++ call contains proper path if this library is at some specific location that will not be searched by g++ by default.
You can read about including libraries and header files in this stack overflow topic: https://stackoverflow.com/a/6141166/4802475

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

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