QVision and undefined reference to `vtable for QVCannyEdgeDetector' - c++

I have compiled and installed QVision on Archlinux. The libraries I have choosed to be compiled with QVision were qwt,opencv and cgal.
Now I want to compile this code. But can't compile.
#include <QVApplication>
#include <QVVideoReaderBlock>
#include <QVImageCanvas>
#include <QVCannyEdgeDetector>
#include <QVDefaultGUI>
int main(int argc, char *argv[])
{
QVApplication app(argc, argv,
"Example program for QVision library. Obtains Canny borders from input video frames."
);
QVVideoReaderBlock videoReader("Video reader");
QVCannyEdgeDetector cannyBlock("Canny block");
QVImageCanvas imageDisplayer("Original image");
QVImageCanvas edgesDisplayer("Canny edges");
videoReader.linkProperty(&cannyBlock,"Input image");
cannyBlock.linkProperty("Input image",imageDisplayer);
cannyBlock.linkProperty("Output image",edgesDisplayer);
QVDefaultGUI defaultGUI;
return app.exec();
}
and this is the .pro file I have used for the qt project:
LIBS = -L /opt/QVision/lib/lib*
INCLUDEPATH = /opt/QVision/src
TARGET = canvasInteract
SOURCES += main.cpp
and these are the errors I get:
main.cpp:-1: error: undefined reference to `QVCannyEdgeDetector::QVCannyEdgeDetector(QString)'
main.cpp:-1: error: undefined reference to `vtable for QVCannyEdgeDetector'
main.cpp:-1: error: undefined reference to `vtable for QVCannyEdgeDetector'
main.cpp:-1: error: undefined reference to `vtable for QVCannyEdgeDetector'
main.cpp:-1: error: undefined reference to `vtable for QVCannyEdgeDetector'
main.cpp:-1: error: more undefined reference to `vtable for QVCannyEdgeDetector'
:-1: error: collect2: error: ld returned 1 exit status
How can I solve this problem?

Related

How to statically link allegro5 (Linux, G++)?

I built the latest stable version of allegro5's source code following these steps
I have the following code (main.cpp):
#include <stdint.h>
#include <allegro5/allegro.h>
#include <allegro5/allegro_primitives.h>
int main()
{
al_init();
al_install_keyboard();
al_install_mouse();
al_init_primitives_addon();
al_set_new_display_flags(ALLEGRO_RESIZABLE);
ALLEGRO_DISPLAY* display = al_create_display(1280, 720);
al_set_window_title(display, "Allegro5 Window");
ALLEGRO_EVENT_QUEUE* queue = al_create_event_queue();
al_register_event_source(queue, al_get_display_event_source(display));
al_register_event_source(queue, al_get_keyboard_event_source());
al_register_event_source(queue, al_get_mouse_event_source());
bool running = true;
while (running)
{
ALLEGRO_EVENT ev;
while (al_get_next_event(queue, &ev))
{
if (ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE)
running = false;
if (ev.type == ALLEGRO_EVENT_DISPLAY_RESIZE)
{
al_acknowledge_resize(display);
}
}
al_clear_to_color(al_map_rgba_f(0.25, 0.25, 0.25, 1));
al_flip_display();
}
al_destroy_event_queue(queue);
al_destroy_display(display);
return 0;
}
... And I am trying to build this source file using the following command:
g++ -g $(pkg-config --libs --static allegro-static-5 allegro_primitives-static-5) main.cpp -o main
Even though pkg-config detects everything, it still doesn't work. The output is:
/usr/bin/ld: /tmp/ccmxycjk.o: in function `main':
pwd/main.cpp:7: undefined reference to `al_install_system'
/usr/bin/ld: pwd/main.cpp:8: undefined reference to `al_install_keyboard'
/usr/bin/ld: pwd/main.cpp:9: undefined reference to `al_install_mouse'
/usr/bin/ld: pwd/main.cpp:10: undefined reference to `al_init_primitives_addon'
/usr/bin/ld: pwd/main.cpp:11: undefined reference to `al_set_new_display_flags'
/usr/bin/ld: pwd/main.cpp:12: undefined reference to `al_create_display'
/usr/bin/ld: pwd/main.cpp:13: undefined reference to `al_set_window_title'
/usr/bin/ld: pwd/main.cpp:14: undefined reference to `al_create_event_queue'
/usr/bin/ld: pwd/main.cpp:15: undefined reference to `al_get_display_event_source'
/usr/bin/ld: pwd/main.cpp:15: undefined reference to `al_register_event_source'
/usr/bin/ld: pwd/main.cpp:16: undefined reference to `al_get_keyboard_event_source'
/usr/bin/ld: pwd/main.cpp:16: undefined reference to `al_register_event_source'
/usr/bin/ld: pwd/main.cpp:17: undefined reference to `al_get_mouse_event_source'
/usr/bin/ld: pwd/main.cpp:17: undefined reference to `al_register_event_source'
/usr/bin/ld: pwd/main.cpp:23: undefined reference to `al_get_next_event'
/usr/bin/ld: pwd/main.cpp:29: undefined reference to `al_acknowledge_resize'
/usr/bin/ld: pwd/main.cpp:33: undefined reference to `al_map_rgba_f'
/usr/bin/ld: pwd/main.cpp:33: undefined reference to `al_clear_to_color'
/usr/bin/ld: pwd/main.cpp:34: undefined reference to `al_flip_display'
/usr/bin/ld: pwd/main.cpp:37: undefined reference to `al_destroy_event_queue'
/usr/bin/ld: pwd/main.cpp:38: undefined reference to `al_destroy_display'
OBS: PWD = project path. Running up-to-date Debian 10
I've tried compiling with '-l:', adding all the libs, etc. Nothing would work. Any ideas?
Before you #include <allegro5/...>, add:
#define ALLEGRO_STATICLINK
You may need to link with additional libraries used by Allegro as well, such as OpenGL32.lib (on Windows), to resolve OpenGL functions.

Simple linking test to MKL libraries fails

I wanted to test my MKL installation by compiling a simple program with the library:
#include <iostream>
#include <mkl.h>
int main(void)
{
std::cout << "Hello World\n";
return 0;
}
Now by using the MKL Link Line Advisor, I get the following compilation line:
g++ -DMKL_ILP64 -m64 -I${MKLROOT}/include test.cpp -L${MKLROOT}/lib/intel64 -Wl,--no-as-needed -lmkl_intel_ilp64 -lmkl_gnu_thread -lmkl_core -lgomp -lpthread -lm -ldl -o test
with using GCC-6.3.0 and MKLROOT set to the correct path. But when compiling, I get
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_gnu_thread.so: error: undefined reference to 'fopen'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_gnu_thread.so: error: undefined reference to 'fflush'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_gnu_thread.so: error: undefined reference to 'free'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_intel_ilp64.so: error: undefined reference to 'exit'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_intel_ilp64.so: error: undefined reference to 'memset'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_gnu_thread.so: error: undefined reference to 'strcasecmp'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_gnu_thread.so: error: undefined reference to 'fclose'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_gnu_thread.so: error: undefined reference to 'syscall'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_gnu_thread.so: error: undefined reference to 'strtol'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_gnu_thread.so: error: undefined reference to 'malloc'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_gnu_thread.so: error: undefined reference to 'strcmp'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_core.so: error: undefined reference to 'calloc'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_core.so: error: undefined reference to 'getenv'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_core.so: error: undefined reference to 'fwrite'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_core.so: error: undefined reference to '__ctype_b_loc'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_core.so: error: undefined reference to 'realloc'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_core.so: error: undefined reference to 'vfprintf'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_core.so: error: undefined reference to 'ceil'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_core.so: error: undefined reference to 'gettimeofday'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_core.so: error: undefined reference to 'strtoul'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_core.so: error: undefined reference to 'fopen64'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_core.so: error: undefined reference to 'strtod'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_core.so: error: undefined reference to 'stdout'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_core.so: error: undefined reference to 'sched_yield'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_core.so: error: undefined reference to 'mmap'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_core.so: error: undefined reference to 'fread'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_core.so: error: undefined reference to 'stderr'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_core.so: error: undefined reference to 'mprotect'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_core.so: error: undefined reference to 'qsort'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_core.so: error: undefined reference to 'munmap'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_core.so: error: undefined reference to 'getuid'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_core.so: error: undefined reference to 'vsnprintf'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_core.so: error: undefined reference to 'strchr'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_core.so: error: undefined reference to 'isspace'
/home/rolandar/local_opt/intel/mkl/lib/intel64/libmkl_core.so: error: undefined reference to 'strdup'
Is my MKL-installation broken? Or did I forget something else?
When removing the option -ldl, it works, but I have no explanation, why.
Could you try this?
-L${MKLROOT}/lib/intel64 Wl,--no-as-needed -lmkl_rt -lpthread -lm -ldl

Error when trying to use NTL vector

I am trying to use NTL::Vec, but I get this error whenever I want to use SetLength()
The c++ code:
#include <NTL/ZZ.h>
#include <NTL/vector.h>
int main(int argc, const char * argv[]) {
NTL::Vec<NTL::ZZ> v;
v.SetLength(8);
return 0;
}
The error message:
/usr/include/NTL/ZZ.h:78: undefined reference to `_ntl_gfree(void**)'
./main.o: In function `NTL::Vec<NTL::ZZ>::AllocateTo(long)':
/usr/include/NTL/vector.h:334: undefined reference to `NTL::Error(char const*)'
/usr/include/NTL/vector.h:337: undefined reference to `NTL::Error(char const*)'
/usr/include/NTL/vector.h:343: undefined reference to `NTL::Error(char const*)'
/usr/include/NTL/vector.h:354: undefined reference to `NTL::Error(char const*)'
/usr/include/NTL/vector.h:369: undefined reference to `NTL::Error(char const*)'
collect2: error: ld returned 1 exit status
If I don't use v.SetLength(8), I don't get an error and everything is fine. What could be the problem ?
Thank you in advance

Gtest: test compiling error

I'm trying to test a motor control lib I've wrote with googletest but I'm not been to compile the test's codes.
The test are in a file named test.cpp such as the following:
#include <gtest/gtest.h>
#include "../motor.hpp"
TEST(constructorTest, contructorDefault)
{
}
And I've put a the tests main function in an other file named main.cpp.
#include <gtest/gtest.h>
#include "../motor.hpp"
int main(int argc, char* argv[])
{
::testing::InitGoogleTest(&argc,argv);
RUN_ALL_TESTS();
}
To compile I've excecuted the following line:
g++ main.cpp test.cpp ../motor.cpp -o test
The result I get is:
main.cpp:8:17: warning: ignoring return value of ‘int RUN_ALL_TESTS()’, declared with attribute warn_unused_result [-Wunused-result]
RUN_ALL_TESTS();
^
/tmp/ccZ5BaBH.o: In function `main':
main.cpp:(.text+0x1e): undefined reference to `testing::InitGoogleTest(int*, char**)'
/tmp/ccZ5BaBH.o: In function `RUN_ALL_TESTS()':
main.cpp:(.text._Z13RUN_ALL_TESTSv[_Z13RUN_ALL_TESTSv]+0x5): undefined reference to `testing::UnitTest::GetInstance()'
main.cpp:(.text._Z13RUN_ALL_TESTSv[_Z13RUN_ALL_TESTSv]+0xd): undefined reference to `testing::UnitTest::Run()'
/tmp/ccFuAMp3.o: In function `__static_initialization_and_destruction_0(int, int)':
test.cpp:(.text+0x5c): undefined reference to `testing::internal::GetTestTypeId()'
test.cpp:(.text+0x84): undefined reference to `testing::internal::MakeAndRegisterTestInfo(char const*, char const*, char const*, char const*, void const*, void (*)(), void (*)(), testing::internal::TestFactoryBase*)'
/tmp/ccFuAMp3.o: In function `constructorTest_contructorDefault_Test::constructorTest_contructorDefault_Test()':
test.cpp:(.text._ZN38constructorTest_contructorDefault_TestC2Ev[_ZN38constructorTest_contructorDefault_TestC5Ev]+0x14): undefined reference to `testing::Test::Test()'
/tmp/ccFuAMp3.o:(.rodata._ZTV38constructorTest_contructorDefault_Test[_ZTV38constructorTest_contructorDefault_Test]+0x20): undefined reference to `testing::Test::SetUp()'
/tmp/ccFuAMp3.o:(.rodata._ZTV38constructorTest_contructorDefault_Test[_ZTV38constructorTest_contructorDefault_Test]+0x28): undefined reference to `testing::Test::TearDown()'
/tmp/ccFuAMp3.o: In function `constructorTest_contructorDefault_Test::~constructorTest_contructorDefault_Test()':
test.cpp:(.text._ZN38constructorTest_contructorDefault_TestD2Ev[_ZN38constructorTest_contructorDefault_TestD5Ev]+0x1f): undefined reference to `testing::Test::~Test()'
/tmp/ccFuAMp3.o:(.rodata._ZTI38constructorTest_contructorDefault_Test[_ZTI38constructorTest_contructorDefault_Test]+0x10): undefined reference to `typeinfo for testing::Test'
collect2: error: ld returned 1 exit status
If I remove the test.cpp of the compiling line I get this other result:
main.cpp: In function ‘int main(int, char**)’:
main.cpp:8:17: warning: ignoring return value of ‘int RUN_ALL_TESTS()’, declared with attribute warn_unused_result [-Wunused-result]
RUN_ALL_TESTS();
^
/tmp/cc61r6NU.o: In function `main':
main.cpp:(.text+0x1e): undefined reference to `testing::InitGoogleTest(int*, char**)'
/tmp/cc61r6NU.o: In function `RUN_ALL_TESTS()':
main.cpp:(.text._Z13RUN_ALL_TESTSv[_Z13RUN_ALL_TESTSv]+0x5): undefined reference to `testing::UnitTest::GetInstance()'
main.cpp:(.text._Z13RUN_ALL_TESTSv[_Z13RUN_ALL_TESTSv]+0xd): undefined reference to `testing::UnitTest::Run()'
collect2: error: ld returned 1 exit status
What am I doing wrong?
EDIT
Look like What #RippeR says is right, but now I getting the following error:
/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../../lib/libgtest.so: undefined reference to `pthread_key_create'
/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../../lib/libgtest.so: undefined reference to `pthread_getspecific'
/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../../lib/libgtest.so: undefined reference to `pthread_key_delete'
/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../../lib/libgtest.so: undefined reference to `pthread_setspecific'
Do I have to include something else?
Solution
The problem was solve adding the -lpthread flag to compile the test.
Try:
g++ main.cpp test.cpp ../motor.cpp -o test -lgtest -lpthread
You have to link external libraries you are using. Including headers is not enough (unless library is header-only). If this solutions doesn't work, or you get error about gcc cannot find lgtest or gtest then you need to install it first (see here).
Also, note that RUN_ALL_TESTS(); returns a value, so your main() should look like:
#include <gtest/gtest.h>
#include "../motor.hpp"
int main(int argc, char* argv[])
{
::testing::InitGoogleTest(&argc,argv);
return RUN_ALL_TESTS();
}
I've updated answer (check 2nd line) to cover your next problem. This is same as before, you really should start to FIND answers to your problems instead of just asking and waiting for someone to do all the work for you.

Compile error when linking against two libraries in C++

compile command:
g++ ast01.cpp -o ast01 -lglu -lglut
error:
/usr/bin/ld: error: cannot find -lglu
/tmp/ccjQZPPr.o:ast01.cpp:function displaySpiral(): error: undefined reference to 'glClear'
/tmp/ccjQZPPr.o:ast01.cpp:function displaySpiral(): error: undefined reference to 'glBegin'
/tmp/ccjQZPPr.o:ast01.cpp:function displaySpiral(): error: undefined reference to 'glColor3ub'
/tmp/ccjQZPPr.o:ast01.cpp:function displaySpiral(): error: undefined reference to 'glEnd'
/tmp/ccjQZPPr.o:ast01.cpp:function displaySpiral(): error: undefined reference to 'glFlush'
/tmp/ccjQZPPr.o:ast01.cpp:function openGLinit(int, char**): error: undefined reference to 'glClearColor'
/tmp/ccjQZPPr.o:ast01.cpp:function openGLinit(int, char**): error: undefined reference to 'glMatrixMode'
/tmp/ccjQZPPr.o:ast01.cpp:function openGLinit(int, char**): error: undefined reference to 'glLoadIdentity'
/tmp/ccjQZPPr.o:ast01.cpp:function openGLinit(int, char**): error: undefined reference to 'gluOrtho2D'
/tmp/ccjQZPPr.o:ast01.cpp:function openGLinit(int, char**): error: undefined reference to 'glMatrixMode'
collect2: ld returned 1 exit status