Can't run OpenCV-App because of runtime error missing Qt5OpenGL.dll and Qt5Test.dll - opencv

I want to build an application using the OpenCV library built with cmake.
First I downloaded the sources for opencv4.5.5. I created in that folder a subfolder mingwbuild and from there I can the command "cmake ../ -G "MinGW Makefiles"
Then I ran the command "mingw32-make install" and it took 2 hours to compile.
I then used cmake again to build a project, like described in the first answer here:
Configuring an c++ OpenCV project with Cmake
When I then ran the generated .exe, it would give me a runtime error "Qt5OpenGl.dll and Qt5Test.dll could not be found"
So I downloaded QtOpenGl.dll with MSYS2 from here https://packages.msys2.org/package/mingw-w64-x86_64-qt5-base
with the command "pacman -S mingw-w64-x86_64-qt5-base"
When I then run my opencvtest.exe , it says that it could not find the entry point of some method in QtOpenGl.dll . So the version or something must be wrong?
When searching for the package in the MSYS2 terminal, it says there are 10 packages I can download and install. The first four are:
$ pacman -Ss qt5-base
mingw32/mingw-w64-i686-qt5-base 5.15.3+kde+r174-2 (mingw-w64-i686-qt5)
A cross-platform application and UI framework (mingw-w64)
mingw32/mingw-w64-i686-qt5-base-debug 5.15.3+kde+r174-2 (mingw-w64-i686-qt5-debug)
A cross-platform application and UI framework (mingw-w64)
mingw64/mingw-w64-x86_64-qt5-base 5.15.3+kde+r174-2 (mingw-w64-x86_64-qt5) [installed]
A cross-platform application and UI framework (mingw-w64)
mingw64/mingw-w64-x86_64-qt5-base-debug 5.15.3+kde+r174-2 (mingw-w64-x86_64-qt5-debug)
Maybe if I choose the release package, I also have to set the option -DCMAKE_BUILD_TYPE=Release when invoking cmake?
Option x86 means 64-bit package and without x86, it means 32-bit packages. How can I figure out which of these I do need?
Any help is appreciated.

I finally managed to compile my OpenCVApp
The key was to work only in the MSYS2 MinGW x64 shell.
First I needed to install cmake like so:
pacman -S mingw-w64-x86_64-cmake
Then I had to install opencv with pacman like so:
pacman -S /mingw-w64-x86_64-opencv
The Qt5, I had to install like so:
pacman -S mingw-w64-x86_64-qt5-base
Then I created a new directory with src/main.cpp and CMakeLists.txt inside it like so:
Here CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
PROJECT (opencvtest)
find_package(OpenCV REQUIRED )
set( NAME_SRC
src/main.cpp
)
set( NAME_HEADERS
include/header.h
)
INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR}/include )
link_directories( ${CMAKE_BINARY_DIR}/bin)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
add_executable( opencvtest ${NAME_SRC} ${NAME_HEADERS} )
target_link_libraries( opencvtest ${OpenCV_LIBS} )
Here main.cpp
#include <iostream>
#include <sstream>
#include <string>
#include <fstream>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace std;
const cv::Vec3b color_azure{ 255, 129, 0 };
const cv::Vec3b color_violet{ 255, 0, 127 };
const cv::Vec3b color_black {0,0,0};
int main() {
cout << "App started" << endl;
cv::Mat image = cv::Mat(cv::Size(800, 600), CV_8UC3, color_black);
std::vector<cv::Point> vs(5);
vs[0] = cv::Point(200, 450);
vs[1] = cv::Point(600, 250);
vs[2] = cv::Point(400, 50);
vs[3] = cv::Point(200, 250);
vs[4] = cv::Point(600, 450);
std::vector<int> nk(9);
nk[0] = 0;
nk[1] = 1;
nk[2] = 2;
nk[3] = 3;
nk[4] = 4;
nk[5] = 0;
nk[6] = 3;
nk[7] = 1;
nk[8] = 4;
std::stringstream ss("Das-ist-das-Haus-vom-Ni-ko-laus");
std::vector<std::string> silben(9);
int j = 0;
while (ss.good())
{
std::string substr;
getline(ss, substr, '-');
silben[j++] = substr + "-";
}
for (int i = 0; i < 8; i++) {
cv::line(image, vs[nk[i]], vs[nk[i + 1]], color_azure, 5);
cv::putText(image, silben[i], cv::Point(i*60, 475),
cv::FONT_HERSHEY_PLAIN, 1, color_violet, 2);
cv::imshow("Image", image);
cv::waitKey();
}
cv::imshow("Image", image);
cv::waitKey(0);
return 0;
}
Then compiling and running worked fine:
mkdir buildmingw
cd buildmingw
cmake .. -G "MinGW Makefiles"
mingw32-make
bin/opencvtest.exe

Related

Linking to statically compiled z3 needs additional libraries on Linux

I used CMake to compile a static version of (a fairly recent of) z3 using:
cmake -DBUILD_LIBZ3_SHARED=false -DCMAKE_INSTALL_PREFIX=/opt/z3-devel -G "Unix Makefiles" ../
Now when I statically link the library against a C++ program, say this small variation of a z3 example:
#include"z3++.h"
using namespace z3;
int main(int argc, char** argv) {
config conf;
context c(conf);
expr x = c.int_const("x");
expr y = c.int_const("y");
expr z = c.int_const("z");
goal g(c);
g.add( ((2*x)+y)+z == 4);
g.add( (x+(2*y))+z == 4);
g.add( x+y == 4);
std::cout << g << "\n";
tactic t(c, "fm");
apply_result r = t(g);
std::cout << r << "\n";
return 0;
}
via
g++ -c -I /opt/z3-devel/include -static -o main.o main.cc
g++ -static -L /opt/z3-devel/lib64 -o main main.o -lz3
I receive a long list of undefined reference linking errors. What solves the issue is to add -lgomp -pthread -lrt -ldl as additional libraries. The linker outputs the following warning:
/usr/bin/ld: /usr/lib/gcc/x86_64-redhat-linux/8/libgomp.a(target.o): in function `gomp_target_init':
(.text+0x32c): warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
Nevertheless, the program runs fine on my own machine and on Starexec.
Is this combination of static and dynamic linking the best I can do? Shouldn't those libraries be already statically linked into libz3.a? I have static versions of gomp, pthread and rt available on the system.

Error when linking C executable to OpenCV

I'm compiling OpenCV under Ubuntu 13.10 using cMake.
i've already compiled c++ programs and they works well.
now i'm trying to compile a C file using this cMakeLists.txt
cmake_minimum_required (VERSION 2.8)
project (hello)
find_package (OpenCV REQUIRED)
add_executable (hello src/test.c)
target_link_libraries (hello ${OpenCV_LIBS})
here is the test.c file:
#include <stdio.h>
#include <stdlib.h>
#include <opencv/highgui.h>
int main (int argc, char* argv[])
{
IplImage* img = NULL;
const char* window_title = "Hello, OpenCV!";
if (argc < 2)
{
fprintf (stderr, "usage: %s IMAGE\n", argv[0]);
return EXIT_FAILURE;
}
img = cvLoadImage(argv[1], CV_LOAD_IMAGE_UNCHANGED);
if (img == NULL)
{
fprintf (stderr, "couldn't open image file: %s\n", argv[1]);
return EXIT_FAILURE;
}
cvNamedWindow (window_title, CV_WINDOW_AUTOSIZE);
cvShowImage (window_title, img);
cvWaitKey(0);
cvDestroyAllWindows();
cvReleaseImage(&img);
return EXIT_SUCCESS;
}
it returns me this error whene running cmake . then make to the project:
Linking C executable hello
/usr/bin/ld: CMakeFiles/hello.dir/src/test.c.o: undefined reference to symbol «lrint##GLIBC_2.1»
/lib/i386-linux-gnu/libm.so.6: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make[2]: *** [hello] Erreur 1
make[1]: *** [CMakeFiles/hello.dir/all] Erreur 2
make: *** [all] Erreur 2
Add -lm /lib/i386-linux-gnu/libm.so.6to your linked library
$ gcc `pkg-config --cflags opencv` -o <output> <input> `pkg-config --libs opencv` -lm /lib/i386-linux-gnu/libm.so.6
I had the same errors and it worked with me
Edit your CMakeLists.txt as follows:
cmake_minimum_required(VERSION 2.8)
project(test)
find_package( OpenCV REQUIRED )
add_executable( test test.c )
target_link_libraries( test ${OpenCV_LIBS} )
Then, $ cmake .
Then $ make and finally $./test

G++: fatal error: no input files

Hi Im trying to display the lena.jpg which is the first demostration for Instant OpenCV Starter Book.
I can build and play 'hello world' easy enough.
The problem code
// opencv header files
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/core/core.hpp"
// namespaces declaration
using namespace cv;
using namespace std;
// create a variable to store the image
Mat image;
int main( int argc, char** argv )
{
// open the image and store it in the 'image' variable
// Replace the path with where you have downloaded the image
// image=imread("<path to image">/lena.jpg");
image=imread("/home/nigel/Documents/ffmpeg/tests/lena.jpg");
// create a window to display the image
namedWindow( "Display window", CV_WINDOW_AUTOSIZE );
// display the image in the window created
imshow( "Display window", image );
// wait for a keystroke
waitKey(0);
return 0;
}
The error
g++ -Wall -fexceptions 'pkg-config --cflags opencv' -g "pkg-config --cflags
opencv' -c/home/nigel/Drone/Test2/main.cpp -o obj/Debug/Drone/Test2/main.o
g++:fatal error:no input files
compilation terminated
process terminated with status 1 (0 minutes, 0 seconds)
I have tried different paths for the lena.jpg, I changed the lena.jpg from lena.pnm not sure if I have the path right maybe ?
New to using OpenCv would appreciate some help
This error occurs when no source code file is passed in to g++. This leads me to believe there is an error in your command line arguments.
Some spots to look at:
It looks like there may be a stray quote before the second pkg-config in the line
'pkg-config --cflags opencv' -g "pkg-config --cflags opencv'
It also looks like you are missing a space between the -c and the /home/.../main.cpp

RabbitMQ install issue on Centos 5.5

I've been trying to get rabbitmq-server-2.4.0 up and running on Centos
5.5 on an Amazon AWS instance.
My instance uses the following kernel: 2.6.18-xenU-ec2-v1.2
I've tried installation of erlang and rabbitmq-server using:
1) yum repos
2) direct rpm installation
3) compiling from source.
In every case, I get the following message when attempting to start the
RabbitMQ-Server process:
pthread/ethr_event.c:98: Fatal error in wait__(): Function not
implemented (38)
Any help would be appreciated.
The problem
When starting erlang, the message pthread/ethr_event.c:98: Fatal error in wait__(): Function not implemented (38) is, on modern distros, most likely the result of a precompiled Erlang binary interacting with a kernel that doesn't implement FUTEX_WAIT_PRIVATE and FUTEX_WAKE_PRIVATE. The kernels Amazon provides for EC2 do not implement these FUTEX_PRIVATE_ macros.
Attempting to build Erlang from source on an ec2 box may fail in the same way if the distro installs kernel headers into /usr/include/linux as a requirement of other packages. (E.g., Centos requires the kernel-headers package as a prerequisite for gcc, gcc-c++, glibc-devel and glibc-headers, among others). Since the headers installed by the package do not match the kernel installed by the EC2 image creation scripts, Erlang incorrectly assumes FUTEX_WAIT_PRIVATE and FUTEX_WAKE_PRIVATE are available.
The fix
To fix it, the fastest is to manually patch erts/include/internal/pthread/ethr_event.h to use the non-_PRIVATE futex implementation:
#if defined(FUTEX_WAIT_PRIVATE) && defined(FUTEX_WAKE_PRIVATE)
# define ETHR_FUTEX_WAIT__ FUTEX_WAIT_PRIVATE
# define ETHR_FUTEX_WAKE__ FUTEX_WAKE_PRIVATE
#else
# define ETHR_FUTEX_WAIT__ FUTEX_WAIT
# define ETHR_FUTEX_WAKE__ FUTEX_WAKE
#endif
should become
//#if defined(FUTEX_WAIT_PRIVATE) && defined(FUTEX_WAKE_PRIVATE)
//# define ETHR_FUTEX_WAIT__ FUTEX_WAIT_PRIVATE
//# define ETHR_FUTEX_WAKE__ FUTEX_WAKE_PRIVATE
//#else
# define ETHR_FUTEX_WAIT__ FUTEX_WAIT
# define ETHR_FUTEX_WAKE__ FUTEX_WAKE
//#endif
Quick test
If you suspect the private futex issue is your problem, but want to verify it before you recompile all of Erlang, the following program can pin it down:
#include <sys/syscall.h>
#include <unistd.h>
#include <sys/time.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <stdint.h>
typedef uint32_t u32; /* required on older kernel headers to fix a bug in futex.h Delete this line if it causes problems. */
#include <linux/futex.h>
int main(int argc, char *argv[])
{
#if defined(FUTEX_WAIT) && defined(FUTEX_WAKE)
uint32_t i = 1;
int res = 0;
res = syscall(__NR_futex, (void *) &i, FUTEX_WAKE, 1,
(void*)0,(void*)0, 0);
if (res != 0)
{
printf("FUTEX_WAKE HAD ERR %i: %s\n", errno, strerror(errno));
} else {
printf("FUTEX_WAKE SUCCESS\n");
}
res = syscall(__NR_futex, (void *) &i, FUTEX_WAIT, 0,
(void*)0,(void*)0, 0);
if (res != 0)
{
printf("FUTEX_WAIT HAD ERR %i: %s\n", errno, strerror(errno));
} else {
printf("FUTEX_WAIT SUCCESS\n");
}
#else
printf("FUTEX_WAKE and FUTEX_WAIT are not defined.\n");
#endif
#if defined(FUTEX_WAIT_PRIVATE) && defined(FUTEX_WAKE_PRIVATE)
uint32_t j = 1;
int res_priv = 0;
res_priv = syscall(__NR_futex, (void *) &j, FUTEX_WAKE_PRIVATE, 1,
(void*)0,(void*)0, 0);
if (res_priv != 0)
{
printf("FUTEX_WAKE_PRIVATE HAD ERR %i: %s\n", errno, strerror(errno));
} else {
printf("FUTEX_WAKE_PRIVATE SUCCESS\n");
}
res_priv = syscall(__NR_futex, (void *) &j, FUTEX_WAIT_PRIVATE, 0,
(void*)0,(void*)0, 0);
if (res_priv != 0)
{
printf("FUTEX_WAIT_PRIVATE HAD ERR %i: %s\n", errno, strerror(errno));
} else {
printf("FUTEX_WAIT_PRIVATE SUCCESS\n");
}
#else
printf("FUTEX_WAKE_PRIVATE and FUTEX_WAIT_PRIVATE are not defined.\n");
#endif
return 0;
}
Paste it into futextest.c, then gcc futextest.c and ./a.out.
If your kernel implements private futexes, you'll see
FUTEX_WAKE SUCCESS
FUTEX_WAIT SUCCESS
FUTEX_WAKE_PRIVATE SUCCESS
FUTEX_WAIT_PRIVATE SUCCESS
If you have a kernel without the _PRIVATE futex functions, you'll see
FUTEX_WAKE SUCCESS
FUTEX WAIT SUCCESS
FUTEX_WAKE_PRIVATE HAD ERR 38: Function not implemented
FUTEX_WAIT_PRIVATE HAD ERR 38: Function not implemented
This fix should allow Erlang to compile, and will yield an environment you can install rabbitmq against using the --nodeps method discussed here.
I installed it by first installing erlang by source:
sudo yum -y install make gcc gcc-c++ kernel-devel m4 ncurses-devel openssl-devel
wget http://www.erlang.org/download/otp_src_R13B04.tar.gz
tar xfvz otp_src_R13B04.tar.gz
cd otp_src_R13B04/
./configure
sudo make install
After that create a symbolic link to also make erl available for root user:
sudo ln -s /usr/local/bin/erl /bin/erl
Install rabbitmq rpm (Maybe outdated check latest release yourself):
wget http://www.rabbitmq.com/releases/rabbitmq-server/v2.4.1/rabbitmq-server-2.4.1-1.noarch.rpm
rpm -Uvh rabbitmq-server-2.4.1-1.noarch.rpm
If erlang is installed from source, rpm install of rabbitmq fails to recognize erlang stating that erlang R12B-3 is required.
Use:
rpm --nodeps -Uvh rabbitmq-server-2.6.1-1.noarch.rpm
I was able to install and use RabbitMQ 2.6.1 successfully on CentOS 5.6 with Erlang R14B04
Seems that this kernel is not compatible with Erlang 14B, 14B01, or 14B02
Compiling Erlang 13B04 led to a successful install of rabbitmq-server
For people in the future finding this answer, the RabbitMQ site itself has a potential answer for you:
Installing on RPM-based Linux (CentOS, Fedora, OpenSuse, RedHat)
Erlang on RHEL 5 (and CentOS 5)
Due to the EPEL package update policy, EPEL 5 contains Erlang version
R12B-5, which is relatively old. rabbitmq-server supports R12B-5, but
performance may be lower than for more recent Erlang versions, and
certain non-core features are not supported (SSL support, HTTP-based
plugins including the management plugin). Therefore, we recommend that
you install the most recent stable version of Erlang. The easiest way
to do this is to use a package repository provided for this purpose by
the owner of the EPEL Erlang package. Enable it by invoking (as root):
wget -O /etc/yum.repos.d/epel-erlang.repo
http://repos.fedorapeople.org/repos/peter/erlang/epel-erlang.repo
and then install or update erlang with yum install erlang.
If you go down the route of building Erlang manually on a minimal OS install, you may also find that you need to install wxGTK & wxGTK-devel in order for all of the tests to build and run correctly.

Using OpenCV in QTCreator (linking problem)

I have a problem with the linking simpliest test program in QTCreator:
CODE:
#include <QtCore/QCoreApplication>
#include <cv.h>
#include <highgui.h>
#include <cxcore.hpp>
using namespace cv;
int _tmain(int argc, _TCHAR* argv[])
{
cv::Mat M(7,7,CV_32FC2,Scalar(1,3));
return 0;
}
.pro file:
QT -= gui
TARGET = testopencv
CONFIG += console
CONFIG -= app_bundle
INCLUDEPATH += C:/OpenCV2_1/include/opencv
TEMPLATE = app
LIBS += C:/OpenCV2_1/lib/cxcore210d.lib \
C:/OpenCV2_1/lib/cv210d.lib \
C:/OpenCV2_1/lib/highgui210d.lib\
C:/OpenCV2_1/lib/cvaux210d.lib
SOURCES += main.cpp
I've tried to use -L and -l like LIBS += -LC:/OpenCV2_1/lib -lcxcored
And in .pro file:
QMAKE_LIBDIR += C:/OpenCV2_1/lib/Debug
LIBS += -lcxcore210d \
-lcv210d \
-lhighgui210d
The errors are like:
debug/main.o:C:\griskin\test\app\testopencv/../../../../OpenCV2_1/include/opencv/cxcore.hpp:97: undefined reference to cv::format(char const*, ...)'
Could anyone help me? Thanks!
In Visual Studio it works but I need it works in QTCreator..
Qt uses the MinGW compiler and linker. It will happily link OpenCV .libs when you use the C interface. However due to ABI issues, it will not link C++ modules.
You will have to either restrict yourself to the C interfaces only (i.e. no cv::Mat), or get OpenCV to compile with MinGw (or compile Qt in/with VS). Also, see this thread.
This is what my .pro file looks like
INCLUDEPATH += C:\\opencv\\release\\install\\include\
LIBS += -LC:\\opencv\\release\\install\\bin \
-lopencv_core240 \
-lopencv_highgui240 \
-lopencv_imgproc240 \
-lopencv_features2d240 \
-lopencv_calib3d240 \
and replace
#include <cv.h>
with
#include <opencv/cv.h>
Above .pro file works perfect for me. I have used mingw to compile OpenCV and using mingw compiler tool chain in Qt.
It seems that QtCreator cannot locate lib files.
Try specifying the include file and libs as follows.
INCLUDEPATH += C:/OpenCV2_1/build/include/
LIBS += C:/OpenCV2_1/build/gpu/x86/lib/cxcore210d.lib
you should refer to build folder if you're using pre-build version of opencv.
(I recommend pre-build version if you're not that familiar with opencv)

Resources