OpenCV made by Cmake does not contain any libaries - c++

I am trying to setup OpenCV for Visual Studio 2015, x64, in windows.
I have followed this guide to get OpenCV up and running, however after the CMake Part, i am not sure if everything has gone well.
1- my build file does not contain any lib folder
2- i am confused as where should i set the environment variable for it
3- I assume in visual studio i have to set path for the libraries, but i
don't see any in my build
4- my include folder has a weird install file
pic1: here is a picture of my OpenCV file that cMake built
bin folder is empty
pic2:include folder contents

CMake does not build your library. It sets your build environment, such as designating the install directory for the OpenCV.
So you need to actually build your OpenCV library, then you'll have your include and lib files at the place you've designated as the install directory (cmake_install_prefix in the CMake option).
If you've done your CMake step successfully, you can build your OpenCV by building ALL_BUILD project in your Visual Studio project explorer, and building INSTALL project after that.

Related

Compiling and Linking to Visual Studio 2022 using OpenCV source code built as Win32 from CMake C++

I'm trying to use OpenCV with Dear ImGui in Visual Studio 2022. I'm new to C/C++ libraries and building in general, so I'm unsure if I'm doing anything right. ImGui uses 32-bit architecture and I've used Cmake gui to compile the source code as Win32. I think I have the compiled source code, but it seems to be different than downloading the pre-built libraries. File Explorer Screenshot. I've added the bin to PATH environmental variable, and in Visual Studio tried adding \include to Include Directories, \lib or \lib\Debug to Library Directories, and opencv_world460d.lib to Additional Dependencies. The program still runs, but it doesn't seem to include anything related to OpenCV in the #include files. I found a few .dll files in bin\Debug, but I'm not sure if I should bother with that. I think I could move the source code into the project, but I'm fairly certain that isn't the proper way to do it. Any help would be appreciated.
I needed to run the install target:
You may have built the project, but probably you didn't run the install target. Try running cmake --build <build_dir> --config Release and then cmake --install <build_dir> --config Release, where <build_dir> is a placeholder for the path to the build dir shown in the screenshot. The latter command probably requires admin privileges. Probably best to check the docs of the lib, if there's a step by step instruction for building & installing the whole thing. –
fabian

Using libraries in a CMake project in Visual Studio 2017

I am working on a small DLL based on an existing cmake project. Now I want to additionally use the libjpeg-library. The libjpeg-project compiles correctly and I select to install the library. When I return to my main project and try to use the library.
My problem is that cmake can't find the libjpeg library. When I try to have CMake check for the library with this command:
include (${CMAKE_ROOT}/Modules/FindJPEG.cmake)
It returns:
Could NOT find JPEG (missing: JPEG_LIBRARY)
How can I force CMake/Visual Studio to find the libary? Just for fun, I copied the lib-file in every single folder of the CMake project with the same result...

How do I setup OpenCV 3.4.0?

I have instructions for OpenCV 2.4.3 at:
Installing OpenCV 2.4.3 in Visual C++ 2010 Express [closed]
But, I have not been able to completely convert that to 3.4.0
I get the error
cannot open file 'opencv_calib3d340d.lib'
For OpenCV 2.4.3 the file name is "opencv_calib3d243d.lib"
My guess is that in OpenCV 3.4.0 the file name is "opencv_calib3d340d.lib"
But that is not correct.
I have been using opencv 3.3, and after seeing this post I decided to try 3.4 to see if opencv_calib3d340.lib is missing, and it's not, it's still there.
If you download the winpack, on windows then I believe you use the opencv_world340.lib and .dll, but if you use cmake and build your own, then opencv_calib3d340.lib is in the lib folder.
To setup:
Download the sources zip file, unzip somewhere. Then open cmake gui, choose the source directory, build binaries directory and a current generator. Then click configure, wait, then generate, wait, then open project.
After that build 'ALL_BUILD', or just build opencv_calib3d if that's all you want, saves a lot of time.
I just tried the steps above and they work:
Áfter this I have both a opencv_calib3d340.dll file in bin/ and opencv_calib3d340.lib in lib/
I also tried the debug build and there is a file opencv_calib3d340d.lib as well as a opencv_calib3d340d.dll file.

"CMakeLists.txt" seems to be missing

I was trying to build SFML in order to start developing 2d-games in c++. I put the source-code directory inside C: (the directory itself is called 'SFML'). while trying to generate .cbp files using CMake, I ran into an error:
"The source directory "C:/SFML" does not appear to contain CMakeLists.txt"
It seems like there is a missing file that CMake didn't create.
I am using Cmake 3.10.1, the installation file can be found in https://cmake.org/download/ under the title:"Windows win32-x86 Installer".
I tried to build SFML 2.4.2, using the generator of Codeblocks - MinGW makefiles. The version of codeblocks used is: codeblocks-16.01mingw-setup.exe, found in http://www.codeblocks.org/downloads/26
Did someone encounter the same problem before and knows how to overcome it? If not -
Is there an already-built, ready to use, libray of this version? (2.4.2)
If not.. do you know about a version of SFML that is usable in visual studio 2017?
And another question (That is the last one, I promise...) - maybe you can recommend me about another library for c++, that is usable to develop 2d-games?
edt:
note: I am completely new to all this building thing
the containments of SFML:
maybe it's the binary version?
lib contains some static libraries, bin contains some .dll s
You probably downloaded something wrong or potentially extracted the SFML source into a sub folder or something like that.
Since you've mentioned Visual Studio: SFML is 100% compatible with Visual Studio and you can build it from source any time without having to worry about dependencies (everything included in the repository).
The steps to compile are pretty easy. I'd recommend you install Git to clone the latest source from the SFML repository. In addition you'll need CMake, which you obviously got already.
Open a Command Prompt and change your directory to C:\SFML.
Clone the official repository using Git: git clone https://github.com/SFML/SFML.git source (note the trailing .)
Wait for the source to be checked out to the source sub directory.
Create a new directory called build: md build && cd build
Now invoke CMake, pointing to the source directory and also defining your install path: cmake -DCMAKE_INSTALL_PREFIX=C:/SFML ../source
Build and install a debug build of SFML: cmake --build . --target install --config debug
Build and install a release build of SFML: cmake --build . --target install --config release
Alternatively you can just open the generated Visual Studio solution and build the INSTALL project on your own.
(You shouldn't have to define a build tool or anything; CMake should notice Visual Studio being installed and pick it up automatically.)
I have experienced this using cmake version 3.10 when using the -S command line option. On cmake version 3.15.4 it behaves as expected - so if you update cmake then it might just work.
Note that the -S command line option was not supported before version 3.13:
https://cmake.org/cmake/help/v3.13/release/3.13.html#command-line
Normally cmake is called from a "build" subdirectory of a project root, the project root contains CMakelists.txt. So you would create a "build" directory, change to it, and submit "cmake ..". This would pull in CMakelists.txt from the project root, and use the "build" subdirectory that you are in as the build directory. We say "build", what it actually does is generate makefiles which can then used by the "native" build system (e.g. "make" or Visual Studio) to perform the actual compilation and linking. This arrangement is not always convenient, hence the introduction of the -S and -B command line options.

How can I build a project with CMake?

I've downloaded a source of leptonica-1.74.4
I need lib, dll and *.h files for using with tesseract lib.
As I understood firstly I have to build this source with CMake and then I'll get VS files. (Or maybe lib and dll???)
I've never work with CMake. Have no idea how to run CMakeLists or whatever through CMake. What should I do?
I was trying to read documentation and it just made me confused.
OS Windows 8.
CMake ist not a build system but manages the build process within your native build environment - in your case (Win8 + VS) it'll create the project and solution files you can use in VisualStudio.
For your specific case it will be best to
Download, install and run CMake-GUI
Specify the source folder(where CMakeLists.txt is located)
Specify the build folder(where the libs / executables shall be build)
Press "Configure" - you will be asked for the generator you want to use - ideally you choose the VS version you have installed in your system.
Press "Generate" - cmake generates the .vcxproj and .sln files in your build folder corresponding to the VS version you have chosen.
Open the .sln file and start building leptonica or integrate the project into your own solution.
In addition - CMake allows you to directly trigger the build with your native compiler. But this needs to be done via the console.
more information here