Library not found OpenCV - xcode

I'm on mac 10.7.5, using xcode 4.6.2 and working with the OpenCV 2.4.3 library. I went through the process of making the build directory with the cmake files in terminal and did the download.
I added the .dylib files in Xcode and changed the header path, changed C++ Library to libstdc++, but when I compiled I got this error :
ld: library not found for -lopencv_calib3d.2.4.3
clang: error: linker command failed with exit code 1
I have libopencv_calib3d.2.4.3.dylib added in the project so I have no idea what else it needs.Any ideas?

If your "make back-end" is Cmake you should stick to using it. Local config changes in Xcode can "secretly" be overwritten when the cmake is rerun (which for example happens after you make changes to it) creating weird build errors and forcing you to remember all the manual changes you made.
Your problem seems to be that the generated project doesn't seem to know where to look for opencv.
Assuming you installed opencv using macports you should add a line saying
link_directories(/opt/local/lib)
to your CMakeLists.txt. (if you installed it using brew, or compiled it manually just replace /opt/local/lib for /usr/local/lib or the path to your compiled libraries)
Also make sure to link against opencv_calib3d instead of opencv_calib3d.2.4.3 (unless you have a very particular reason for bypassing this, but that usually means that something else is weird in the setup :) )
Final pointer that you might already know of: As you are already using Cmake you should add the libraries to link against using TARGET_LINK_LIBRARIES(...) in Cmake rather than manually adding them in Xcode (referring to my previous argument).

Related

runtime error ‘symbol not found in flat namespace’ on macOS 12 but not macOS 10.15, with both Xcode and CMake builds

I have problems building an executable file for a simple disease-transmission model implemented in C++, using cmake under macOS Monterey (v12.6.1). When I build the executable file, I obtain the following error when I try running it:
dyld[5281]: symbol not found in flat namespace (_cblas_caxpy) Abort trap: 6
The problem persists when I try to use XCode (v14.0.1) instead, resulting in the same error message.
Interestingly, my friend is able to build (& run) the executable file under macOS v10.15.7 without any problems.
Does anybody know what is going on here and how this issue can be resolved? The C++ project is publicly available on GitHub: https://github.com/AnnaMariaL/DengueSim
Any help would be very much appreciated.
Thanks!
Anna
tried: build an executable file with cmake, and Xcode under MacOS v12.16.1
expected: executable file
the program runs fine when launched under Xcode itself, but if I try to run the built executable from Xcode on the command line, that fails with the same error as for the CMake executable. So Xcode itself is, somehow, magically able to get this linker issue to resolve.
Your title/post is very confusing, however the issue isn't with cmake. It's with your cblas library and/or your linker. Look at the bug closely:
dyld[5281]: symbol not found in flat namespace (_cblas_caxpy) Abort trap: 6
Your linker is telling you that it can't find a function (symbol) in the given namespace. This is either due to the fact that your linker doesn't know where to find the correct library or you are linking against a wrong version of the library that doesn't have the symbols. The other issues might be related to how the library was built and with what it was built (architecture, compiler, etc...). This we can't answer because we don't have enough information to know for sure.

Can't compile App from Titanium Appcelerator with iOS OpenCV Module

I have an issue that is going on for over a month and I can't find any solution for it.
I created an Appcelerator Titanium Module, which uses the OpenCV framework.
I tried literally everything I found on the internet to make it work, but no sucess.
The module compiles, but it crashes when building the App that uses it.
To dig deep in the problem, I compile the App via CLI using appc run -p ios -l trace to see the whole thing. This is what I get:
[TRACE] ld: framework not found opencv2 [TRACE] clang: error: linker command failed with exit code 1 (use -v to see invocation)
This happens if I declare the framework in the module.xconfig file, like this:
OTHER_LDFLAGS=$(inherited) -framework opencv2
If I don't declare it in the file, I get:
[TRACE] symbols not found for architecture x86_64 [TRACE] clang: error: linker command failed with exit code 1 (use -v to see invocation)
Well, the opencv2.framework file is inside the /ios folder in the module.
This is what I tried so far, to put the OpenCV Framework in the project:
OpenCV Official Example for XCode
Compiling it from scratch and then adding to the Project
brew install opencv and then adding it to the project
I configured Framework Search Paths like this:
$(inherited) $(PROJECT_DIR) $(SRCROOT)
Header Search Paths like this:
$(inherited) "$(TITANIUM_SDK)/iphone/include" /usr/local/Cellar/opencv/4.4.0/include (this last one, when installed by brew CLI command.
The Other Linker Flags, is configured like this:
This configuration I got from this tutorial: OpenCV on XCode
And finally, I tried adding the .dylib files from the source of the OpenCV Framework in the project by right-clicking the project's name and Add Files.
So, I tried everything I could find to solve it, but I can't get it to work.
Sorry for the long question, but I am completly out of ideas on how to make this work.
Please, help me!
First of all, the opencv2.framework is copied automatically to the XCode /ios folder (if you selected Copy Files if Needed). BUT, Appcelerator needs 3rd party frameworks to be put on /ios/platform folder. So, I moved it there.
Secondly I added -lz to the Other Linker Flags in Build Settings.
This solved the problem. I must thank the team and developers from TiSlack (An Appcelerator platform community), which helped me through this. Michael and Hans, Thanks!
Here is a video that helped me install OpenCV4 on my Macbook Pro Mojave 10.14.6. I tried installing OpenCV using another video and it led me to getting a linker error that was similar to yours.
Basically, the problem was the path I specified as for my /lib and /include folders.
https://www.youtube.com/watch?edufilter=NULL&v=HxNZEa7Slyk

Solving a difficult compilation issue

Good day,
First up, I have a mac running Mavericks, and I am attempting to build PCL (Point Cloud Library) as part of ROS.
This is the command that fails:
cd /Users/X/ros_catkin_ws/build_isolated/pcl_ros && /Users/X/ros_catkin_ws/install_isolated/env.sh cmake -vd /Users/X/ros_catkin_ws/src/perception_pcl/pcl_ros -DCATKIN_DEVEL_PREFIX=/Users/X/ros_catkin_ws/devel_isolated/pcl_ros -DCMAKE_INSTALL_PREFIX=/Users/X/ros_catkin_ws/install_isolated -DCMAKE_BUILD_TYPE=Release
With:
CMake Error at /usr/local/share/pcl-1.8/PCLConfig.cmake:47 (message):
simulation is required but glew was not found
Call Stack (most recent call first):
/usr/local/share/pcl-1.8/PCLConfig.cmake:500 (pcl_report_not_found)
/usr/local/share/pcl-1.8/PCLConfig.cmake:663 (find_external_library)
CMakeLists.txt:8 (find_package)
Now, I have done what I can to debug this. Looking up online, I notice this is happening due to the fact that in Mavericks, there is no longer the GLEW.framework
https://github.com/PointCloudLibrary/pcl/issues/492
Hence, I installed it via brew, and yet I still get the same issue. Now, I'm thinking, perhaps cmake cannot find it, so I created my own cmake project, and attempted to add find_package(glew). It seems to have found the package here:
-- Found GLEW: /usr/local/include
Hence, I included /usr/local/include in my $PATH variable. Yet once again, it seems to fail with the same error. I am kind of at a lost here, and am not sure how to continue.
I am speculating that in the command above, it seems that somehow the env.sh there seems to change the environmental variables such that it can't find glew.
Any thoughts?
EDIT:
More absurdity. I create a CMake file and included find_package(PCL). It works perfectly. WTF? It even says it found glew
Found Glew: -framework GLEW;-framework Cocoa
How come it works in my Cmake file, but not in theirs? What might cause this
Bastards. I went to the pcl_ros folder, and the glew include directory was pointing to Glew.Framework, which is deprecated as of OSX 10.8!
Scumbag Mavericks! I simply pointed it to the correct glew include directory, which for me is:
/usr/local/Cellar/glew/1.11.0/include/GL
Same as user ovfstack described encountered on OS X 10.10. While compiling ros indigo I found that /usr/local/share/pcl-1.8/PCLConfig.cmake is deprecated.
I installed glew via homebrew under /usr/local/Cellar/glew/1.11.0/include/ and changed line 415 in the above mentioned cmake file from
/System/Library/Frameworks/GLEW.framework/Versions/A/Headers
to
/usr/local/Cellar/glew/1.11.0/include/
Now it compiles just fine.

Clear CMake's internal cache

I am sure there is a simple command for this.
I had installed opencv 2.4.3 manually in /usr/local.
Then I removed it and installed OpenCV 2.4.5 from the arch community(I am using Arch linux) which gets installed in /usr
Now when I try to use OpenCV in a cmake project, cmake returns the old paths from /usr/local.
I did some digging around and found that if remove "CACHE" from the line:
get_filename_component(OpenCV_CONFIG_PATH ="${CMAKE_CURRENT_LIST_FILE}" PATCH CACHE)
in /usr/share/opencv/OpenCVConfig.cmake I get the correct path.
This points to my question. How do I clear the cmake cache?I am talking about cmake's internal cache not the application's cache which can be deleted by removing CMakeCache.txt. Is there a command? Or where is the cmake cache directory/file located? I am sure there's a simple answer for this.
I know how to set/unset a CACHE variable, but don't know how to clear the complete cache.
The problem was with pkg-config settings. I hadn't removed the old .pc file and adjusted the PKG_CONFIG_PATH. pkg-config was using the opencv.pc file present in /usr/local/lib/pkgconfig rather than the one present in /usr/lib/pkgconfig. There isn't any cache that cmake uses internally, i think.
Recompiling the dependency library solved my problem.
I have a project that depends on Opencv. When I still using Xcode 7.2beta, the path of SDK of MacOSX is "/Applications/xcode7.2beta.app/Content/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk". So, the cmake generated and compiled opencv libraries with MacOSX10.11.sdk under "/Applications/xcode7.2beta.app/".
A few days ago, I upgraded my xcode to 8.0, the new path of xcode and its SDK is "/Applications/xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk". But anyway, when cmake generates my project, the reference to opencv always points to the old xcode.
Later I realized that opencv was generated using the old Xcode, so I re-compiled the opencv with the new Xcode, and my project was compiled correctly.

Compiling cvblob on OSX does not correctly locate OpenCV libs

I'm having issues with CVBlob locating the OpenCV installation on OSX 10.6. I have patch for the osx install as described in an earlier message on the cvblob wiki. When I run make, the build process immediately complains that it cannot find cv.h or highgui.h and then subsequently fails to locate additional symbols and vars declared in those headers.
The cmake command I am using is :
cmake -DOpenCV_DIR=/usr/local/Cellar/opencv/2.3.1a/ .
I can see that cv.h is contained in the includes directory in that location. I also tried the following cmake command where I specify the location of the OpenCV Cmake info:
cmake -DOpenCV_DIR=/usr/local/share/OpenCV/ .
Neither seems to correctly tell the cvblob installation where OpenCV is located.
Please help!
SR
In later versions of cvBlob, openCV is automatically located. But version 0.10.4 and before expects the openCV directory to be located next to the cvblob directory. Specifically, version 0.10.4 seems to expect the opencv-2.4.9 directory to be next to cvblob. In this version of cvBlob, the -DOpenCV_DIR parameter seems to have no effect on OS X, and this was the only way I could get it working.
Are you working with Xcode?
If so, just add the OpenCV-path to your header search path in your Xcode project.

Resources