I am trying to compile boost C++ using clang.
./b2 --prefix=~/boost --includedir=~/boost/include --libdir=~/boost/lib toolset=clang cxxflags="-std=c++11 -stdlib=libc++ -isystem ~/libcxx/include/" linkflags="-stdlib=libc++ -L ~/libcxx/lib/"
When I see log file it gives error saying
Undefined symbols for architecture x86_64:
"boost::system::system_category()", referenced from:
__GLOBAL__I_a in exceptions.o
"boost::system::generic_category()", referenced from:
__GLOBAL__I_a in exceptions.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
my default clang is clang-mp-3.3. Can anyone please help me figure out what this problem is.
After searching for the reason of error in the web I found this which explain about compiling boost with clang. I am not sure why adding define=BOOST_SYSTEM_NO_DEPRECATED made it worked. Please do comment anyone who knows why it worked. I was then able to compile with no error but I still see some warnings but it worked for me for now.
The default clang I am using is (clang-mp-3.3)
$ clang -v
clang version 3.3 (tags/RELEASE_33/final)
Target: x86_64-apple-darwin11.4.2
Thread model: posix
./bootstrap.sh --with-toolset=clang --without-libraries=mpi,python,graph_parallel
./b2 clean
./b2 toolset=clang cxxflags="-std=c++11 -stdlib=libc++" linkflags="-stdlib=libc++" define=BOOST_SYSTEM_NO_DEPRECATED
Related
I'm having trouble compiling a project requiring OpenMP using CMake and clang, I set my CMakeLists.txt like this
cmake_minimum_required(VERSION 3.20)
project(cmat C)
set(CMAKE_C_STANDARD 11)
include_directories("/usr/local/include" "/usr/local/opt/llvm/include")
link_directories("/usr/local/lib" "/usr/local/opt/llvm/lib")
add_library(cmat SHARED cmat.c Calculation/_Basic_Calculate_.c Calculation/_Basic_Calculate_.h)
And when I started to build my project, it gave error
Undefined symbols for architecture x86_64:
"_omp_get_thread_num", referenced from:
_NmMulMat in _Basic_Calculate_.c.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[3]: *** [libcmat.dylib] Error 1
make[2]: *** [CMakeFiles/cmat.dir/all] Error 2
make[1]: *** [CMakeFiles/cmat.dir/rule] Error 2
make: *** [cmat] Error 2
I've tried some of the other answers like this and this, but they just don't work for me.
The clang version for my Mac is 13.0.0 and CMake is of 3.21.3_1, I'm using Clion as IDE, and such command will work when compiling files by shell
clang -Xpreprocessor -fopenmp -I/usr/local/include -L/usr/local/lib -lomp filename.c -o output
Great appreciate for your help.
You need to add -fopenmp to the linker flags as well by providing -DCMAKE_EXE_LINKER_FLAGS=-fopenmp [and any other options like -g].
In CLion (which I don't use) this would be specified in Preferences ->
Build, Execution, Deployment -> CMake -> CMake options as far as I understand the documentation.
Also please note that explicitly linking with -lomp is probably the wrong strategy, that happening should be a side-effect of specifying -fopenmp.
I'm having trouble getting the sandboxed_server example from RInside/examples/sandboxed_server working on xcode. I have OS X Yosemite 10.10.1.
I get the following error:
clang++ server/rinsideserver.o common/binarystream.o datatypes/bar.o datatypes/foo.o example_server.o -F/Library/Frameworks/R.framework/.. -framework R -llzma -lz -licucore -lm -liconv -L/Library/Frameworks/R.framework/Resources/lib -lRblas -L/Library/Frameworks/R.framework/Resources/lib -lRlapack /Library/Frameworks/R.framework/Versions/3.1/Resources/library/RInside/lib/libRInside.a -o example_server
Undefined symbols for architecture x86_64:
"RInside::set_callbacks(Callbacks*)", referenced from:
_main in example_server.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: *** [example_server] Error 1
Command /usr/bin/make failed with exit code 2
I have not been able to get any example that uses callbacks to work. Examples (from standard examples) that don't use callbacks do work.
I've uncommented #define RINSIDE_CALLBACKS in RInsideConfig.h. I've reinstalled the source files through R/CRAN from source- as was suggested on another post.
I did modify the code in sandboxed_server to get CLOCK_MONOTONIC to work on mac- but nothing other than that.
I'd really like to get this example working. Any help would be greatly appreciated!
I am trying to build a library that only has static references to libgfortran (and preferably libgcc also).
However, if I use the linker flags
-static -lgfortran -static-libgfortran -static-libgcc
on OS X I get
ld: library not found for -lcrt0.o
collect2: error: ld returned 1 exit status
and if I try to use
-shared -lgfortran -static-libgfortran
I get
Undefined symbols for architecture x86_64:
"_quadmath_snprintf", referenced from:
_write_float in libgfortran.a(write.o)
"_strtoflt128", referenced from:
__gfortrani_convert_real in libgfortran.a(read.o)
__gfortrani_convert_infnan in libgfortran.a(read.o)
and everything compiles fine (but has a dynamic link to libgfortran and libgcc) if I use -dynamiclib -lgfortran.
It would appear that gcc is not build statically on OS X.
How do I build my library so that end-users don't need to have gfortran or gcc installed?
I'm using the macports version of gcc but I'm prepared to use another distributor of gfortran/gcc if it allows me to do this.
-dynamiclib -lgfortran -static-libgfortran \
/opt/local/lib/gcc47/libquadmath.a -static-libgcc
seems to do the trick!
The bizarre thing was figuring out that I needed to add a full path to the libquadmath.a, which feels like a bug with gcc/gfortran to be honest.
I know there are several questions regarding this. I have looked through them all but still haven't found an answer.
I'm trying to use SDL with xCode on my Mac. I'm using xCode 4.5
I followed this tutorial exactly, twice! I even tried a second tutorial which was basically the same and it still didnt compile.
When i compile i get this error:
Ld /Users/shardy/Library/Developer/Xcode/DerivedData/SDL_SetUp-efqnmqdzqqtkktbodsopeytuwjxt/Build/Products/Debug/SDL_SetUp normal x86_64
cd "/Users/shardy/Desktop/shardy/C++ Programs/GlutApps/SDL_SetUp"
setenv MACOSX_DEPLOYMENT_TARGET 10.7
/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.8.sdk -L/Users/shardy/Library/Developer/Xcode/DerivedData/SDL_SetUp-efqnmqdzqqtkktbodsopeytuwjxt/Build/Products/Debug -F/Users/shardy/Library/Developer/Xcode/DerivedData/SDL_SetUp-efqnmqdzqqtkktbodsopeytuwjxt/Build/Products/Debug -F/Library/Frameworks -filelist /Users/shardy/Library/Developer/Xcode/DerivedData/SDL_SetUp-efqnmqdzqqtkktbodsopeytuwjxt/Build/Intermediates/SDL_SetUp.build/Debug/SDL_SetUp.build/Objects-normal/x86_64/SDL_SetUp.LinkFileList -mmacosx-version-min=10.7 -stdlib=libc++ -framework SDL -framework Cocoa -o /Users/shardy/Library/Developer/Xcode/DerivedData/SDL_SetUp-efqnmqdzqqtkktbodsopeytuwjxt/Build/Products/Debug/SDL_SetUp
Undefined symbols for architecture x86_64:
"_main", referenced from:
start in crt1.10.6.o
(maybe you meant: _SDL_main)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Followed by:
"_main", referenced from:
Start in crt1.10.6.o
(maybe you meant:_SDL_main)
Symbol(s) not found for architecture x86_64
Linker command failed with exit code 1 (use -v to see invocation)
I was originally using xCode 4.3 and it wouldnt compile, so i updated to xCode to 4.5 thinking maybe xCode was causing issues and tried everything again, but unfortunately, still did not compile...
I am not experienced enough to know how to fix this and i am out of relatable threads to read...
Thanks.
I have succesfully compiled the LLVM kalidoscope examples in C.
Now I'm extending the code with:
#include "llvm/Support/CommandLine.h"
static cl::opt<std::string> InputFilename(cl::Positional, cl::desc("<input file>"), cl::Required);
int mail(...
now i compile using:
clang++ -g toy.cpp llvm-config --cppflags --ldflags --libs all -O3 -o toy
and after this change i receive the following error:
Undefined symbols for architecture x86_64:
"typeinfo for llvm::cl::GenericOptionValue", referenced from:
typeinfo for llvm::cl::OptionValueCopy<std::string> in toy-Pq1GSI.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
What could be wrong, and how can i fix it?
Versions:
clang++ -v Apple clang version 4.1 (tags/Apple/clang-421.11.66) (based on LLVM 3.1svn) Target: x86_64-apple-darwin12.2.0 Thread model: posix
brew info llvm llvm: stable 3.2 (bottled), HEAD http://llvm.org/ /usr/local/Cellar/llvm/3.2 (628 files, 106M) * https://github.com/mxcl/homebrew/commits/master/Library/Formula/llvm.rb
==> Options
--all-targets Build all target backends
--universal Build a universal binary
--rtti Build with C++ RTTI
--shared Build LLVM as a shared library
--with-clang Build Clang C/ObjC/C++ frontend
==> Caveats Extra tools and bindings are installed in /usr/local/Cellar/llvm/3.2/share/llvm and /usr/local/Cellar/llvm/3.2/share/clang.
It seems that changing the compile command to this is a fix:
clang++ -g toy.cpp llvm-config --cxxflags --ldflags --libs -O3 -o toy