Static linking library asan with gcc 4.8 - gcc

I'm compiling my test executable in this way using gcc 4.8.3:
gcc -o test -g -L/lib64 -fsanitize=address -static-libasan
Result:
/usr/bin/ld: cannot find -lasan
collect2: error: ld returned 1 exit status
Libasan is installed and if I compile without the static option it works. How can I compile the library statically?

You need to install special package to get static GCC libraries. On Ubuntu you should do
$ sudo apt-get install libgcc-4.8-dev

Related

OpenMP with g++ MacOS on Sierra

I have a makefile with the following that I'm trying to make on macOS Sierra:
CPP = g++
CPPFLAGS = -m64 -fopenmp -O3
and I keep getting the error clang: error: unsupported option '-fopenmp'.
I did
brew install libomp
brew install llvm
brew install gcc
These all were successful but I still get the same error. Would appreciate any suggestions!
There are a number of options...
As you have installed llvm with homebrew, you can compile C++ code using OpenMP with:
/usr/local/Cellar/llvm/9.0.0/bin/clang++ -fopenmp main.cpp -o main
As you have installed GCC with homebrew, you can compile C++ code using OpenMP with:
/usr/local/bin/g++-9 -fopenmp main.cpp -o main
As you have installed libomp, you can use that with the Apple-supplied clang++ (note it is not in /usr/local because it is supplied by Apple) to compile C++ with OpenMP with:
/usr/bin/clang++ -I/usr/local/include -Xpreprocessor -fopenmp -L/usr/local/lib -lomp main.cpp -o main

gcc compile, getting "clang: error: unsupported option '-fopenmp'"

I am running the command
gcc -o openmptest -fopenmp openmptest.c
however am getting the error:
clang: error: unsupported option '-fopenmp'
I am running this on Mac Mojave. In addition I am using VS code which is telling me
cannot open source file "omp.h"
for my include statement.
I think it could work if you install libomp by
brew install libomp
and then,
clang -Xpreprocessor -fopenmp -I/usr/local/include -L/usr/local/lib -lomp openmptest.c -o main
This should work, I was having the same issue and and managed to compile my code by using the above.

configure: error: CGAL library not found

My ultimate goal is to get python package graph_tool working on my system and also on ipynb if possible. I have already brew install graph-tool, as indicated here, but that's still insufficient.
So I follow Anaconda instructions here, and I make decent progress, until the CGAL Library could not be found.
Note: to comply with the Anaconda instructions, I installed anaconda3 and created a new conda environment (named py36env) to conda install all the required packages (packages that must also match with python 3.6)
The entire ./configure output. Below is a snippet:
(py36env) $ ./configure --prefix=/Users/tamtran/anaconda3/envs/py36env/ --with-python-module-path=/Users/tamtran/anaconda3/envs/py36env/lib/python3.6/site-packages --with-cgal=/Users/tamtran/anaconda3/envs/py36env/
.
.
checking whether CGAL is available in /Users/tamtran/anaconda3/envs/py36env/... no
configure: error: CGAL library not found.
The entire config.log. Below is a snippet:
configure:21200: checking whether CGAL is available in /Users/tamtran/anaconda3/envs/py36env/
configure:21236: g++ -std=gnu++14 -o conftest -fopenmp -O3 -fvisibility=default -fvisibility-inlines-hidden -Wno-deprecated -Wall -Wextra -ftemplate-backtrace-limit=0 -DNDEBUG -I/Users/tamtran/anaconda3/envs/py36env//include -pthread -I/usr/local/include -L/Users/tamtran/anaconda3/envs/py36env//lib -lCGAL -lCGAL_Core -lgmp -lboost_thread-mt -lpthread conftest.cpp -lgmp -lgmp >&5
| #include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
| #include <CGAL/convex_hull_2.h>
| typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
| CGAL::convex_hull_2(points.begin(),points.end(),std::back_inserter(result));
configure:21278: error: CGAL library not found.
CGAL_CPPFLAGS='-I/Users/tamtran/anaconda3/envs/py36env//include'
CGAL_FLAGS=''
CGAL_LDFLAGS='-L/Users/tamtran/anaconda3/envs/py36env//lib -lCGAL -lCGAL_Core -lgmp -lboost_thread-mt -lpthread'
Note: Even without the --with-cgal tag, the same issue occurs. It's also important (I think) that the CGAL search directory is within py36env because CGAL matching with python3.6 is in there, whereas CGAL-python3.5 is in conda root environment. The only differences of ./configure output without the CGAL directory are:
checking whether CGAL is available in /usr... no
checking whether CGAL is available in /usr/local... no
checking whether CGAL is available in /opt... no
checking whether CGAL is available in /opt/local... no
on mac os x You must use -lcgal (is using brew)
for example on fedora linux -lCGAL

RcppArmadillo Compile Errors on OS X Mavericks

This is a follow-up to the question at Element-Wise Matrix Multiplication in Rcpp
I have been getting a number of different kinds of errors with RcppArmadillo since upgrading to Mavericks. I have Xcode 5.0.2 and Command Line Tools installed. Also, gfortran from Homebrew. But I keep encountering the error below --
> cppFunction("arma::mat schur(arma::mat& a, arma::mat& b)
{ return(a % b); }", depends="RcppArmadillo")
ld: library not found for -lgfortran
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [sourceCpp_18474.so] Error 1
clang++ -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/usr/local/include - I"/Library/Frameworks/R.framework/Versions/3.0/Resources/library/Rcpp/include" -I"/Library/Frameworks/R.framework/Versions/3.0/Resources/library/RcppArmadillo/include" -fPIC "-mtune=native -g -O2 -Wall -pedantic -Wconversion" -c fileaf992bfb8f84.cpp -o fileaf992bfb8f84.o clang++ -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/usr/local/lib -L/usr/local/lib -o sourceCpp_18474.so fileaf992bfb8f84.o -L/Library/Frameworks/R.framework/Resources/lib -lRlapack -L/Library/Frameworks/R.framework/Resources/lib -lRblas -lgfortran /Library/Frameworks/R.framework/Versions/3.0/Resources/library/Rcpp/lib/libRcpp.a -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
Error in sourceCpp(code = code, env = env, rebuild = rebuild, showOutput = showOutput, :
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).
# Contents of Makevars
$ cat ~/.R/Makevars
CC=clang
CXX=clang++
CXXFLAGS="-mtune=native -g -O2 -Wall -pedantic -Wconversion"
FLIBS=-lgfortran
Commenting FLIBS=-lgfortran does not help and results in even more error messages --
> cppFunction("arma::mat schur(arma::mat& a, arma::mat& b) { return(a % b); }", depends="RcppArmadillo")
ld: warning: directory not found for option '-L/usr/local/lib/gcc/i686-apple-darwin8/4.2.3/x86_64'
ld: warning: directory not found for option '-L/usr/local/lib/x86_64'
ld: warning: directory not found for option '-L/usr/local/lib/gcc/i686-apple-darwin8/4.2.3'
ld: library not found for -lgfortran
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [sourceCpp_50381.so] Error 1
Thanks in advance.
Update
Following suggestions from response from Kevin and Dirk below, I re-installed Rcpp, RcppArmadillo and inline from source and updated FLIBS to point to the actual directory. This solved the issue.
# Update FLIBS in ~/.R/Makevars
FLIBS=-L/usr/local/Cellar/gfortran/4.8.2/gfortran
#Re-Install from source
install.packages(c("Rcpp","RcppArmadillo","inline"),type="source")
#Restart R
EDIT: If you're a Homebrew user, you now instead need to use brew install gcc (gfortran is no longer provided separate of gcc), and you can then follow the instructions here to get set up.
You have to symlink the libraries to /usr/local/lib manually:
ln -s /usr/local/Cellar/gfortran/4.8.2/gfortran/lib/libgfortran.* /usr/local/lib/
I thought brew link gfortran would handle this, but apparently it only symlinks the gfortran program and not the actual libraries. So, unfortunately, you have to do it yourself.
(Replace 4.8.2 with whichever version of gfortran you're using from homebrew.)
Alternatively, if you want to keep from modifying /usr/local/lib, you can use
FLIBS=-L/usr/local/Cellar/gfortran/4.8.2/gfortran
in your ~/.R/Makevars file instead, so R knows where to find the gfortran libraries.
I can only suggest you study the numerous threads on the r-sig-mac list, the different answers here on SO as well as the posts on the rcpp-devel list.
As your error comes from the failed Fortran linking, maybe also review the standard page by Simon U. as well as the tools page it points too. AFAIK you should use the (older) gfortran 4.2.* from that page with R -- but then I am not an OS X user.
Edit in late 2016: We now have more detailed instructions in section 2.16 of the Rcpp FAQ.

How to install PyGSL? (Windows 7, 64 bit, Python 2.7, GSL 1.15)

I'm trying to install PyGSL on my computer (64 bit Windows 7), with Python 2.7 and GSL 1.15 installed. I'm pretty much stuck and I would love for some extra help. GSL installed fine, but its the wrapper that's the problem. For some reason I can't build pygsl. Apparently gcc is the problem (got the same problem on another windows machine). Or it could be that pygsl appears to be using a file named AMD64 while my computer is x86. I would love to use the windows binary for pygsl, but it only exists for python 2.5, and my project needs 2.6 or higher. I've used both the windows binary for GSL and built it from source, but I get the same problem either way. I tried copying dlls from GSL into pygsl but that didn't work. Some forums mentioned a file called gsl.dll but I can't seem to find it. I've also tried to use Cygwin and to compile with minGW32 to no avail.
cmds I ran:
python setup.py install
python setup.py build
python setup.py build_ext -i
python setup.py build --compiler=mingw32
Any ideas?? Thanks.
Cheers,
Bereket
Got the same message in Cygwin as in the windows cmd prompt. Error message:
$ /cygdrive/c/Python27/python.exe setup.py build_ext -i
numpy
Forcing DISTUTILS_USE_SDK=1
Building testing ufuncs!
running build_ext
building 'errno' extension
C compiler: gcc -g -DDEBUG -DMS_WIN64 -mno-cygwin -O0 -Wall -Wstrict-prototypes
compile options: '-DSWIG_COBJECT_TYPES=1 -DGSL_RANGE_CHECK=1 -DDEBUG=1 -DNUMERIC=0 -DPYGSL_GSL_MAJOR_VERSION=1 -DPYGSL_GSL_MINOR_VERSION=15 -UNDEBUG -IC:\Users\Bereket\gsl-1.15\include -IInclude -I. -IC:\Python27\lib\site-packages\numpy\core\include -IC:\Python27\include -IC:\Python27\PC -c'
gcc -g -DDEBUG -DMS_WIN64 -mno-cygwin -O0 -Wall -Wstrict-prototypes -DSWIG_COBJECT_TYPES=1 -DGSL_RANGE_CHECK=1 -DDEBUG=1 -DNUMERIC=0 -DPYGSL_GSL_MAJOR_VERSION=1 -DPYGSL_GSL_MINOR_VERSION=15 -UNDEBUG -IC:\Users\Bereket\gsl-1.15\include -IInclude -I. -IC:\Python27\lib\site-packages\numpy\core\include -IC:\Python27\include -IC:\Python27\PC -c src/init/errorno.c -o build\temp.win-amd64-2.7\Release\src\init\errorno.o
Found executable C:\cygwin\bin\gcc.exe
gcc -g -mno-cygwin -shared build\temp.win-amd64-2.7\Release\src\init\errorno.o -LC:\Users\Bereket\gsl-1.15\lib -LC:\Python27\libs -LC:\Python27\PCbuild\amd64 -lgsl -lgslcblas -lm -lpython27 -lmsvcr90 -o C:\Python27\Lib\pygsl-0.9.5\pygsl\errno.pyd
build\temp.win-amd64-2.7\Release\src\init\errorno.o: In function `add_errno':
/cygdrive/c/Python27/Lib/pygsl-0.9.5/src/init/errorno.c:14: undefined reference to `__imp__PyInt_FromLong'
/cygdrive/c/Python27/Lib/pygsl-0.9.5/src/init/errorno.c:20: undefined reference to `__imp__PyDict_SetItemString'
build\temp.win-amd64-2.7\Release\src\init\errorno.o: In function `initerrno':
/cygdrive/c/Python27/Lib/pygsl-0.9.5/src/init/errorno.c:37: undefined reference to `__imp__Py_InitModule4_64'
/cygdrive/c/Python27/Lib/pygsl-0.9.5/src/init/errorno.c:40: undefined reference to `__imp__PyModule_GetDict'
collect2: ld returned 1 exit status
error: Command "gcc -g -mno-cygwin -shared build\temp.win-amd64-2.7\Release\src\init\errorno.o -LC:\Users\Bereket\gsl-1.15\lib -LC:\Python27\libs -LC:\Python27\PCbuild\amd64 -lgsl -lgslcblas -lm -lpython27 -lmsvcr90 -o C:\Python27\Lib\pygsl-0.9.5\pygsl\errno.pyd" failed with exit status 1
I'm pretty sure now that my GSL install with Cygwin failed / had unresolved dependencies. I'm now trying to install it with visual studio 2010. Here are some good sites for doing that:
Instructions
Alt Method
Installing the Python 2.7 compiler for Windows is a good place to start
http://www.microsoft.com/en-gb/download/details.aspx?id=44266
Running python setup.py build_ext --inplace does the trick for me.
If this doesn't work let me know. You might need to add an environment variable.
Is your Python 32 or 64? To check open Python and do
import sys
sys.versions

Resources