-lomp not found for openmp apple m1 - clang

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

Related

Problems linking FFTW with gfortran (symbol(s) not found for architecture x86_64)

I am on macOS Catalina (10.15.5) and I have installed FFTW using brew install fftw. I also have GCC (version 10.2.0) installed which is symlinked to the commands I am using below.
I am able to compile and run a simple C++ program like so:
g++-10 test.cpp -L/usr/local/lib -I/usr/local/include -lfftw3 -lm
But, I had to modify the environment variable CPATH to make this work.
I am unable to get a simple Fortran FFTW example to work (I am using this one). The command I am using to compile is:
gfortran-10 test.f90 -L/usr/local/lib -I/usr/local/include -lfftw3 -lm
The error I get is as follows:
Undefined symbols for architecture x86_64:
"__gfortran_os_error_at", referenced from:
_MAIN__ in ccRvJaEQ.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
If I understand correctly, the linking step fails. Any inputs on how I might find the relevant paths that I may have to pass to the compiler would be very helpful. I searched for solutions and I wasn't able to find one. But, in case I missed something obvious, I apologise.
Thanks to msi_gerva's helpful hints through comments, I was able to solve the issue by downloading FFTW and compiling it to a custom directory following the installation directions.
Now, the linking doesn't fail if I pass the new locations of the libraries to gfortran like so:
gfortran-10 test.f90 -L/new/path/to/lib -I/new/path/to/include -lfftw3 -lm
Since /usr/local/ is the default installation path, it's possible that there is a mixing up of the FFTW library files from previous installations.

Not able to build openh264 for ios because of libstdc++

I am trying to build openh264 for ios. I have downloaded the source code from the latest release. then changed the PREFIX in makefile to ios_local. After that I did make OS=ios ARCH=arm64 which completed with lot of warning.
After that when I did sudo make OS=ios ARCH=arm64 install It exited with error like below
clang: warning: libstdc++ is deprecated; move to libc++ with a minimum deployment target of iOS 7 [-Wdeprecated]
ld: library not found for -lstdc++
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [libopenh264.2.0.0.dylib] Error 1
After researching it seems like Apple does not support libstdc++ now, so mac os compatible version is libc++ which is supposed to be installed when you install XCode. My XCode version is Version 10.2.1 (10E1001) which is more than enough to get this libc++ I think.I am using macOS Mojave. What's going wrong here?

Symbols not found in libusb

Note that I am new to iOS (actually, iDevices) internals.
I'm trying to compile iRecovery,
a tool used to communicate with iBoot, iOS's bootloader. Sadly... I'm getting errors about libusb while compiling :
./configure: line 15323: syntax error near unexpected token `libusb,'
./configure: line 15323: `PKG_CHECK_MODULES(libusb, libusb-1.0 >= 1.0.3)'
libusb is installed :
$> pkg-config --libs libusb
-L/opt/local/lib -lusb
$> pkg-config --libs libusb-1.0
-L/opt/local/lib -lusb-1.0
I tried to comment out the line that checks for libusb, but then I get a bunch of not found symbols, such as :
"_libusb_set_configuration", referenced from:
_irecv_open_with_ecid in libirecovery_la-libirecovery.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 simple question is... WHY ?!
Thanks for any help...
Okay, so here's a dirty workaround :
open (NOT RUN) autogen.sh file, and comment out the "PKG_CHECK_MODULES(libusb, libusb-1.0 >= 1.0.3)" line
save
run autogen.sh modified file provided
open the makefile located in /src : add "-lusb-1.0 -L/usr/local/lib/ -I /usr/local/include/ - I /usr/local/include/libusb-1.0" to the "GLOBAL_CFLAGS" variable
save
cd to main directory (parent of /src)
make
make install
Once done, your should be able to run irecovery from your shell.
Please note that it is not really clean, and that it is only confirmed to work for iRecovery.
But - It Works !

Linking libiconv on ios

I am trying to use the objective-git library for an ios application I am in the proccess of developing. I am able to get the library to compile, link, and run perfectly fine in the simulator. However, when I try to run the application on an actual iPad, I get the followign error:
Undefined symbols for architecture armv7s:
"_libiconv", referenced from:
_git_path_iconv in libObjectiveGit-iOS.a(path.c.o)
"_libiconv_close", referenced from:
_git_path_iconv_clear in libObjectiveGit-iOS.a(path.c.o)
"_libiconv_open", referenced from:
_git_path_iconv_init_precompose in libObjectiveGit-iOS.a(path.c.o)
ld: symbol(s) not found for architecture armv7s
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I believe the issue is that I am compiling the libgit2 library with a different version of iconv then the one included with ios. However, I have messed with the build script in an attempt to force it to link with the ios version, but the error persists. How should I go about properly linking the iconv library so that I can run the application on an actual device?
You need to add libiconv.tbd to 'Link Binary With Libraries' section in Build Phases.
Note: I know ObjectiveGit fixed this issue but maybe that helps to others those who are trying to use iconv in their projects.

how to uninstall openCV on mac 10.6.8?

I have multiple versions of openCV (2.0,2.1) on my mac. Is there a way to erase these multiple versions and all its files so that i can make a fresh install of openCV 2.3.0
The most obvious command
sudo port uninstall opencv
may not work, at least in my case it complained that it needs a particular version. I run then
sudo port uninstall opencv 4.2
All opencv libraries in /opt/local/lib were gone after that command. After that I re-installed openCV with
sudo port install opencv
(If there is a problem with ffmpeg just uninstlal it with sudo port uninstall ffmpeg)
Reinstalling opencv, by the way, fixed my problems with compilation and linking that I had after switching from Mountain Lion to Maverick (10.9.2). In particular, I had a linker problem in Eclipse:
Invoking: GCC C++ Linker
g++ -L/opt/local/lib -o "deltetit" ./src/deltetit.o -lopencv_core -lopencv_highgui -lopencv_imgproc
Undefined symbols for architecture x86_64:
"cv::imshow(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, cv::_InputArray const&)", referenced from:
_main in deltetit.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: *** [deltetit] Error 1
Just delete the install folder.
And make sure to point to the correct install path when compiling your proj

Resources