Error when compiling OpenCV for Qt - c++

In order to use OpenCV in Qt, I have to compile it with MinGW by cmake.
Software are the following:
Qt 5.4.0
Opencv 2.4.11
CMake 3.2.2
MinGW version unknown, GCC 4.8.1
A fatal error occurred when I make file and I have no idea how to solve it at all.
[ 29%] Automatic moc for target opencv_highgui
Generating moc_window_QT.cpp
Exit code 0xc000007b
AUTOGEN: error: process for C:/opencvbuild/modules/highgui/moc_window_QT.cpp failed:
Exit code 0xc000007b
moc failed...
modules\highgui\CMakeFiles\opencv_highgui_automoc.dir\build.make:48: recipe for target 'modules/highgui/CMakeFiles/opencv_highgui_automoc' failed
mingw32-make[2]: *** [modules/highgui/CMakeFiles/opencv_highgui_automoc] Error 1
CMakeFiles\Makefile2:2066: recipe for target 'modules/highgui/CMakeFiles/opencv_highgui_automoc.dir/all' failed
mingw32-make[1]: *** [modules/highgui/CMakeFiles/opencv_highgui_automoc.dir/all] Error 2
Makefile:145: recipe for target 'all' failed
mingw32-make: *** [all] Error 2
These messages are shown in cmd.
Then I revised CMakeLists.txt, SET(CMAKE_AUTOMOC OFF)
modules\highgui\CMakeFiles\opencv_highgui_automoc.dir\build.make:64: recipe for target 'modules/highgui/qrc_window_QT.cpp' failed
Does anybody know a solution?

2 items to try.
Try running make with VERBOSE=1 to increase the output on the makefile. That should give you a better idea of what is wrong.
Try running with cmake-gui, then turn on advanced mode to check out what CMake found for the different Qt5 dependencies. On Mac, I install the latest Qt to my home directory, causing me to have to manually set variables. This is what it looks like for me.
Hopefully this provides some useful information.

Related

Error with linking flag when using the cmake build for cppyy

I am trying to build the example for a make build for cppyy in the cppyy-knearestneighbors example (https://github.com/jclay/cppyy-knearestneighbors-example). From what I understand it used the more modern cppyy cmake.
However when it comes to the linking I find this error,
ld: unknown option: --no-as-needed
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [knn_example/libknn_exampleCppyy.dylib] Error 1
make[1]: *** [CMakeFiles/knn_exampleCppyy.dir/all] Error 2
make: *** [all] Error 2
I couldn't find away to remove this flag as it seems to be something internal to cppyy cmake. Is there any work around to fix the compilation?
I cannot talk about cppyy since I have never used it, but since it internally uses CMake, the issue that you have could control by the value of the LINK_WHAT_YOU_USE property.
I would first try to disable the default value of LINK_WHAT_YOU_USE with:
# When running cmake configure:
cmake -GNinja -DCMAKE_LINK_WHAT_YOU_USE=OFF
If it does not work, a more evolve approach which means iterating all of the targets and unsetting their LINK_WHAT_YOU_USE property. Let me know if you need help for this
https://cmake.org/cmake/help/latest/variable/CMAKE_LINK_WHAT_YOU_USE.html#variable:CMAKE_LINK_WHAT_YOU_USE

How to fix 'cannot find -lgmp' build error on OMNeT++?

I have become aware that OverSim can be used with the newer versions of OMNeT++. I installed OMNeT++ 5.6.1 on Windows 10 by following the instructions in InstallGuide. Then, I imported INET 3.6.5 in OMNeT++ and built it, there were no errors. Finally, I imported OverSim-20190424 and when I build it I get the following error at the end of the build process:
make[1]: Entering directory '/c/omnet561/oversim-20190424/src'
Creating executable: ../out/gcc-debug/src/OverSim_dbg.exe
C:/omnet561/omnetpp-5.6.1/tools/win64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/7.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lgmp
collect2.exe: error: ld returned 1 exit status
make[1]: *** [Makefile:418: ../out/gcc-debug/src/OverSim_dbg.exe] Error 1
make[1]: Leaving directory '/c/omnet561/oversim-20190424/src'
make: *** [Makefile:11: all] Error 2
"make MODE=debug -j8 all" terminated with exit code 2. Build might be incomplete.
12:15:59 Build Failed. 3 errors, 0 warnings. (took 12s.448ms)
The other two errors are:
Description Resource Path Location Type
make: *** [Makefile:11: all] Error 2 OverSim C/C++ Problem
make[1]: *** [Makefile:418: ../out/clang-debug/src/OverSim_dbg.exe] Error 1 OverSim C/C++ Problem
Does anyone know how this error can be fixed? I have tried using OverSim on Windows 7 as well and tried using OMNeT++ 5.4.1 but the same error is still produced.
The libgmp libraries (libgmp-10.dll and libgmpxx-4.dll) are in the directory "C:/omnet561/omnetpp-5.6.1/tools/win64/mingw64/bin". I think the problem here might be that the software is using the wrong directory to search for the libraries but I'm not sure how to fix such an issue.
Try to add path to libgmp libraries using Makefrag.
Go to OverSim-20190424 Project Properties, choose OMNeT++ | Makemake | select src | Options | Custom | Makefrag and write:
LIBS += -L/c/libraries/libgmp
It is assumed that libgmp libraries (*.dll or *.a) are in C:\libraries\libgmp.
EDIT
Open Makefrag from oversim-20190424\src\ in a text editor, and then change LIBS and OMNETPP_LIBS to proper values:
LIBS += -L/sw/lib -L/c/omnet561/omnetpp-5.6.1/tools/win64/mingw64/bin
OMNETPP_LIBS += -lgmp
or
OMNETPP_LIBS += -lgmp-10
For anyone who encounters the same problem, I managed to solve it by using OMNeT++ 5.6.1 and Oversim 20190424 on Ubuntu 18.04. When I built Oversim, I got an error "Could not find gmp.h", to solve that error I installed libgmp3-dev - apt-get install libgmp3-dev. If somebody manages to get it to work on Windows 10 or has an idea of how it can be fixed, then please feel free to post.

Getting “no rule to make target” error while trying to run OpenCV code

I'm trying to run example code from https://docs.opencv.org/master/db/df5/tutorial_linux_gcc_cmake.html. I use Ubuntu 16. I have OpenCV installed in /home/marcin/opencv/ directory. I use CMakeLists.txt file like in example, with addition of line
set (CMAKE_CXX_STANDARD 11)
I run in terminal
cmake -D CMAKE_PREFIX_PATH=/home/marcin/opencv/build
and I get positive output. But when I try to run make command I get:
make[2]: *** No rule to make target '/home/marcin/opencv/build/lib/libopencv_core.so.4.0.1',
needed by 'DisplayImage'. Stop.
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/DisplayImage.dir/all' failed
make[1]: *** [CMakeFiles/DisplayImage.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
As #Tsyvarev suggestet, I reinstalled the library one more time. It seems like it was broken.

Compiling an existing C++ program using Makefile

Edit: not solved, but as I moved on to other software, I ran into other challenges.
For a research project, I downloaded a Github project (Tagliasacchi et al., 2015) for computer vision to Linux 16.04. I have programming experience with PHP but I am new to C++. When I try to replicate the results of the study on my computer, I run early into a compiling error.
The Hello world-example of the Github project (apps » helloworld) works fine.
When trying to compile another application, I run into an error with the Makefile: cmake . works fine and some files are created. However, make does not work.
After the error, g++ [filename].cpp -o main obviously does not work.
How to solve this and get the dependencies right?
In some cases, there is a Makefile, but I run into an error:
[ 33%] Building CXX object CMakeFiles/helloworld_atb.dir/main.cpp.o
/bin/sh: 1: /usr/bin/g++-4.8: not found
CMakeFiles/helloworld_atb.dir/build.make:62: recipe for target 'CMakeFiles/helloworld_atb.dir/main.cpp.o' failed
make[2]: *** [CMakeFiles/helloworld_atb.dir/main.cpp.o] Error 127
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/helloworld_atb.dir/all' failed
make[1]: *** [CMakeFiles/helloworld_atb.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
In other cases (e.g. in tracker » HandFinder), I can't run either cmake . or make and compiling using g++ HandFinder.cpp -o handfinder does not work:
In file included from HandFinder.cpp:1:0:
HandFinder.h:2:41: fatal error: tracker/ForwardDeclarations.h: No such file or directory
compilation terminated.

linking error cxx: cannot find -lvulkan

When I tried to compile example from Anvil framework for Vulkan I get following errors:
[ 97%] Linking CXX executable OutOfOrderRasterization
/usr/bin/ld: cannot find -lvulkan
collect2: error: ld returned 1 exit status
CMakeFiles/OutOfOrderRasterization.dir/build.make:126: recipe for target 'OutOfOrderRasterization' failed
make[2]: *** [OutOfOrderRasterization] Error 1
CMakeFiles/Makefile2:72: recipe for target 'CMakeFiles/OutOfOrderRasterization.dir/all' failed
make[1]: *** [CMakeFiles/OutOfOrderRasterization.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
How i need to configure Vulkan to resolve it? (Ubuntu)
Check you LIBRARY paths. You might need to download and install vulkan. There should a .so file in one your library paths(/usr/lib{,64},/lib{,64}, /usr/share/lib{,64}) named to the effect of libvulkan.numbers.so.
See this ask ubuntu question: https://askubuntu.com/questions/796442/ld-cannot-find-lvulkan
CMake versions 3.7 and later ship with a FindVulkan.cmake module that finds the Vulkan includes and library for you if you have a Vulkan SDK installed and the VULKAN_SDK environment variable set. The CMake module also finds the includes and library if you have installed a Vulkan package to your system directories. The Getting Started guide on the LunarXchange website has some additional detail.