How to solve : library not found for -lgcov - gcov

Here is my environment
c++ --version
Apple clang version 13.1.6 (clang-1316.0.21.2.5)
Target: arm64-apple-darwin21.4.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
gcov --version
Apple LLVM version 13.1.6 (clang-1316.0.21.2.5)
Optimized build.
Default target: arm64-apple-darwin21.4.0
Host CPU: vortex
I try to collect coverage on my M1 Mac. However, when I invoke c++ -lgcov, it said:
ld: library not found for -lgcov, where can I find the lib and link?

Related

-lomp not found for openmp apple m1

I am currently trying to compile a cpp program with openmp. From what I have read online this is the command that I need to use for indeed using openmp on apple silicon:
g++ -Xpreprocessor -fopenmp -I/opt/homebrew/Cellar/libomp/14.0.6/include -L/usr/local/lib -lomp heat2D.cpp
I have installed everything required for openmp (libomp,llvm,etc...) but it gives me this error:
ld: library not found for -lomp
clang: error: linker command failed with exit code 1 (use -v to see invocation)
In addition if try to remove the lomp flag:
g++ -Xpreprocessor -fopenmp -I/opt/homebrew/Cellar/libomp/14.0.6/include heat2D.cpp
this is the error i get:
Undefined symbols for architecture arm64:
"_omp_set_num_threads", referenced from:
_main in heat2D-0b5aaa.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Since you mention that you installed GCC (and LLVM) via Homebrew, the problem is probably (as Jim Cownie suggested) that when you type "g++", you are running the default link to Apple's LLVM installation (which, alas, does not support OpenMP).
The problem is that Homebrew installs its versions of the compiler binary commands using versioned names -- e.g., "g++-12" if you installed the latest version of GCC. So you have to use those names if you want to run the Homebrew versions. (They are probably installed in /opt/homebrew/bin/ in your case, since you have an Apple Silicon Mac.)
(I haven't installed Homebrew's version of LLVM, but it's probably a similar situation for that as well, since you wouldn't want it to overwrite Apple's LLVM commands.)

OpenSSL FIPS capable library for iOS arm64 architecture

I am successfully generating OpenSSL FIPS capable library for iOS armv7 architecture by referring Appendix E
from https://www.openssl.org/docs/fips/UserGuide-2.0.pdf
However for arm64 architecture with grater than iOS8 I am trying to build FIPS capable library by tweaking setenv-ios-11.sh setenv-darwin-i386.sh files and compiler but it is throwing below error.
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/
llvm-gcc: cannot execute: No such file or directory
How do I build the OpenSSL FIPS capable library for iOS arm64 architecture?
The problem is related to GCC path. So you need to link gcc to your path by below command.
Details: llvm-gcc-4.2: error
Fix the issue on iOS devices:
cd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin
ln -s /usr/bin/llvm-gcc gcc-4.2

Build armeabi instead of armeabi-v7a target using arm clang toolchain

I followed the article "Standalone Toolchains" to create seven customized toolchains (armeabi, armeabi-v7a, arm64-v8a, misp, mips64, x86, and x86_64). Then I want to build PROJ.4 library. I know ARM clang toolchain by default targets armeabi-v7a, so in order to target armeabi, I use the following commands:
export CFLAGS="-march=arm -O2"
export CC=~/Android/toolchain/arm/bin/clang
export CXX==~/Android/toolchain/arm/bin/clang++
./configure --host=arm-linux-androideabi
Then I get the errors:
clang38: error: the clang compiler does not support '-march=arm'
If I change CFLAGS to "-march=arm-v7a -O2", there would be no errors. But it targets armeabi-v7a, not armeabi. So what is the value for -march flag targeting armeabi?
Try armv5 instead, as described here:
https://developer.android.com/ndk/guides/abis.html

Clang Cross Compiling with Yocto SDK

Is it possible to use the toolchain and sysroot from the Yocto SDK to cross compile with Clang/LLVM for ARM?
The environment-setup script within the Yocto SDK has the following compiler options:
export CC="arm-poky-linux-gnueabi-gcc -march=armv7-a -mfloat-abi=hard -mfpu=neon -mtune=cortex-a7 --sysroot=$SDKTARGETSYSROOT"
I would like to cross compile this simple userspace application
testapp.c:
#include <stdio.h>
int main()
{
printf("Hello World\n");
return(0);
}
Following the guide http://clang.llvm.org/docs/CrossCompilation.html, I am trying to cross compile the app with
$ GCCFLAGS="-mcpu=cortex-a7 -mfpu=neon -mfloat-abi=hard"
$ GCCINCLUDE="/opt/poky/2.0.1/sysroots/cortexa7hf-vfp-neon-poky-linux-gnueabi/usr/include/c++/5.2.0/arm-poky-linux-gnueabi/
$ /usr/bin/clang -target arm-poky-linux-gnueabi $GCCFLAGS -I$GCCINCLUDE -ccc-gcc-name arm-poky-linux-gnueabi-gcc testapp.c -o testapp -v
However, this fails with
Ubuntu clang version 3.4.2-3ubuntu2~xedgers (tags/RELEASE_34/dot2-final) (based on LLVM 3.4.2)
Target: arm-poky-linux-gnueabi
Thread model: posix
Selected GCC installation:
"/usr/lib/llvm-3.4/bin/clang" -cc1 -triple armv7-poky-linux-gnueabi -S -disable-free -disable-llvm-verifier -main-file-name testapp.c -mrelocation-model static -mdisable-fp-elim -fmath-errno -mconstructor-aliases -target-cpu cortex-a7 -target-feature +neon -target-abi aapcs-linux -mfloat-abi hard -target-linker-version 2.24 -v -resource-dir /usr/lib/llvm-3.4/bin/../lib/clang/3.4.2 -I /opt/poky/2.0.1/sysroots/cortexa7hf-vfp-neon-poky-linux-gnueabi/usr/include/c++/5.2.0/arm-poky-linux-gnueabi/ -internal-isystem /usr/include/clang/3.4.2/include/ -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-3.4/bin/../lib/clang/3.4.2/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -fno-dwarf-directory-asm -fdebug-compilation-dir /home/adtec/workspace/yocto/testapp -ferror-limit 19 -fmessage-length 207 -mstackrealign -fno-signed-char -fobjc-runtime=gcc -fdiagnostics-show-option -fcolor-diagnostics -vectorize-slp -o /tmp/testapp-8517af.s -x c testapp.c
clang -cc1 version 3.4.2 based upon LLVM 3.4.2 default target x86_64-pc-linux-gnu
ignoring nonexistent directory "/include"
ignoring duplicate directory "/usr/include/clang/3.4.2/include"
#include "..." search starts here:
#include <...> search starts here:
/opt/poky/2.0.1/sysroots/cortexa7hf-vfp-neon-poky-linux-gnueabi/usr/include/c++/5.2.0/arm-poky-linux-gnueabi
/usr/include/clang/3.4.2/include
/usr/local/include
/usr/include
End of search list.
'cortex-a7' is not a recognized processor for this target (ignoring processor)
'cortex-a7' is not a recognized processor for this target (ignoring processor)
'cortex-a7' is not a recognized processor for this target (ignoring processor)
'cortex-a7' is not a recognized processor for this target (ignoring processor)
'cortex-a7' is not a recognized processor for this target (ignoring processor)
'cortex-a7' is not a recognized processor for this target (ignoring processor)
"/usr/bin/as" -mfloat-abi=hard -mcpu=cortex-a7 -mfpu=neon -o /tmp/testapp-f4f688.o /tmp/testapp-8517af.s
/usr/bin/as: unrecognized option '-mfloat-abi=hard'
clang: error: assembler command failed with exit code 1 (use -v to see invocation)
What would be the appropriate Clang flags necessary to cross compile this simple application for ARM?
If you have access to a full build rather than just the SDK, you could try using the clang layer, https://github.com/kraj/meta-clang. Whilst it should be possible eventually to build an SDK containing clang I don't think anyone has done that yet.
you can use meta-clang and also generate a SDK which contains both gcc and clang based cross compilers, once SDK is installed there are CLANGCC and CLANGCXX environment variables available to invoke clang instead of gcc. if you want to use it as default you can do
export CC=${CLANGCC}
export CXX=${CLANGCXX}
export CPP=${CLANGCPP}
There is also a writeup for Clang SDK here

stop compilation switching to clang

No matter what I try, any compilation I attempt always calls clang. For example, in CMake, setting CC=/usr/bin/gcc has no effect and clang is still called. In terminal entering any compiler results in clang being called:
~/tinyos-main/tools$ nescc
clang: error: no input files
~/tinyos-main/tools$ gcc
clang: error: no input files
Can I stop this? Running on OS X Yosemite and using home-brew.
~$ /usr/bin/gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin14.0.0
Thread model: posix
No, gcc is not installed as /usr/bin/gcc. Clang is installed as /usr/bin/gcc, because Apple doesn't ship gcc anymore. If you want gcc, you need to install it (presumably by saying brew install gcc) and then setting CC=/usr/local/bin/gcc.

Resources