I'm actually looking for a way to create apps with OpenCV with Clion from JetBrains.
I've installed OpenCV with Choco, so I have all the stuff in C:\opencv
this is my projet with Clion
CMakeLists.txt:
cmake_minimum_required(VERSION 3.3)
project(test)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
include_directories("C:\\opencv\\build\\include\\")
FIND_PACKAGE( OpenCV REQUIRED core highgui imgproc)
set(OpenCV_FOUND TRUE)
set(SOURCE_FILES main.cpp)
add_executable(prog ${SOURCE_FILES})
and the main.cpp:
#include <opencv2/opencv.hpp>
int main() {
cv::Mat img = cv::imread("./test.jpg", -1);
cv::imshow("Mon image", img);
cv::waitKey(0);
return 0;
}
and the response to build is :
undefined reference to `cv::imread(cv::String const&, int)'
and undefined errors for all OpenCV functions
Do you know why it doesn't works?
First of all, you need CMake.
Then you need a compiler of your choise (MinGW, Visual Studio, ...).
Download the OpenCV source files. Link
Unpack to C:\opencv (or a folder of your choice)
Open CMake and select source (directory of 2.) and build for example C:\opencv\mingw-build or C:\opencv\vs-x64-build. Choose one accoring your configuration.
Click Configure and select the generator according to you compiler. MinGW Makefiles in case of MingGW or Visual Studio ... if you are using Visual Studio and so on ...
(If you experience problems with MinGW, ensure that the minGW/bin directory is added to the evironment path labelled, 'PATH')
Wait for the configuration to be done, edit your properties of your needs (in my case I don't need tests, docs and python).
Click Configure again. When everything is white click Generate else edit the red fields.
Open cmd and dir to build directory of 3.
If you chose Visual Studio open the generated solution.
Compile the library. Run mingw32-make (or mingw64-make) or build the BUILD_ALL project from the generated solution in Visual Studio if your choosen compiler is MSVC.
This takes a while.
Once it is done, run mingw32-make install (or mingw64-make install). If you've choosen Visual Studio you need to build the INSTALL project.
This creates an install folder, where everything you need for building your own OpenCV apps is included.
To system PATH add C:\opencv\mingw-build\install\x86\mingw\bin
Restart your PC.
Set up CLion:
You need to download FindOpenCV.cmake and add it to project-root/cmake/.
CMakeLists.txt:
project(test)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
# Where to find CMake modules and OpenCV
set(OpenCV_DIR "C:\\opencv\\mingw-build\\install")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
add_executable(test_cv main.cpp)
# add libs you need
set(OpenCV_LIBS opencv_core opencv_imgproc opencv_highgui opencv_imgcodecs)
# linking
target_link_libraries(test_cv ${OpenCV_LIBS})
main.cpp:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
int main(int argc, char** argv)
{
if(argc != 2)
{
std::cout << "Usage: display_image ImageToLoadAndDisplay" << std::endl;
return -1;
}
cv::Mat frame;
frame = cv::imread(argv[1], IMREAD_COLOR); // Read the file
if(!frame) // Check for invalid input
{
std::cout << "Could not open or find the frame" << std::endl;
return -1;
}
cv::namedWindow("Window", WINDOW_AUTOSIZE); // Create a window for display.
cv::imshow("Window", frame); // Show our image inside it.
cv::waitKey(0); // Wait for a keystroke in the window
return 0;
}
Build and run main.cpp.
All Paths depend on the setup you make in 2. and 3. You can change them if you like.
UPDATE 1: I updated the post for using a compiler of you choice.
SUGGESTION: Using a package manager like Conan makes life much easier.
I just want to add one more thing in the answer of daB0bby. Few Min-GW Compilers do not support C++ Version 11 or later. This version is required for thread in OpenCV. So I will suggest using TDM-GCC Compiler instead of MinGW Compiler. Install this compiler and set path C:\TDM-GCC-64\bin to the system's environmental variable.
Related
Summary
In Windows, CLion doesn't complain anything after cmake and before makefile.
All code seems to link correctly without error. I am able to see the reference, documents, linter and jump into cv::Mat or opencv.hpp header file with ctrl RMB.
CMake seems to correctly generate make files without error.
But the compile error occurs: undefined reference to OpenCV methods.
my setup
CMakeLists.txt:
cmake_minimum_required(VERSION 3.9)
project(test)
# Set compile version
set(CMAKE_CXX_STANDARD 17)
add_executable(test ./test.cpp )
find_package(OpenCV REQUIRED)
message(STATUS "OpenCV library status:")
message(STATUS " version: ${OpenCV_VERSION}")
message(STATUS " libraries: ${OpenCV_LIBS}")
message(STATUS " libraries: ${OpenCV_LIBRARIES}")
message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}")
target_link_libraries(test ${OpenCV_LIBRARIES})
The output seems correct
"D:\Program Files\JetBrains\CLion 2021.3.2\bin\cmake\win\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - MinGW Makefiles" D:\repo\CS5330\test
-- OpenCV library status:
-- version: 4.5.5
-- libraries: opencv_calib3d;opencv_core;opencv_dnn;opencv_features2d;opencv_flann;opencv_gapi;opencv_highgui;opencv_imgcodecs;opencv_imgproc;opencv_ml;opencv_objdetect;opencv_photo;opencv_stitching;opencv_video;opencv_videoio;opencv_world
-- libraries: opencv_calib3d;opencv_core;opencv_dnn;opencv_features2d;opencv_flann;opencv_gapi;opencv_highgui;opencv_imgcodecs;opencv_imgproc;opencv_ml;opencv_objdetect;opencv_photo;opencv_stitching;opencv_video;opencv_videoio;opencv_world
-- include path: /path/to/scoop/apps/opencv/current/include
-- Configuring done
-- Generating done
-- Build files have been written to: /path/to/test/cmake-build-debug
[Finished]
And this generates CMakeCache.txt, which includes,
//The directory containing a CMake configuration file for OpenCV.
OpenCV_DIR:PATH= /path/to/scoop/apps/opencv/current/x64/vc15/lib
//Details about finding OpenCV
FIND_PACKAGE_MESSAGE_DETAILS_OpenCV:INTERNAL=[/path/to/scoop/apps/opencv/current][v4.5.5()]
As you see, system-wide environment variable OpenCV_DIR has been already set and read correctly by CLion.
Here is a simple test code, but failed to run
#include <opencv2/opencv.hpp>
int main() {
cv::Mat img = cv::imread("./test.jpg", -1);
cv::imshow("Mon image", img);
cv::waitKey(0);
return 0;
}
I also installed msys2 from winget, and from msys2 installed clang, make, MinGW-w64 GDB,cmake. Following this tutorial.
And tested through that toolchain instead of CLion bundled toolchain, it returns the same result.
OpenCV binary is from scoop.
For some reason, it has the same problem as one from homebrew. In opencv.hpp, includes headers are incorrect due to file hierarchy that opencv.hpp is inside opencv2 folder.
I changed all #include "opencv2/header.hpp" to #include "header.hpp", but it doesn't help, and vice versa.
Can't figure out the reason for hours.. Any help will be appreciated.
So I figured out how to get Qt Framework working with CLion, but I don't have Qt Designer in CLion. How can I make a GUI in CLion using Qt Framework? Every tutorial i've seen uses Qt Creator so I cannot get an answer.
I worked with QtCreator and then with Qt5 libraries on Clion.
For a better understanding see my project at https://github.com/FraScandiffio/Timer_Laboratorio
Search for MyTimerApp.ui .h .cpp files.
1)You need a .ui file: it was created for me by QtCreator: when i worked on Clion i just copied the file into my project folder and add in the SOURCES_FILES.
You can download it from my project: it's the MyTimerApp.ui file but you have to change just 3 words to adapt it to your needs.
Re-name the file with the name that you prefer. Now open the file with a text editor and replace all the "MyTimerApp" with the name that you have just chosen.
2)Add this in your Cmake.txt (the explanation of why you have to do it is here)
cmake_minimum_required(VERSION 3.3)
project({your_project_name})
set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOUIC ON)
set(SOURCE_FILES main.cpp MyApp.ui #...)
#... the rest of your cmake.txt ...
Download also MyTimerApp.cpp and MyTimerApp.h files. (i suggest you to create a new .h file and paste into them the code instead of refactor my file)
Open it and replace "MyTimerApp" whit the same name you have chosen before.
obviously add them into the SOURCE_FILES list.
In the main.cpp type
#include "nameyouhavechoosen.h"
#include "QApplication"
#include "QWidget"
int main(int argc, char *argv[]){
QApplication app(argc, argv);
QWidget* MyWidget= new {nameyouhavechoosen};
MyWidget->setGeometry(500,200,617,416);
app.setActiveWindow(MyWidget);
MyWidget->show();
return app.exec();
}
If you run it you should see a very simple window.
In my github repository you can find how to create buttons/timer and more. Anyway Qt documentation is great for learning.
On Windows 7 64 bit, AMD processor, I installed OpenCV 2.4.5, with eclipse CDT Juno and MinGW, everything to the latest update. Previously eclipse CDT and MinGW compiled 100+ source files without problems. They even compile this small OpenCV source file,
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace std;
int main()
{
IplImage* img1 = cvLoadImage("lenna.png");
cvShowImage("MyWindow1", img1);
cv::Mat img2;
img2 = cv::imread("lenna.png", CV_LOAD_IMAGE_COLOR);
cv::namedWindow("MyWindow2", CV_WINDOW_AUTOSIZE);
cv::imshow("MyWindow2", img2);
cvWaitKey(0);
return 0;
}
but when I try to Run it then it breaks with notorious
"The application was unable to start correctly (0xc0000005). Click OK
to close the application."
What might be wrong and what would be solution to this problem?
OpenCV (PreCompiled) is unzipped to "C:\OpenCV245PC\ (README,index.rst and CMakeLists.txt are there with all subfolders)
Windows System PATH is set to C:\OpenCV245PC\build\x86\mingw\bin
Eclipse GCC C++ Compiler, Include paths (-I) is set to "C:\OpenCV245PC\build\include"
Eclipse MinGW C++ Linker, Library search path (-L) is set to: "C:\OpenCV245PC\build\x86\mingw\lib"
Eclipse MinGW C++ Linker, Libraries (-l) are set to:
opencv_calib3d245 opencv_contrib245 opencv_core245
opencv_features2d245 opencv_flann245 opencv_gpu245 opencv_highgui245
opencv_imgproc245 opencv_legacy245 opencv_ml245 opencv_nonfree245
opencv_objdetect245 opencv_photo245 opencv_stitching245
opencv_video245 opencv_videostab245
After many trials and errors I decided to follow this tutorial and to compile my own binaries as it seems that too many people are complaining that precompiled binaries are NOT working for them. Eclipse CDT Juno was already installed.
My procedure was as follows:
Download and install MinGW and add to the system PATH with
c:/mingw/bin
Download cmake from http://www.cmake.org and install it
Download OpenCV2.4.5 Windows version
Install/unzip Opencv to C:\OpenCV245PC\ (README,index.rst and CMakeLists.txt are there with all subfolders)
Run CMake GUI tool, then
Choose C:\OpenCV245PC\ as source
Choose the destination, C:\OpenCV245MinGW\x86 where to build the binaries
Press Configure button, choose MinGW Makefiles as the generator. There are some red highlights in the window, choose options as you need.
Press the Configure button again. Configuring is now done.
Press the Generate button.
Exit the program when the generating is done.
Exit the Cmake program.
Run the command line mode (cmd.exe) and go to the destination
directory C:\OpenCV245MinGW\x86
Type "mingw32-make". You will see a progress of building
binaries. If the command is not found, you must make sure that the
system PATH is added with c:/mingw/bin. The build continues
according the chosen options to a completion.
In Windows system PATH (My Computer > Right button click >
Properties > Advanced > Environment Variables > Path) add the
destination's bin directory, C:\OpenCV245MinGW\x86\bin
RESTART COMPUTER
Go to the Eclipse CDT IDE, create a C++ program using the sample OpenCV code (You can use code from top of this topic).
Go to Project > Properties > C/C++ Build > Settings > GCC C++ Compiler > Includes, and add
the source OpenCV folder "C:\OpenCV245PC\build\include"
Go to Project > Properties > C/C++ Build > Settings > MinGW C++ Linker > Libraries, and add to the Libraries (-l) ONE BY ONE (this could vary from project to project, you can add all of them if you like or some of them just the ones that you need for your project): opencv_calib3d245 opencv_contrib245 opencv_core245 opencv_features2d245 opencv_flann245 opencv_gpu245 opencv_highgui245 opencv_imgproc245 opencv_legacy245 opencv_ml245 opencv_nonfree245 opencv_objdetect245 opencv_photo245 opencv_stitching245 opencv_video245 opencv_videostab245
Add the built OpenCV library folder, "C:\OpenCV245MinGW\x86\lib" to Library search path (-L).
You can use this code to test your setup:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main()
{
Mat img = imread("c:/lenna.png", CV_LOAD_IMAGE_COLOR);
namedWindow("MyWindow", CV_WINDOW_AUTOSIZE);
imshow("MyWindow", img);
waitKey(0);
return 0;
}
Don't forget to put image to the C:/ (or wherever you might find suitable, just be sure that eclipse have read acess.
Can you try this code,
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main()
{
Mat img = imread("lenna.png", CV_LOAD_IMAGE_COLOR);
namedWindow("MyWindow", CV_WINDOW_AUTOSIZE);
imshow("MyWindow", img);
waitKey(0);
return 0;
}
cause it seems like you are not creating a window for img1, and not assigning imread output to img2.
I tried two methods to use opencv with qt creator
first one using Mingw where the dlls and .dll.a files are already downloaded with the opencv library and I just add reference to the .dll.a files in the .pro file as follow
INCLUDEPATH += D:\\OpenCV\\opencv\\build\\include
LIBS += D:\\OpenCV\\opencv\\build\\x64\\mingw\\lib\\libopencv_calib3d242.dll.a
LIBS += D:\\OpenCV\\opencv\\build\\x64\\mingw\\lib\\libopencv_contrib242.dll.a
LIBS += D:\\OpenCV\\opencv\\build\\x64\\mingw\\lib\\libopencv_core242.dll.a
LIBS += D:\\OpenCV\\opencv\\build\\x64\\mingw\\lib\\libopencv_features2d242.dll.a
I have a simple code to test opencv:
#include <QtCore/QCoreApplication>
#include <opencv/cv.h>
using namespace cv;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
Mat image;
return a.exec();
}
but I got a build issues as follow
C:\Users\Kato\Documents\QT projects\QtOpenCVYaRab\debug\main.o:-1: In function ~Mat':
d:\OpenCV\opencv\build\include\opencv2\core\mat.hpp:278: error: undefined reference tocv::fastFree(void*)'
d:\OpenCV\opencv\build\include\opencv2\core\mat.hpp:367: error: undefined reference to `cv::Mat::deallocate()'
:-1: error: collect2: ld returned 1 exit status
Here is some of the compile output:
Running build steps for project QtOpenCVYaRab...
Configuration unchanged, skipping qmake step.
Starting: "C:\QtSDK\mingw\bin\mingw32-make.exe"
C:/QtSDK/mingw/bin/mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory `C:/Users/Kato/Documents/QT projects/QtOpenCVYaRab'
g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL
d:/OpenCV/opencv/build/include/opencv2/core/mat.hpp:278: undefined reference to `cv::fastFree(void*)'
debug/main.o:d:/OpenCV/opencv/build/include/opencv2/core/mat.hpp:367: undefined reference to `cv::Mat::deallocate()'
collect2: ld returned 1 exit status
mingw32-make[1]: *** [debug\QtOpenCVYaRab.exe] Error 1
mingw32-make: *** [debug] Error 2
The process "C:\QtSDK\mingw\bin\mingw32-make.exe" exited with code 2.
Error while building project QtOpenCVYaRab (target: Desktop)
When executing build step 'Make'
the second method is using cmake to compile the opencv library the using visual studio 2010 to build it and add references to the files in the bin folder but I got almost the same building issues.
#include "iostream"
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
using namespace std;
int main()
{
IplImage *image = cvLoadImage("C:\\lena.jpg");
Mat im(image);
imshow("TEST",im);
waitKey();
return 0;
}
this is ur main.cpp...the above programme displays the picture of lena...use double backslashes for indicating change of directory on windows platform...some how the imread does work for me so i have loaded the image as IplImage and casted it to Mat...u cn do the following also..
IplImage *image = cvLoadImage("C:\\lena.jpg",1);
cvShowImage("TEST",image);
cvWaitKey();
your .pro file should have the following lines as mentioned earlier...
INCLUDEPATH += D:\OpenCV\opencv\build\include
LIBS +=-LD:\OpenCV\opencv\build\x64\mingw\lib\
-lopencv_core242\
-lopencv_highgui242\
-lopencv_imgproc242\
-lopencv_video242\
and your system variable named path should have
D:\Opencv2.4.2\opencv\build\x86\vc9\bin (if you have Qt 4.8.1 for
desktop MSVC2008 (QtSDK) Debug as your target)
D:\Opencv2.4.2\opencv\build\x86\mingw\bin (if your target is based on Qt MinGW x86 )
D:\OpenCV2.4.2\opencv\build\common\tbb\ia32\vc9(mingw) (i have added this coz it was showing some weird errors...u can try it)
after editing the path variable close the Qt ide/application and restart it for the system variable change to get reflected..
INCLUDEPATH += D:\OpenCV\opencv\build\include
LIBS +=-LC:\OpenCV\opencv\build\x64\mingw\lib\
-lopencv_core242\
-lopencv_highgui242\
-lopencv_imgproc242\
-lopencv_video242\
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
int main()
{
}
if u are running it as an console application then no need to include QtCore/QtApplication
You have to specify your library path with -L and then add the library file with
-l<libname_without_extension>
For unix (installed in default place):
unix: LIBS += -lopencv_core
unix: LIBS += -lopencv_highgui
For windows (your problem):
win32: LIBS += -L C:\OpenCV2.3\opencv\build\gpu\x64\lib\ -lopencv_core231
From the error mentioned, it seems that Opencv library is missing some files/components.Please start with the simple program for Opencv. This program just display the camera image.
Please follow the given link.
http://linux.softpedia.com/get/Multimedia/Graphics/qwebcam-38246.shtml
Download the source code for qwebcam and follow the instruction to setup Opencv. This is a very simple source code and works fine (tested on Linux-os).
I recently tried with Opencv & this link was quiet useful for me to begin with.
Hope you will be able to resolve your error through this code.
I ran into the same problem, but altering the .pro manually didn't work for me. Eventually I found a simple solution to connect the openCV to Qt. I posted about it a few other threads, https://stackoverflow.com/a/51914928/10245006 and have included the information below.
The steps listed below are found in the Qt5 documentation: [http://doc.qt.io/qtcreator/creator-project-qmake-libraries.html][1] under the "To Add Library" section.
Right click on the project file located in the 'project pane' on the left side of the creator... and select "Add Library..."
Follow the instructions of the wizard
Let me add some specificity from here...
Select "External Library"
For the "Library File" navigate to your opencv_worldXXX.lib file (or opencv_worldXXXd.lib file, you will notice that by specifying only one or the other the wizard has a checkbox which includes the other automatically) [ex. ...\opencv\build\x64\vc12\lib\opncv_world310.lib]
For the "Include Folder" navigate to the "include" folder within the build. [ex. ...\opencv\build\include]
Select your operating system, dynamic/static library (whichever is appropriate)
Hit NEXT, CLEAN UP, and RUN!
For a week I've been struggling with compiling openCV programs. I've tried everything I could possibly find on the internet.
What I did is: I've downloaded OpenCV-2.3.1-win-superpack.exe and followed this official installation guide.
In the CMake (gui) my source was: D:\opencv and build destination was: C:\opencv.
I've also added C:\opencv\install\bin;C:\opencv\bin to my system's PATH variable.
What I want is to compile openCV programs on my Windows OS using MinGW's gcc/g++ compilers.
I've tried various gcc/g++ parameters that I've found on the internet and days playing with the -I and -L options the compiler can never find the openCV functions or structures.
What I am trying to compile:
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <cv.h>
#include <highgui.h>
int main(int argc, char *argv[])
{
// Nothing but create a window
cvNamedWindow("mainWin", CV_WINDOW_AUTOSIZE);
cvMoveWindow("mainWin", 100, 100);
cvWaitKey(0);
return 0;
}
Error:
Input:
gcc test.c -o test -I"C:\opencv\install\include" -I"C:\opencv\install\include\opencv" -L"C:\opencv\install\bin"
Output:
...\ccK4MfHv.o:test.c:(.text+0xa0b): undefined reference to `cvFree_'
Or with g++:
Input:
g++ test.c -o test -I"C:\opencv\install\include" -I"C:\opencv\install\include\opencv" -L"C:\opencv\install\bin"
Output:
...\ccXCTKa1.o:test.c:(.text+0x1e): undefined reference to `cvNamedWindow'
Side note: trying to compile in VS2005 I get the same error.
Thank you for your time!
In case someone else needs to solve this issue, here's how I got the posted OpenCV/HighGUI sample code to compile in Windows 7 x64 using MinGW, MSYS, and CMake:
build OpenCV from source using MinGW/MSYS/CMake. This is because I could not get the MinGW compiled version in the OpenCV-win-SuperPack to link properly in MinGW/MSYS/Windows 7 x64.
For full reference, here's how I compiled OpenCV:
make sure you have an up-to-date CMake (v2.6 or later) and MinGW (with GCC, G++, and MSYS options) installed
if you want the new Qt-based OpenCV HighGUI front-end, you will need to install Qt 4 (SDK).
download a OpenCV source/superpack version 2.2 or later (I used OpenCV-2.3.1-win-superpack.exe)
unzip the contents to [OPENCV_SOURCE_DIR] (I put it in C:/opencv, so there should be a file at C:/opencv/README for example)
create a [OPENCV_BUILD_DIR] directory elsewhere (I used C:/opencv/build/mingw)
use the CMake-GUI tool, specify the source directory as [OPENCV_SOURCE_DIR], the build directory as [OPENCV_BUILD_DIR], and click "Configure".
you may wish/need to go tweak the options (e.g. I ticked "Qt" and "Qt-OpenGL" entries, then clicked "Configure" again, then had to provide the path to the qmake executable)
once you have finished configuring OpenCV, click "Generate"
in a MSYS terminal, browse to [OPENCV_BUILD_DIR], and run "make" to build the code (this may take a while)
once the has been built properly, run "make install", which collects the built code/libraries/include dirs into [OPENCV_BUILD_DIR]/install folder (or a different folder if you changed the corresponding option when using the CMake-GUI tool)
add [OPENCV_BUILD_DIR]/install/bin folder to the PATH environmental variable. If you do not know how to do this, then I'd recommend using the Path Editor GUI tool.
if you end up using Qt, you will also need to put the bin folder of Qt SDK in the PATH environmental variable. This is the folder that includes qmake.exe.
put the following sample code into a file called test.c. I modified the includes slightly to make them compatible with OpenCV v2.2 and above.
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <opencv/cv.h>
#include <opencv/highgui.h>
int main(int argc, char *argv[])
{
// Nothing but create a window
cvNamedWindow("mainWin", CV_WINDOW_AUTOSIZE);
cvMoveWindow("mainWin", 100, 100);
cvWaitKey(0);
return 0;
}
in a MSYS terminal, browse to the folder where you put test.c, and run:
gcc -o test -I"[OPENCV_BUILD_DIR]/install/include" test.c \
-L"[OPENCV_BUILD_DIR]/install/lib" \
-lopencv_core[OPENCV_VERSION] \
-lopencv_imgproc[OPENCV_VERSION] \
-lopencv_highgui[OPENCV_VERSION]
So in my case:
gcc -o test -I"/c/opencv/build/mingw/install/include" test.c \
-L"/c/opencv/build/mingw/install/lib" \
-lopencv_core231
-lopencv_imgproc231
-lopencv_highgui231
Path Editor: http://www.redfernplace.com/software-projects/patheditor/
You have the directory, C:\opencv\install\bin, to locate libraries on the gcc/g++ command line, but I think you'll also need to specify the libraries to use as linker inputs as well. I'm not sure what libraries are part of the OpenCV distribution, but going by the example on the instruction page you linked to, one might be:
-lopencv_calib3d220.dll
You'll probably have to add one or more other ones (that follow the name pattern lib*.a in the C:\opencv\install\bin directory - or maybe some other lib directory that you should be passing in a -L option).