Hello. I've been trying to use xcode as the IDE of choice to write C++ code with openCV.
I've downloaded the openCV source from github and compiled it myself.
To use openCV within xcode, I went to the project file and included in the "Build settings"
Header Search Paths /Users/fabricio/opencv/build/installation/OpenCV-4/include/opencv4
Library Serch Paths /Users/fabricio/opencv/build/installation/OpenCV-4/lib
This allows xcode to identify and find the headers and libraries so that I can get auto-complete for opencv and so on.
The following code builds fine
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
#include "opencv2/core.hpp"
#include "opencv2/highgui.hpp"
using namespace cv;
int main() {
// Do absolutely nothing
return 0;
}But, the following throws out a bunch of errors
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
#include "opencv2/core.hpp"
#include "opencv2/highgui.hpp"
using namespace cv;
int main() {
Mat color = imread("/Users/fabricio/Documents/opencv-test/sample.jpg");
Mat gray = imread("/Users/fabricio/Documents/opencv-test/sample.jpg", IMREAD_GRAYSCALE);
return 0;
}The errors are all related to "Undefined Symbol":
It seems that when I try to use the libraries, I get errors.
If I try running cmake to compile opencv code, things seem to work out. Here is the cmake file I used.
# cmake needs this line
cmake_minimum_required(VERSION 3.1)
# Enable C++11
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
SET(OpenCV_DIR /Users/fabricio/opencv/build/installation/OpenCV-4/lib/cmake/opencv4)
# Define project name
project(sample)
# Find OpenCV, you may need to set OpenCV_DIR variable
# to the absolute path to the directory containing OpenCVConfig.cmake file
# via the command line or GUI
find_package(OpenCV REQUIRED)
# If the package has been found, several variables will
# be set, you can find the full list with descriptions
# in the OpenCVConfig.cmake file.
# Print some message showing some of them
message(STATUS "OpenCV library status:")
message(STATUS " config: ${OpenCV_DIR}")
message(STATUS " version: ${OpenCV_VERSION}")
message(STATUS " libraries: ${OpenCV_LIBS}")
message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}")
# Declare the executable target built from your sources
add_executable(sample sample.cpp)
# Link your application with OpenCV libraries
target_link_libraries(sample ${OpenCV_LIBS})Obviously, there is a solution that my poor brain is not capable of grasping.
Any help here would be greatly appreciated.
Thank you
Fabricio