Linking my CMAKE project with libpng in Windows - windows

I'm working on a C++ project that requires libpng. So far I've worked on Linux and everything is smooth. I installed libpng, CMAKE picks it up and everything is alright. Now move to Windows.
Here I first installed zlib (required by libpng) and libpng. When I say install, I mean I downloaded the source files, and then built them and install them using msbuild.
I noticed that by doing so, I got new folders under c:\program files (x86):
c:\program files (x86)\zlib
c:\program files (x86)\libpng
Seemed all right to me. Now when I configure my project with CMAKE zlib is picked up:
-- Found ZLIB: C:/Program Files (x86)/zlib/lib/zlib.lib (found version "1.2.13")
but there's no way CMAKE finds the PNG library:
Could NOT find PNG (missing: PNG_LIBRARY PNG_PNG_INCLUDE_DIR)
Now I tried to have a look at the FindPNG and I noticed this line:
find_path(PNG_PNG_INCLUDE_DIR png.h PATH_SUFFIXES include/libpng)
Does this mean that CMAKE expects the file png.h to be in a directory ending in include/libpng? If so, then it will never find it because in my case png.h is placed in libpng/include. But this is also the "official" installation from the source code just downloaded from http://www.libpng.org/pub/png/libpng.html.
So now I am superconfused. How things are supposed to work in Windows? Should I "create" a folder structure with the correct files for every library so that CMAKE is happy? In a way I hoped things in Windows were similar to what happens in Linux: libraries go in a standard folder, they are detected by CMAKE.. everything is ok. But apparently this is not the case. So my question in general is: how do you ship a package like this to a Windows user so that he can builds it without having to go through all this?
Thanks so much
Fabrizio

This would be the right one to use:
find_package(PNG)
You can tell CMake to look in the location where you installed it by adding the libpng base install location to CMAKE_PREFIX_PATH. Without this, CMake doesn't know where you put it.
cmake "-DCMAKE_PREFIX_PATH=C:/Program Files (x86)/libpng" ...
Note that FindPNG first looks for zlib and will fail if zlib could not be found.

Related

How to install libxml++ in Visual studio? Does nmake "see" vcpkg packages?

I am having troubles installing libxmlplusplus (https://github.com/libxmlplusplus/libxmlplusplus) in Visual studio.
It is extremely annoying libxml2 wrapper that someone used to parse setup for project I am working and it has so many annoying little dependencies that I am tempted just to rewrite setup parsing with new code as I want to distribute this project as open source and I wish to no one to go through with installation of this library.
The README file in MSVC_NMake directory states that I only need to install libxml2 and include it in my VC directories.
Now I know that this hellish library also needs glib, and glibmm as few years back, this person http://hostagebrain.blogspot.com/2015/07/building-libxml-by-visual-studio.html went through horrible ways to build everything in VC when I am assuming glibmm and libxml2 were not easy to get.
I installed glibmm and libxml2 via vcpkg.
I downloaded libxmlplusplus, went to MSVC_NMake directory and run:
nmake /f Makefile.vc CFG=release
I am getting error messages as:
..\libxml++\attribute.cc: fatal error C1083: Cannot open include file: 'msvc_recommended_pragmas.h': No such file or directory
So it seems some dependency is not linked, but have no idea which.
I checked ..\libxml++\attribute.cc and went down the include labyrinth to find out that it includes libxml\tree.h and libxml is part of libxml2, so I am suspecting libxml2 was not linked properly.
I exited powershell and then went to manually set VC includes and library dirs to vcpkg/packages/xxx location where they are installed, but I am still getting the same error.
I added glibmm to VC dirs, I even installed gtk and linked to VC hoping it'll find the missing header.
Can someone please help? Shouldn't vcpkg packages be in "path" when running nmake automatically? Am I missing completely different dependency?
nmake won't magically see vcpkg installations. You need to either setup the environment variables (LIB/LIBPATH/PATH/INCLUDE/CL/LINK etc) for it or provide the paths to vcpkg in some other way.
That being said libxml++ is a available port in vcpkg -> see libxmlpp

How to use Tesseract OCR with Cmake on Windows?

I'm tryint to use tesseract in my cmake project on Windows. I installed tesseract 5.0 and tesseract 4.0. They both come with no cmake folder so the line
find_package(Tesseract REQUIRED)
produces
CMake Error at CMakeLists.txt:14 (find_package):
By not providing "FindTesseract.cmake" in CMAKE_MODULE_PATH this project
has asked CMake to find a package configuration file provided by
"Tesseract", but CMake did not find one.
Could not find a package configuration file provided by "Tesseract"
(requested version 4.0) with any of the following names:
TesseractConfig.cmake
tesseract-config.cmake
Add the installation prefix of "Tesseract" to CMAKE_PREFIX_PATH or set
"Tesseract_DIR" to a directory containing one of the above files. If
"Tesseract" provides a separate development package or SDK, be sure it has
been installed.
However, in the installation folder for tesseract 5.0, there's libtesseract-5.dll and many others. Can I link those in my cmake project? If so, how? And why there are no include files in the installation folder? How am I suppose to include the .h files in my project?
UB-Mannheim installer is autotools build and it has only runtime part of tesseract (e.g. executables and linked libraries).
You can not use it for any development because it does not provide needed files (libraries and header files), so missing cmake files are reasonable consequences of this installation.
You can check this information in detail where installer finished.
Have you tried using the MSYS/Mingw build of tesseract: pacman -S mingw-w64-x86_64-tesseract-ocr? Since there is no cmake config file you will have to use pkg_check_modules instead (see also cMakefile for using tesseract and opencv without the opencv bit)

Visual studio and dlib: "cannot open include file: 'zlib.h': No such file or directory"

For my thesis I want to use Dlib's face_landmark_detection, but I keep running into these errors (for both Visual studio 2013 as well as 2015):
"cannot open include file: 'zlib.h': No such file or directory"
and
"'F77_INT': undeclared identifier".
It repeats itself so I have 36 errors based on these two problems.
My supervisor has given me some steps to follow to set up the project:
add dlib-master and dlib-master\examples to VC++ directories -> include directories
add dlib-master\dlib\external\libjpeg and dlib-master\dlib\entropy_decoder to C/C++ -> General -> Additional include directories
add all folders and items from dlib-master\dlib\external (cblas, libjpeg, libpng and zlib) to the project source folder
add the dlib source file (from dlib-master\dlib\all) and add face_landmark_detection (from dlib-master\examples) to the project source folder.
and according to him this has worked on every other computer so far, but on my laptop it just won't. We checked to project, but zlib.h is in the zlib folder in the project. Does anyone here have an idea on what might be going wrong?
If I didn't give enough info, please ask. I don't know what else might be needed to solve this.
I have just come about this same problem and wanted to post my solution since I have found so much conflicting documentation on the subject.
The folder containing the dlib folder as well as the libpng, libjpeg, and zlib folders from dlib/external need to be added to the additional include directories list in the solution settings.
dlib/all/source.cpp as well as the source files for libpng, libjpeg, and zlib also need to be added to the project.
Note that CBLAS should not be added to the project in any way, because it needs Fortran to compile, and it is very difficult to get this to compile from Visual Studio.
Finally, make sure to add DLIB_PNG_SUPPORT and DLIB_JPEG_SUPPORT as preprocessor defines in the project settings.
I also attempted to use a cmake generated solution, however, for some reason it had trouble with png support.
It is probably easiest to use CMake to configure your project which uses dlib. It avoids setting all those paths manually. During CMake configure step you can disable usage of libraries like zlib which you don't have/want/need. Here is an example CMakeLists.txt which works for me:
cmake_minimum_required(VERSION 2.6)
PROJECT(DatasetClassifier CXX C)
set(dlib_DIR "" CACHE PATH "Path to dlib") # http://dlib.net/
include(${dlib_DIR}/dlib/cmake)
ADD_EXECUTABLE(DatasetClassifier DatasetClassifier.cpp)
TARGET_LINK_LIBRARIES(DatasetClassifier ${dlib_LIBRARIES})

Gstreamer on windows

I'd like to build application using Gstreamer 1.0 and GTK+-3.0 on Windows 8 (64bit).
I have sucessfully install and build GTK+-3.0, 32 bit version using Dev-C++ and Mingw 32-bit (there is no 64 bit version of GTK+). Everything works perferkt. It also installed pkg-config, I addeded it in %PATH% and it works.
I have installed gstreamer-1.0-devel-x86-1.4.4.msi and gstreamer-1.0-x86-1.4.4.msi from here
1) First problem: it installed itself into I:\gstreamer\ without asking me. I am very unhappy about it, I'd like have it on C:. But its not the biggest problem.
2) pkg-config do not know about gstreamer. I have found in I:\gstreamer\1.0\x86\lib\pkgconfig\ *.pc files, so I looked into gstreamer-1.0.pc and added to my projekt this options:
C compiler:
-I"I:/gstreamer/1.0/x86/include/gstreamer-1.0/"
Linker:
-L"I:/gstreamer/1.0/x86/lib" -lgstreamer-1.0
3) Now the program was compiled, but when I run it, it was not able to find gstreamer-1.0-0.dll. So i tried copy I:\gstreamer\1.0\x86\bin\gstreamer-1.0-0.dll into to the same directory as is my compiled file. Then it was not able to find libwinptread-1.dll. So I copied it also.
Then te program run, but it faild with some error like "cannot find entry point to windows thread ..." (I do not remember it exactly). So I copied ALL dll files from I:\gstreamer\1.0\x86\bin\ and then finally the program run.
But now it is not able to create elements:
source = gst_element_factory_make ("videotestsrc", "source");
//source is null
So, my question is, how to install gstreamer, that my program will find all dll files and will be able to create elements?
installing -- choose "custom install", there you can change the installation path.
for vs you can use *.props (gstreamer\1.0\x86\share\vs\2010\libs)
you need set Environment variable - GST_PLUGIN_SYSTEM_PATH_1_0 to plug-ins. For more details see http://gstreamer.freedesktop.org/data/doc/gstreamer/head/gstreamer/html/gst-running.html

Library not found OpenCV

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

Resources