I have been trying to use Clang's address code sanitizer, but the linker will not have it. The linker may be "ld", though my CMAKE settings assure me that clang is the linker.
Added -fsanitize=address to compiler and linker flags.
Error:
Undefined symbols for architecture x86_64:
___asan_after_dynamic_init
...
___asan_before_dynamic_init
...
etc.
ld: symbol(s) not found for architecture x86_64 <<<< **suspicious**
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Environment: MacOS
clang: Apple LLVM version 8.0.0 (clang-800.0.38)
cmake: 3.7.1
CMAKE_CXX_COMPILER = /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ (redirects to clang)
CMAKE_CXX_COMPILER_ID = Clang
Compiler Flags: -O0 -g -fsanitize=address
CMAKE_LINKER = /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ (redirects to clang)
CMAKE_CXX_LINK_EXECUTABLE = CMAKE_CXX_COMPILER FLAGS CMAKE_CXX_LINK_FLAGS LINK_FLAGS OBJECTS -o TARGET LINK_LIBRARIES
CMAKE_CXX_LINK_FLAGS = -Wl,-search_paths_first -Wl,-headerpad_max_install_names -fsanitize=address -v
Solution from here
Pass the -fsanitize=address flag to the linker as well as the compiler.
-DCMAKE_EXE_LINKER_FLAGS="-fsanitize=address"
Related
I'm building a set of libraries on Mac M1 (arm64 architecture), Big Sur and use GNU11 compilers (gcc, gfortran, g++), as well as openmpi 4.1.2 for multi-processing. All is done as a command-line using a Terminal.app, which is running as Apple native, and NOT using Rosetta Translation. The steps taken: 1) GCC, g++, gfortran are installed using "brew install gcc#11", then symbolic links created in /opt/homebrew/bin/ for gcc -> gcc-11, g++ -> g++-11 ; 2) openmpi 4.1.2 installed, with mpicc based on gcc, mpixx based on g++, and mpifort/mpif90 based on gfortran; 3) command-line tools installed as "xcode-select --install".
Getting the problem with finally linking of the libraries:
...
/Users/Natalie/openmpi/bin/mpifort -L/opt/homebrew/opt/openssl#3/lib -fallow-argument-mismatch -fallow-invalid-boz -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk -mmacosx-version-min=11.6 CMakeFiles/cmTC_9a888.dir/testFortranCompiler.f.o -o cmTC_9a888
Undefined symbols for architecture arm64:
"_sgemm_", referenced from:
_MAIN__ in testFortranCompiler.f.o
ld: symbol(s) not found for architecture arm64
collect2: error: ld returned 1 exit status
make[1]: *** [cmTC_9a888] Error 1
make: *** [cmTC_9a888/fast] Error 2 ```
I am trying to compile dynamic lib in Mac OS X Mavericks, but when I try to link it, it says:
Undefined symbols for architecture i386:
"operator new(unsigned long, int, char const*, int)", referenced from:
...
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Compile flags I use:
Wall -Wextra -m32 -march=pentium4 -arch i386 -fvisibility=hidden
tried with
-stdlib=libc++ -lstdc++ -lc++
not helping.
gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.0.0
Thread model: posix
Please help!
EDIT:
Ok, lack of attention:
ld: symbol(s) not found for architecture i386
So, figured out that this is only happening when -g flag is present :)
For release build there is no error.
The question that arises is why there is no debug information symbols on MacOS X for libc++ (operator new). Any clues?
I get a compile-time error in Xcode that includes this message
clang: error: linker command failed with exit code 1 (use -v to see invocation)
This -v is evidently a command-line option. I've run into this message before and have always been at a loss as to what I can do about it and why it's included if I can't do anything about it.
How can I employ the option in Xcode to see the invocation?
You can add the -v to the "Other Linker Flags" field in the project settings. Doing so in a test project here yields the complete linker invocation:
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld"
-demangle
-dynamic
-arch x86_64
-macosx_version_min 10.8.0
-syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk
-o /Users/carl/Library/Developer/Xcode/DerivedData/example-ewesimyvcwmjptdwzbkqoasrcppe/Build/Products/Debug/example
-L/Users/carl/Library/Developer/Xcode/DerivedData/example-ewesimyvcwmjptdwzbkqoasrcppe/Build/Products/Debug
-filelist /Users/carl/Library/Developer/Xcode/DerivedData/example-ewesimyvcwmjptdwzbkqoasrcppe/Build/Intermediates/example.build/Debug/example.build/Objects-normal/x86_64/example.LinkFileList
-dependency_info /Users/carl/Library/Developer/Xcode/DerivedData/example-ewesimyvcwmjptdwzbkqoasrcppe/Build/Intermediates/example.build/Debug/example.build/Objects-normal/x86_64/example_dependency_info.dat
-lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/5.0/lib/darwin/libclang_rt.osx.a
-F/Users/carl/Library/Developer/Xcode/DerivedData/example-ewesimyvcwmjptdwzbkqoasrcppe/Build/Products/Debug
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
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