Compiling Qt5 App on Raspberry - c++

I'd like to compile a program on my Raspberry Pi 3.
I've installed the latest Raspbian and crosscompiled Qt 5.8 as described in this manual and then I've tried to build GST to run it on the board. The compile process seems to finish, however, I've got following linker errors:
root#raspberrypi:/home/pi/headunit-WIP-headunit-gst/gst# make
g++ -fPIC -std=c++11 `pkg-config --cflags gstreamer-1.0 gstreamer-app-1.0 gstreamer-video-1.0 libcrypto libusb-1.0 openssl` -I../jni -I/opt/Qt5.8/include/QtWidgets -I/opt/Qt5.8/include -I/opt/Qt5.8/include/QtGui -c main.cc -o main.o
g++ -o headunit ../jni/hu_aad.o ../jni/hu_aap.o ../jni/hu_ssl.o ../jni/hu_usb.o ../jni/hu_uti.o main.o `pkg-config --libs gstreamer-1.0 gstreamer-app-1.0 gstreamer-video-1.0 libcrypto libusb-1.0 openssl` -L/opt/Qt5.8/include/QtCore/QtCore -L/opt/Qt5.8/include/QtWidgets/QtWidgets -L/opt/Qt5.8/include/QtGui/QtGui
main.o: In function `gst_loop(gst_app_t*, QApplication*)':
main.cc:(.text+0xb5c): undefined reference to `QApplication::exec()'
main.o: In function `main':
main.cc:(.text+0x10e0): undefined reference to `QApplication::QApplication(int&, char**, int)'
main.cc:(.text+0x10f0): undefined reference to `qFlagLocation(char const*)'
main.cc:(.text+0x1104): undefined reference to `qFlagLocation(char const*)'
main.cc:(.text+0x1134): undefined reference to `QObject::connect(QObject const*, char const*, QObject const*, char const*, Qt::ConnectionType)'
main.cc:(.text+0x1140): undefined reference to `QMetaObject::Connection::~Connection()'
main.cc:(.text+0x1178): undefined reference to `QWidget::show()'
main.cc:(.text+0x11bc): undefined reference to `QWidget::winId() const'
main.cc:(.text+0x1280): undefined reference to `QWidget::hide()'
main.cc:(.text+0x12c4): undefined reference to `QApplication::~QApplication()'
main.cc:(.text+0x12e4): undefined reference to `QApplication::~QApplication()'
main.o: In function `QWidget::resize(int, int)':
main.cc:(.text._ZN7QWidget6resizeEii[_ZN7QWidget6resizeEii]+0x38): undefined reference to `QWidget::resize(QSize const&)'
main.o: In function `HuMainWindow::HuMainWindow()':
main.cc:(.text._ZN12HuMainWindowC2Ev[_ZN12HuMainWindowC5Ev]+0x38): undefined reference to `QMainWindow::QMainWindow(QWidget*, QFlags<Qt::WindowType>)'
main.o: In function `HuMainWindow::~HuMainWindow()':
main.cc:(.text._ZN12HuMainWindowD2Ev[_ZN12HuMainWindowD5Ev]+0x48): undefined reference to `QMainWindow::~QMainWindow()'
main.o:(.data.rel.ro._ZTV12HuMainWindow[_ZTV12HuMainWindow]+0x8): undefined reference to `QMainWindow::metaObject() const'
main.o:(.data.rel.ro._ZTV12HuMainWindow[_ZTV12HuMainWindow]+0xc): undefined reference to `QMainWindow::qt_metacast(char const*)'
main.o:(.data.rel.ro._ZTV12HuMainWindow[_ZTV12HuMainWindow]+0x10): undefined reference to `QMainWindow::qt_metacall(QMetaObject::Call, int, void**)'
main.o:(.data.rel.ro._ZTV12HuMainWindow[_ZTV12HuMainWindow]+0x1c): undefined reference to `QMainWindow::event(QEvent*)'
main.o:(.data.rel.ro._ZTV12HuMainWindow[_ZTV12HuMainWindow]+0x20): undefined reference to `QObject::eventFilter(QObject*, QEvent*)'
main.o:(.data.rel.ro._ZTV12HuMainWindow[_ZTV12HuMainWindow]+0x24): undefined reference to `QObject::timerEvent(QTimerEvent*)'
main.o:(.data.rel.ro._ZTV12HuMainWindow[_ZTV12HuMainWindow]+0x28): undefined reference to `QObject::childEvent(QChildEvent*)'
main.o:(.data.rel.ro._ZTV12HuMainWindow[_ZTV12HuMainWindow]+0x2c): undefined reference to `QObject::customEvent(QEvent*)'
main.o:(.data.rel.ro._ZTV12HuMainWindow[_ZTV12HuMainWindow]+0x30): undefined reference to `QObject::connectNotify(QMetaMethod const&)'
main.o:(.data.rel.ro._ZTV12HuMainWindow[_ZTV12HuMainWindow]+0x34): undefined reference to `QObject::disconnectNotify(QMetaMethod const&)'
main.o:(.data.rel.ro._ZTV12HuMainWindow[_ZTV12HuMainWindow]+0x38): undefined reference to `QWidget::devType() const'
main.o:(.data.rel.ro._ZTV12HuMainWindow[_ZTV12HuMainWindow]+0x3c): undefined reference to `QWidget::setVisible(bool)'
main.o:(.data.rel.ro._ZTV12HuMainWindow[_ZTV12HuMainWindow]+0x40): undefined reference to `QWidget::sizeHint() const'
main.o:(.data.rel.ro._ZTV12HuMainWindow[_ZTV12HuMainWindow]+0x44): undefined reference to `QWidget::minimumSizeHint() const'
main.o:(.data.rel.ro._ZTV12HuMainWindow[_ZTV12HuMainWindow]+0x48): undefined reference to `QWidget::heightForWidth(int) const'
main.o:(.data.rel.ro._ZTV12HuMainWindow[_ZTV12HuMainWindow]+0x4c): undefined reference to `QWidget::hasHeightForWidth() const'
main.o:(.data.rel.ro._ZTV12HuMainWindow[_ZTV12HuMainWindow]+0x50): undefined reference to `QWidget::paintEngine() const'
main.o:(.data.rel.ro._ZTV12HuMainWindow[_ZTV12HuMainWindow]+0x5c): undefined reference to `QWidget::mouseDoubleClickEvent(QMouseEvent*)'
main.o:(.data.rel.ro._ZTV12HuMainWindow[_ZTV12HuMainWindow]+0x64): undefined reference to `QWidget::wheelEvent(QWheelEvent*)'
main.o:(.data.rel.ro._ZTV12HuMainWindow[_ZTV12HuMainWindow]+0x68): undefined reference to `QWidget::keyPressEvent(QKeyEvent*)'
main.o:(.data.rel.ro._ZTV12HuMainWindow[_ZTV12HuMainWindow]+0x6c): undefined reference to `QWidget::keyReleaseEvent(QKeyEvent*)'
main.o:(.data.rel.ro._ZTV12HuMainWindow[_ZTV12HuMainWindow]+0x70): undefined reference to `QWidget::focusInEvent(QFocusEvent*)'
main.o:(.data.rel.ro._ZTV12HuMainWindow[_ZTV12HuMainWindow]+0x74): undefined reference to `QWidget::focusOutEvent(QFocusEvent*)'
main.o:(.data.rel.ro._ZTV12HuMainWindow[_ZTV12HuMainWindow]+0x78): undefined reference to `QWidget::enterEvent(QEvent*)'
main.o:(.data.rel.ro._ZTV12HuMainWindow[_ZTV12HuMainWindow]+0x7c): undefined reference to `QWidget::leaveEvent(QEvent*)'
main.o:(.data.rel.ro._ZTV12HuMainWindow[_ZTV12HuMainWindow]+0x80): undefined reference to `QWidget::paintEvent(QPaintEvent*)'
main.o:(.data.rel.ro._ZTV12HuMainWindow[_ZTV12HuMainWindow]+0x84): undefined reference to `QWidget::moveEvent(QMoveEvent*)'
main.o:(.data.rel.ro._ZTV12HuMainWindow[_ZTV12HuMainWindow]+0x88): undefined reference to `QWidget::resizeEvent(QResizeEvent*)'
main.o:(.data.rel.ro._ZTV12HuMainWindow[_ZTV12HuMainWindow]+0x8c): undefined reference to `QWidget::closeEvent(QCloseEvent*)'
main.o:(.data.rel.ro._ZTV12HuMainWindow[_ZTV12HuMainWindow]+0x90): undefined reference to `QMainWindow::contextMenuEvent(QContextMenuEvent*)'
main.o:(.data.rel.ro._ZTV12HuMainWindow[_ZTV12HuMainWindow]+0x94): undefined reference to `QWidget::tabletEvent(QTabletEvent*)'
main.o:(.data.rel.ro._ZTV12HuMainWindow[_ZTV12HuMainWindow]+0x98): undefined reference to `QWidget::actionEvent(QActionEvent*)'
main.o:(.data.rel.ro._ZTV12HuMainWindow[_ZTV12HuMainWindow]+0x9c): undefined reference to `QWidget::dragEnterEvent(QDragEnterEvent*)'
main.o:(.data.rel.ro._ZTV12HuMainWindow[_ZTV12HuMainWindow]+0xa0): undefined reference to `QWidget::dragMoveEvent(QDragMoveEvent*)'
main.o:(.data.rel.ro._ZTV12HuMainWindow[_ZTV12HuMainWindow]+0xa4): undefined reference to `QWidget::dragLeaveEvent(QDragLeaveEvent*)'
main.o:(.data.rel.ro._ZTV12HuMainWindow[_ZTV12HuMainWindow]+0xa8): undefined reference to `QWidget::dropEvent(QDropEvent*)'
main.o:(.data.rel.ro._ZTV12HuMainWindow[_ZTV12HuMainWindow]+0xac): undefined reference to `QWidget::showEvent(QShowEvent*)'
main.o:(.data.rel.ro._ZTV12HuMainWindow[_ZTV12HuMainWindow]+0xb0): undefined reference to `QWidget::hideEvent(QHideEvent*)'
main.o:(.data.rel.ro._ZTV12HuMainWindow[_ZTV12HuMainWindow]+0xb4): undefined reference to `QWidget::nativeEvent(QByteArray const&, void*, long*)'
main.o:(.data.rel.ro._ZTV12HuMainWindow[_ZTV12HuMainWindow]+0xb8): undefined reference to `QWidget::changeEvent(QEvent*)'
main.o:(.data.rel.ro._ZTV12HuMainWindow[_ZTV12HuMainWindow]+0xbc): undefined reference to `QWidget::metric(QPaintDevice::PaintDeviceMetric) const'
main.o:(.data.rel.ro._ZTV12HuMainWindow[_ZTV12HuMainWindow]+0xc0): undefined reference to `QWidget::initPainter(QPainter*) const'
main.o:(.data.rel.ro._ZTV12HuMainWindow[_ZTV12HuMainWindow]+0xc4): undefined reference to `QWidget::redirected(QPoint*) const'
main.o:(.data.rel.ro._ZTV12HuMainWindow[_ZTV12HuMainWindow]+0xc8): undefined reference to `QWidget::sharedPainter() const'
main.o:(.data.rel.ro._ZTV12HuMainWindow[_ZTV12HuMainWindow]+0xcc): undefined reference to `QWidget::inputMethodEvent(QInputMethodEvent*)'
main.o:(.data.rel.ro._ZTV12HuMainWindow[_ZTV12HuMainWindow]+0xd0): undefined reference to `QWidget::inputMethodQuery(Qt::InputMethodQuery) const'
main.o:(.data.rel.ro._ZTV12HuMainWindow[_ZTV12HuMainWindow]+0xd4): undefined reference to `QWidget::focusNextPrevChild(bool)'
main.o:(.data.rel.ro._ZTV12HuMainWindow[_ZTV12HuMainWindow]+0xd8): undefined reference to `QMainWindow::createPopupMenu()'
main.o:(.data.rel.ro._ZTV12HuMainWindow[_ZTV12HuMainWindow]+0xec): undefined reference to `non-virtual thunk to QWidget::devType() const'
main.o:(.data.rel.ro._ZTV12HuMainWindow[_ZTV12HuMainWindow]+0xf0): undefined reference to `non-virtual thunk to QWidget::paintEngine() const'
main.o:(.data.rel.ro._ZTV12HuMainWindow[_ZTV12HuMainWindow]+0xf4): undefined reference to `non-virtual thunk to QWidget::metric(QPaintDevice::PaintDeviceMetric) const'
main.o:(.data.rel.ro._ZTV12HuMainWindow[_ZTV12HuMainWindow]+0xf8): undefined reference to `non-virtual thunk to QWidget::initPainter(QPainter*) const'
main.o:(.data.rel.ro._ZTV12HuMainWindow[_ZTV12HuMainWindow]+0xfc): undefined reference to `non-virtual thunk to QWidget::redirected(QPoint*) const'
main.o:(.data.rel.ro._ZTV12HuMainWindow[_ZTV12HuMainWindow]+0x100): undefined reference to `non-virtual thunk to QWidget::sharedPainter() const'
main.o:(.data.rel.ro._ZTI12HuMainWindow[_ZTI12HuMainWindow]+0x8): undefined reference to `typeinfo for QMainWindow'
collect2: error: ld returned 1 exit status
Makefile:23: recipe for target 'headunit' failed
make: *** [headunit] Error 1
As far as I understand, there is no reference to QApplication, but I wrote it in the Makefile:
CC=gcc
CPP=g++
LD=ld
INCLUDES=`pkg-config --cflags gstreamer-1.0 gstreamer-app-1.0 gstreamer-video-1.0 libcrypto libusb-1.0 openssl` -I$(TOP)/jni -I/opt/Qt5.8/include/QtWidgets -I/opt/Qt5.8/include -I/opt/Qt5.8/include/QtGui
CFLAGS=
CPPFLAGS=-fPIC -std=c++11
LFLAGS=`pkg-config --libs gstreamer-1.0 gstreamer-app-1.0 gstreamer-video-1.0 libcrypto libusb-1.0 openssl` -L/opt/Qt5.8/include/QtCore/QtCore -L/opt/Qt5.8/include/QtWidgets/QtWidgets -L/opt/Qt5.8/include/QtGui/QtGui
TOP = ..
AASRCS = $(TOP)/jni/hu_aad.c \
$(TOP)/jni/hu_aap.c \
$(TOP)/jni/hu_ssl.c \
$(TOP)/jni/hu_usb.c \
$(TOP)/jni/hu_uti.c
HSRCS = main.cc
OBJS = $(AASRCS:.c=.o) $(HSRCS:.cc=.o)
APP = headunit
.PHONY: depend clean
all: $(APP)
$(APP): $(OBJS)
$(CPP) -o $(APP) $(OBJS) $(LFLAGS)
.c.o:
$(CC) $(CFLAGS) $(INCLUDES) -c $< -o $#
.cc.o:
$(CPP) $(CPPFLAGS) $(INCLUDES) -c $< -o $#
clean:
rm -f $(OBJS) *~ $(APP)
depend: $(SRCS)
makedepend $^
# DO NOT DELETE
I also tried qmake -project to get a project file and then qmake and make.
But then i receive other errors.
Maybe someone can help me fixing these problems to finally compile this program.

did you try to let the Pi find the libraries by adding the /lib folder of the Qt installation to ld.so.conf?
In your case this would maybe look like echo /opt/Qt5.8/lib | sudo tee /etc/ld.so.conf.d/qt5pi.conf
After that you have to reload the ld.so.conf by using sudo ldconfig
Now the linker can find the Qt-Libs without any additions to your Makefile.
Maybe this will help you.

Related

Error in opengl undefined reference to symbol

I am running an OpenGL C++ file with fragment and vertex files.
I am on Ubuntu 18.04.
The problem is that when I link with g++ command I get errors :
my first linking command was :
g++ -o proj prog.cpp -lGL -lm
and I am getting these errors :
/tmp/ccdaDttM.o: In function `main':
prog.cpp:(.text+0x18): undefined reference to `glfwInit'
prog.cpp:(.text+0x27): undefined reference to `glfwWindowHint'
prog.cpp:(.text+0x36): undefined reference to `glfwWindowHint'
prog.cpp:(.text+0x45): undefined reference to `glfwWindowHint'
prog.cpp:(.text+0x54): undefined reference to `glfwWindowHint'
prog.cpp:(.text+0x63): undefined reference to `glfwWindowHint'
prog.cpp:(.text+0x84): undefined reference to `glfwCreateWindow'
prog.cpp:(.text+0x9f): undefined reference to `glfwGetFramebufferSize'
prog.cpp:(.text+0xd3): undefined reference to `glfwTerminate'
prog.cpp:(.text+0xe9): undefined reference to `glfwMakeContextCurrent'
prog.cpp:(.text+0xef): undefined reference to `glewExperimental'
prog.cpp:(.text+0xf5): undefined reference to `glewInit'
prog.cpp:(.text+0x22c): undefined reference to `__glewGenVertexArrays'
prog.cpp:(.text+0x241): undefined reference to `__glewGenBuffers'
prog.cpp:(.text+0x256): undefined reference to `__glewBindVertexArray'
prog.cpp:(.text+0x264): undefined reference to `__glewBindBuffer'
prog.cpp:(.text+0x277): undefined reference to `__glewBufferData'
prog.cpp:(.text+0x293): undefined reference to `__glewVertexAttribPointer'
prog.cpp:(.text+0x2bc): undefined reference to `__glewEnableVertexAttribArray'
prog.cpp:(.text+0x2ca): undefined reference to `__glewVertexAttribPointer'
prog.cpp:(.text+0x2f3): undefined reference to `__glewEnableVertexAttribArray'
prog.cpp:(.text+0x301): undefined reference to `__glewBindVertexArray'
prog.cpp:(.text+0x314): undefined reference to `glfwWindowShouldClose'
prog.cpp:(.text+0x326): undefined reference to `glfwPollEvents'
prog.cpp:(.text+0x368): undefined reference to `__glewBindVertexArray'
prog.cpp:(.text+0x38a): undefined reference to `__glewBindVertexArray'
prog.cpp:(.text+0x39d): undefined reference to `glfwSwapBuffers'
prog.cpp:(.text+0x3a9): undefined reference to `__glewDeleteVertexArrays'
prog.cpp:(.text+0x3be): undefined reference to `__glewDeleteBuffers'
prog.cpp:(.text+0x3d1): undefined reference to `glfwTerminate'
/tmp/ccdaDttM.o: In function `Shader::Shader(char const*, char const*)':
prog.cpp:(.text._ZN6ShaderC2EPKcS1_[_ZN6ShaderC5EPKcS1_]+0x27b): undefined reference to `__glewCreateShader'
prog.cpp:(.text._ZN6ShaderC2EPKcS1_[_ZN6ShaderC5EPKcS1_]+0x28f): undefined reference to `__glewShaderSource'
prog.cpp:(.text._ZN6ShaderC2EPKcS1_[_ZN6ShaderC5EPKcS1_]+0x2af): undefined reference to `__glewCompileShader'
prog.cpp:(.text._ZN6ShaderC2EPKcS1_[_ZN6ShaderC5EPKcS1_]+0x2c0): undefined reference to `__glewGetShaderiv'
prog.cpp:(.text._ZN6ShaderC2EPKcS1_[_ZN6ShaderC5EPKcS1_]+0x2e7): undefined reference to `__glewGetShaderInfoLog'
prog.cpp:(.text._ZN6ShaderC2EPKcS1_[_ZN6ShaderC5EPKcS1_]+0x347): undefined reference to `__glewCreateShader'
prog.cpp:(.text._ZN6ShaderC2EPKcS1_[_ZN6ShaderC5EPKcS1_]+0x35b): undefined reference to `__glewShaderSource'
prog.cpp:(.text._ZN6ShaderC2EPKcS1_[_ZN6ShaderC5EPKcS1_]+0x37b): undefined reference to `__glewCompileShader'
prog.cpp:(.text._ZN6ShaderC2EPKcS1_[_ZN6ShaderC5EPKcS1_]+0x38c): undefined reference to `__glewGetShaderiv'
prog.cpp:(.text._ZN6ShaderC2EPKcS1_[_ZN6ShaderC5EPKcS1_]+0x3b3): undefined reference to `__glewGetShaderInfoLog'
prog.cpp:(.text._ZN6ShaderC2EPKcS1_[_ZN6ShaderC5EPKcS1_]+0x413): undefined reference to `__glewCreateProgram'
prog.cpp:(.text._ZN6ShaderC2EPKcS1_[_ZN6ShaderC5EPKcS1_]+0x427): undefined reference to `__glewAttachShader'
prog.cpp:(.text._ZN6ShaderC2EPKcS1_[_ZN6ShaderC5EPKcS1_]+0x443): undefined reference to `__glewAttachShader'
prog.cpp:(.text._ZN6ShaderC2EPKcS1_[_ZN6ShaderC5EPKcS1_]+0x45f): undefined reference to `__glewLinkProgram'
prog.cpp:(.text._ZN6ShaderC2EPKcS1_[_ZN6ShaderC5EPKcS1_]+0x473): undefined reference to `__glewGetProgramiv'
prog.cpp:(.text._ZN6ShaderC2EPKcS1_[_ZN6ShaderC5EPKcS1_]+0x49d): undefined reference to `__glewGetProgramInfoLog'
prog.cpp:(.text._ZN6ShaderC2EPKcS1_[_ZN6ShaderC5EPKcS1_]+0x500): undefined reference to `__glewDeleteShader'
prog.cpp:(.text._ZN6ShaderC2EPKcS1_[_ZN6ShaderC5EPKcS1_]+0x511): undefined reference to `__glewDeleteShader'
/tmp/ccdaDttM.o: In function `Shader::Use()':
prog.cpp:(.text._ZN6Shader3UseEv[_ZN6Shader3UseEv]+0xf): undefined reference to `__glewUseProgram'
collect2: error: ld returned 1 exit status
When I googled, I found this post : undefined reference to `__glewCreateShader`
and according to the post, I changed the command to :
g++ -o proj prog.cpp -lGLEW -lm
The long list of errors is reduced but still :
/usr/bin/ld: /tmp/ccSaE0MX.o: undefined reference to symbol 'glDrawArrays'
//usr/lib/x86_64-linux-gnu/libGL.so.1: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
I viewed several posts and they almost say the same thing
OpenGL library not linking
The command I tried :
g++ -o proj prog.cpp -lGLEW -lm -lGLU -lglut
g++ -o proj prog.cpp -lGL -lGLEW -lm
g++ -o proj prog.cpp -lGLEW -lGL -lm
g++ -o proj prog.cpp -lGLEW -lopengl32 -lm
g++ prog.cpp -lGL -lGLU -lGLEW -lGLFW -lm
g++ prog.cpp -lGL -lGLU -lGLEW -lglut -lm -o proj
include :
#include <iostream>
#define GLEW_STATIC
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include "Shader.h"
Update :
here is what I am getting now
g++ -o proj sample.cpp libglut.a -lGL -lm
/usr/bin/ld: libglut.a(glut_event.o): undefined reference to symbol 'XWithdrawWindow'
//usr/lib/x86_64-linux-gnu/libX11.so.6: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
Please tell me what am I doing wrong.
Thanks

How to link MinGW (gcc) and TBB

I am trying to compile my TBB program using MinGW. I know that TBB is installed on my machine correctly because it compiles just fine in Visual Studio. Do I have to do something more to tell MinGW where TBB is installed? Or is just linking the library all that is needed? I am getting these error, when trying to compile using gcc.
C:\Users\Owner\Desktop\New folder\OpenMP vs TBB>make
g++ -LC:\tbb\tbb\lib\intel64\vc14 -O3 -o pps avl.o main.o parPlaneSweep.o -fopenmp -ltbb
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text+0x433f): undefined reference to `tbb::task_group_context::init()'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text+0x435d): undefined reference to `tbb::internal::allocate_root_with_context_proxy::allocate(unsigned int) const'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text+0x439d): undefined reference to `tbb::internal::get_initial_auto_partitioner_divisor()'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text+0x43d0): undefined reference to `tbb::task_group_context::~task_group_context()'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text+0x47d5): undefined reference to `tbb::task_group_context::init()'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text+0x47f3): undefined reference to `tbb::internal::allocate_root_with_context_proxy::allocate(unsigned int) const'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text+0x4835): undefined reference to `tbb::internal::get_initial_auto_partitioner_divisor()'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text+0x4868): undefined reference to `tbb::task_group_context::~task_group_context()'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text+0x7743): undefined reference to `tbb::internal::allocate_continuation_proxy::allocate(unsigned int) const'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text+0x776c): undefined reference to `tbb::internal::allocate_child_proxy::allocate(unsigned int) const'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text+0x7a66): undefined reference to `tbb::task_group_context::is_group_execution_cancelled() const'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text+0x7abc): undefined reference to `tbb::internal::allocate_continuation_proxy::allocate(unsigned int) const'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text+0x7ae5): undefined reference to `tbb::internal::allocate_child_proxy::allocate(unsigned int) const'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text+0x8cab): undefined reference to `tbb::internal::allocate_continuation_proxy::allocate(unsigned int) const'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text+0x8cd4): undefined reference to `tbb::internal::allocate_child_proxy::allocate(unsigned int) const'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text+0x8f69): undefined reference to `tbb::task_group_context::is_group_execution_cancelled() const'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text+0x8fb4): undefined reference to `tbb::internal::allocate_continuation_proxy::allocate(unsigned int) const'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text+0x8fdd): undefined reference to `tbb::internal::allocate_child_proxy::allocate(unsigned int) const'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text$_ZN3tbb4flow11interface105graphD1Ev[__ZN3tbb4flow11interface105graphD1Ev]+0x43): undefined reference to `tbb::interface7::internal::task_arena_base::internal_execute(tbb::interface7::internal::delegate_base&) const'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text$_ZN3tbb4flow11interface105graphD1Ev[__ZN3tbb4flow11interface105graphD1Ev]+0x4e): undefined reference to `tbb::task_group_context::is_group_execution_cancelled() const'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text$_ZN3tbb4flow11interface105graphD1Ev[__ZN3tbb4flow11interface105graphD1Ev]+0x73): undefined reference to `tbb::interface5::internal::task_base::destroy(tbb::task&)'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text$_ZN3tbb4flow11interface105graphD1Ev[__ZN3tbb4flow11interface105graphD1Ev]+0x87): undefined reference to `tbb::task_group_context::~task_group_context()'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text$_ZN3tbb4flow11interface105graphD1Ev[__ZN3tbb4flow11interface105graphD1Ev]+0xe3): undefined reference to `tbb::interface7::internal::task_arena_base::internal_terminate()'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text$_ZN3tbb4flow11interface105graphD1Ev[__ZN3tbb4flow11interface105graphD1Ev]+0xf1): undefined reference to `tbb::task_group_context::reset()'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text$_ZN3tbb4flow11interface105graphD1Ev[__ZN3tbb4flow11interface105graphD1Ev]+0x10b): undefined reference to `tbb::interface7::internal::task_arena_base::internal_initialize()'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text$_ZN3tbb4flow11interface105graphD1Ev[__ZN3tbb4flow11interface105graphD1Ev]+0x12e): undefined reference to `tbb::task_group_context::reset()'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text$_ZN3tbb4flow11interface105graphD0Ev[__ZN3tbb4flow11interface105graphD0Ev]+0x44): undefined reference to `tbb::interface7::internal::task_arena_base::internal_execute(tbb::interface7::internal::delegate_base&) const'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text$_ZN3tbb4flow11interface105graphD0Ev[__ZN3tbb4flow11interface105graphD0Ev]+0x4f): undefined reference to `tbb::task_group_context::is_group_execution_cancelled() const'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text$_ZN3tbb4flow11interface105graphD0Ev[__ZN3tbb4flow11interface105graphD0Ev]+0x74): undefined reference to `tbb::interface5::internal::task_base::destroy(tbb::task&)'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text$_ZN3tbb4flow11interface105graphD0Ev[__ZN3tbb4flow11interface105graphD0Ev]+0x88): undefined reference to `tbb::task_group_context::~task_group_context()'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text$_ZN3tbb4flow11interface105graphD0Ev[__ZN3tbb4flow11interface105graphD0Ev]+0xf3): undefined reference to `tbb::interface7::internal::task_arena_base::internal_terminate()'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text$_ZN3tbb4flow11interface105graphD0Ev[__ZN3tbb4flow11interface105graphD0Ev]+0x101): undefined reference to `tbb::task_group_context::reset()'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text$_ZN3tbb4flow11interface105graphD0Ev[__ZN3tbb4flow11interface105graphD0Ev]+0x11b): undefined reference to `tbb::interface7::internal::task_arena_base::internal_initialize()'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text$_ZN3tbb4flow11interface105graphD0Ev[__ZN3tbb4flow11interface105graphD0Ev]+0x13e): undefined reference to `tbb::task_group_context::reset()'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text.unlikely+0xf3): undefined reference to `tbb::internal::allocate_root_with_context_proxy::free(tbb::task&) const'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text.unlikely+0xff): undefined reference to `tbb::task_group_context::~task_group_context()'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.text.unlikely+0x118): undefined reference to `tbb::internal::allocate_root_with_context_proxy::free(tbb::task&) const'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: parPlaneSweep.o:parPlaneSweep.cpp:(.rdata$_ZTVN3tbb10interface98internal9flag_taskE[__ZTVN3tbb10interface98internal9flag_taskE]+0x14): undefined reference to `tbb::task::note_affinity(unsigned short)'
collect2.exe: error: ld returned 1 exit status
Makefile:10: recipe for target 'pps' failed
make: *** [pps] Error 1
This is what my current Makefile looks like right now.
CC=gcc
CPLUSPLUS = g++
OPTFLAGS = -O3
TBB_INCLUDE_PATH = C:\tbb-2020.1-win\tbb\include
TBB_LIBRARY_PATH = C:\tbb\tbb\lib\intel64\vc14
all: pps
pps: avl.o main.o parPlaneSweep.o
$(CPLUSPLUS) -L$(TBB_LIBRARY_PATH) $(OPTFLAGS) -o $# $^ -fopenmp -ltbb
avl.o: avl.h avl.c
$(CC) -c $(OPTFLAGS) -fPIC avl.c
main.o: main.cpp parPlaneSweep.h
$(CPLUSPLUS) -c $(OPTFLAGS) -fopenmp main.cpp
parPlaneSweep.o: parPlaneSweep.h parPlaneSweep.cpp
$(CPLUSPLUS) -c $(OPTFLAGS) -ITBB_INCLUDE_PATH -fPIC -fopenmp parPlaneSweep.cpp
clean:
rm *.o
rm pps
MinGW and MSVC are different toolchains, even though both can produce EXE/DLL files in "native" Windows format. But the C++ symbol decoration (aka mangling) is done very differently, so the same function in source code would be compiled into differently named binary functions. There might also be more application binary interface (ABI) differences between the toolchains. Therefore you cannot simply link object files/libraries created by/for MinGW and by/for MSVC; you need all libraries to be prepared with the same toolchain.
You can build TBB binaries for MinGW on your own (it's supported in TBB makefiles), or you can try finding a ready-to-use package such as the one for MSYS2 mentioned in the comments to the question.

g++ undefined reference error on compiling

Im trying to compile my program on linux. It works great on Windows (compiled under Visual Studio 2015). But when I try to do the same on Linux, I get this error:
g++ -std=c++0x -std=c++0x Prueba1.cpp -o Prueba1
/tmp/cc9HTgYi.o: In function `Escuchador::onFrame(Leap::Controller const&)':
Prueba1.cpp:(.text+0x51): undefined reference to `Leap::Controller::frame(int) const'
Prueba1.cpp:(.text+0x6c): undefined reference to `Leap::Frame::fingers() const'
Prueba1.cpp:(.text+0x7d): undefined reference to `Leap::FingerList::count() const'
Prueba1.cpp:(.text+0x97): undefined reference to `Leap::Frame::hands() const'
Prueba1.cpp:(.text+0xa8): undefined reference to `Leap::HandList::count() const'
Prueba1.cpp:(.text+0xbc): undefined reference to `Leap::Frame::timestamp() const'
Prueba1.cpp:(.text+0xce): undefined reference to `Leap::Frame::id() const'
Prueba1.cpp:(.text+0x1ac): undefined reference to `Leap::Frame::hands() const'
Prueba1.cpp:(.text+0x1c7): undefined reference to `Leap::HandList::begin() const'
Prueba1.cpp:(.text+0x203): undefined reference to `Leap::Hand::isLeft() const'
Prueba1.cpp:(.text+0x245): undefined reference to `Leap::Hand::id() const'
Prueba1.cpp:(.text+0x2fc): undefined reference to `Leap::Hand::palmNormal() const'
Prueba1.cpp:(.text+0x317): undefined reference to `Leap::Hand::direction() const'
Prueba1.cpp:(.text+0x332): undefined reference to `Leap::Hand::fingers() const'
Prueba1.cpp:(.text+0x34d): undefined reference to `Leap::FingerList::begin() const'
Prueba1.cpp:(.text+0x37e): undefined reference to `Leap::Pointable::id() const'
Prueba1.cpp:(.text+0x38e): undefined reference to `Leap::Finger::type() const'
Prueba1.cpp:(.text+0x47b): undefined reference to `Leap::Finger::bone(Leap::Bone::Type) const'
Prueba1.cpp:(.text+0x510): undefined reference to `Leap::Frame::hands() const'
Prueba1.cpp:(.text+0x533): undefined reference to `Leap::HandList::operator[](int) const'
Prueba1.cpp:(.text+0x54e): undefined reference to `Leap::Hand::fingers() const'
Prueba1.cpp:(.text+0x582): undefined reference to `Leap::FingerList::begin() const'
Prueba1.cpp:(.text+0x595): undefined reference to `Leap::Bone::Bone()'
Prueba1.cpp:(.text+0x5ea): undefined reference to `Leap::Finger::bone(Leap::Bone::Type) const'
Prueba1.cpp:(.text+0x63e): undefined reference to `Leap::Finger::type() const'
Prueba1.cpp:(.text+0x67f): undefined reference to `Leap::operator<<(std::ostream&, Leap::Bone const&)'
Prueba1.cpp:(.text+0x6ee): undefined reference to `Leap::FingerList::end() const'
Prueba1.cpp:(.text+0x726): undefined reference to `Leap::Hand::fingers() const'
Prueba1.cpp:(.text+0x74d): undefined reference to `Leap::FingerList::begin() const'
Prueba1.cpp:(.text+0x768): undefined reference to `Leap::FingerList::end() const'
Prueba1.cpp:(.text+0x7ab): undefined reference to `Leap::Finger::bone(Leap::Bone::Type) const'
Prueba1.cpp:(.text+0x7ce): undefined reference to `Leap::Finger::bone(Leap::Bone::Type) const'
Prueba1.cpp:(.text+0x7f1): undefined reference to `Leap::Finger::bone(Leap::Bone::Type) const'
Prueba1.cpp:(.text+0x814): undefined reference to `Leap::Finger::bone(Leap::Bone::Type) const'
Prueba1.cpp:(.text+0x825): undefined reference to `Leap::Finger::type() const'
Prueba1.cpp:(.text+0x848): undefined reference to `Leap::Bone::direction() const'
Prueba1.cpp:(.text+0x863): undefined reference to `Leap::Bone::direction() const'
Prueba1.cpp:(.text+0x89e): undefined reference to `Leap::Bone::direction() const'
Prueba1.cpp:(.text+0x8b9): undefined reference to `Leap::Bone::direction() const'
Prueba1.cpp:(.text+0x8f4): undefined reference to `Leap::Bone::direction() const'
/tmp/cc9HTgYi.o:Prueba1.cpp:(.text+0x90c): more undefined references to `Leap::Bone::direction() const' follow
/tmp/cc9HTgYi.o: In function `Escuchador::onFrame(Leap::Controller const&)':
Prueba1.cpp:(.text+0xa15): undefined reference to `Leap::Finger::type() const'
Prueba1.cpp:(.text+0xa37): undefined reference to `Leap::Bone::direction() const'
Prueba1.cpp:(.text+0xa4f): undefined reference to `Leap::Bone::direction() const'
Prueba1.cpp:(.text+0xa87): undefined reference to `Leap::Bone::direction() const'
Prueba1.cpp:(.text+0xa9f): undefined reference to `Leap::Bone::direction() const'
Prueba1.cpp:(.text+0xad7): undefined reference to `Leap::Bone::direction() const'
/tmp/cc9HTgYi.o:Prueba1.cpp:(.text+0xaef): more undefined references to `Leap::Bone::direction() const' follow
/tmp/cc9HTgYi.o: In function `Escuchador::onFrame(Leap::Controller const&)':
Prueba1.cpp:(.text+0xbf8): undefined reference to `Leap::Finger::type() const'
Prueba1.cpp:(.text+0xc1b): undefined reference to `Leap::Bone::direction() const'
Prueba1.cpp:(.text+0xc33): undefined reference to `Leap::Bone::direction() const'
Prueba1.cpp:(.text+0xc6b): undefined reference to `Leap::Bone::direction() const'
Prueba1.cpp:(.text+0xc83): undefined reference to `Leap::Bone::direction() const'
Prueba1.cpp:(.text+0xcbb): undefined reference to `Leap::Bone::direction() const'
/tmp/cc9HTgYi.o:Prueba1.cpp:(.text+0xcd3): more undefined references to `Leap::Bone::direction() const' follow
/tmp/cc9HTgYi.o: In function `Escuchador::onFrame(Leap::Controller const&)':
Prueba1.cpp:(.text+0xeb4): undefined reference to `Leap::FingerList::end() const'
Prueba1.cpp:(.text+0xf27): undefined reference to `Leap::HandList::end() const'
/tmp/cc9HTgYi.o: In function `main':
Prueba1.cpp:(.text+0x11a3): undefined reference to `Leap::Controller::Controller()'
Prueba1.cpp:(.text+0x11b7): undefined reference to `Leap::Controller::addListener(Leap::Listener&)'
Prueba1.cpp:(.text+0x11fb): undefined reference to `Leap::Controller::removeListener(Leap::Listener&)'
Prueba1.cpp:(.text+0x120c): undefined reference to `Leap::Controller::~Controller()'
Prueba1.cpp:(.text+0x122a): undefined reference to `Leap::Controller::~Controller()'
/tmp/cc9HTgYi.o: In function `Leap::Pointable::~Pointable()':
Prueba1.cpp:(.text._ZN4Leap9PointableD2Ev[_ZN4Leap9PointableD5Ev]+0x16): undefined reference to `Leap::Interface::~Interface()'
/tmp/cc9HTgYi.o: In function `Leap::Bone::operator=(Leap::Bone&&)':
Prueba1.cpp:(.text._ZN4Leap4BoneaSEOS0_[_ZN4Leap4BoneaSEOS0_]+0x14): undefined reference to `Leap::Interface::operator=(Leap::Interface const&)'
/tmp/cc9HTgYi.o: In function `Leap::ConstListIterator<Leap::HandList, Leap::Hand>::operator*() const':
Prueba1.cpp:(.text._ZNK4Leap17ConstListIteratorINS_8HandListENS_4HandEEdeEv[_ZNK4Leap17ConstListIteratorINS_8HandListENS_4HandEEdeEv]+0x20): undefined reference to `Leap::HandList::operator[](int) const'
/tmp/cc9HTgYi.o: In function `Leap::ConstListIterator<Leap::FingerList, Leap::Finger>::operator*() const':
Prueba1.cpp:(.text._ZNK4Leap17ConstListIteratorINS_10FingerListENS_6FingerEEdeEv[_ZNK4Leap17ConstListIteratorINS_10FingerListENS_6FingerEEdeEv]+0x20): undefined reference to `Leap::FingerList::operator[](int) const'
/tmp/cc9HTgYi.o: In function `Leap::Frame::~Frame()':
Prueba1.cpp:(.text._ZN4Leap5FrameD2Ev[_ZN4Leap5FrameD5Ev]+0x16): undefined reference to `Leap::Interface::~Interface()'
/tmp/cc9HTgYi.o: In function `Leap::HandList::~HandList()':
Prueba1.cpp:(.text._ZN4Leap8HandListD2Ev[_ZN4Leap8HandListD5Ev]+0x16): undefined reference to `Leap::Interface::~Interface()'
/tmp/cc9HTgYi.o: In function `Leap::FingerList::~FingerList()':
Prueba1.cpp:(.text._ZN4Leap10FingerListD2Ev[_ZN4Leap10FingerListD5Ev]+0x16): undefined reference to `Leap::Interface::~Interface()'
/tmp/cc9HTgYi.o: In function `Leap::Hand::~Hand()':
Prueba1.cpp:(.text._ZN4Leap4HandD2Ev[_ZN4Leap4HandD5Ev]+0x16): undefined reference to `Leap::Interface::~Interface()'
/tmp/cc9HTgYi.o: In function `Leap::Bone::~Bone()':
Prueba1.cpp:(.text._ZN4Leap4BoneD2Ev[_ZN4Leap4BoneD5Ev]+0x16): undefined reference to `Leap::Interface::~Interface()'
/tmp/cc9HTgYi.o:(.rodata._ZTIN4Leap5FrameE[_ZTIN4Leap5FrameE]+0x8): undefined reference to `typeinfo for Leap::Interface'
/tmp/cc9HTgYi.o:(.rodata._ZTIN4Leap8HandListE[_ZTIN4Leap8HandListE]+0x8): undefined reference to `typeinfo for Leap::Interface'
/tmp/cc9HTgYi.o:(.rodata._ZTIN4Leap10FingerListE[_ZTIN4Leap10FingerListE]+0x8): undefined reference to `typeinfo for Leap::Interface'
/tmp/cc9HTgYi.o:(.rodata._ZTIN4Leap4HandE[_ZTIN4Leap4HandE]+0x8): undefined reference to `typeinfo for Leap::Interface'
/tmp/cc9HTgYi.o:(.rodata._ZTIN4Leap4BoneE[_ZTIN4Leap4BoneE]+0x8): undefined reference to `typeinfo for Leap::Interface'
/tmp/cc9HTgYi.o:(.rodata._ZTIN4Leap9PointableE[_ZTIN4Leap9PointableE]+0x8): more undefined references to `typeinfo for Leap::Interface' follow
collect2: error: ld returned 1 exit status
make: *** [Prueba1] Error 1
My #include are:
#include <iostream>
#include <cstring>
#include "Leap.h"
So it seems the problem is with the Leap.h header. In the SDK there is a Sample.cpp that I can compile and runs great. Im using the same makefile and the same filesystem; I am using the same #include than the Sample.cpp, so I move my .cpp file into the same folder the Sample.cpp is and try to compile, and I get the error. I dont know how to solve it, any ideas? Here is the makefile:
OS := $(shell uname)
ARCH := $(shell uname -m)
CXXFLAGS := -std=c++0x -std=c++0x
ifeq ($(OS), Linux)
ifeq ($(ARCH), x86_64)
LEAP_LIBRARY := ../lib/x64/libLeap.so -Wl,-rpath,../lib/x64
else
LEAP_LIBRARY := ../lib/x86/libLeap.so -Wl,-rpath,../lib/x86
endif
else
# OS X
LEAP_LIBRARY := ../lib/libLeap.dylib
endif
Sample: Sample.cpp
$(CXX) -Wall -g -I../include Sample.cpp -o Sample $(LEAP_LIBRARY)
ifeq ($(OS), Darwin)
install_name_tool -change #loader_path/libLeap.dylib ../lib/libLeap.dylib Sample
endif
clean:
rm -rf Sample Sample.dSYM
I only added the CXXFLAGS to solve a C+98 compiler error. I can compile the Sample.cpp this way too, but when I try to do the same on my file, I get the errors. Thanks for the help!
So it seems the problem is with the Leap.h header.
No, there's no problem with the header. You're simply not linking to the library that provides the definitions of those functions.
Look at how the makefile builds the sample program: it links to libleap.so,
You need to do the same:
g++ -std=c++0x -std=c++0x Prueba1.cpp -o Prueba1 ../lib/x64/libleap.so -Wl,-rpath,../lib/x64
(replacing x64 with x86 if you're on a 32-bit system).
First, required reading: What is an undefined reference/unresolved external symbol error and how do I fix it? Please read at least answers related to external library components, then return to this question.
OK so in your case you are running a link command without specifying the external library. How come? Why are you able to compile a sample that comes with the package?
Take a look at the makefile. It says
Sample: Sample.cpp
$(CXX) -Wall -g -I../include Sample.cpp -o Sample $(LEAP_LIBRARY)
This rule tells make three things: what to build (the first line before the colon), what to build it from (after the colon), and how to build it (the second line). So when you run a command like
make Sample
make has a pretty good idea what to do.
Now if you say
make Prueba1
things are a bit different. There are no special rules in the makefile that talk about Prueba1, so make fetches its (huge) set of built-in rules and looks for one that would allow it to build Prueba1 for you. There is indeed such a built-in rule, but it doesn't know about libLeap.so. This is why you don't see it in your build log.
Of course you can add something like this to your makefile:
Prueba1: Prueba1.cpp
$(CXX) -Wall -g -I../include Prueba1.cpp -o Prueba1 $(LEAP_LIBRARY)
but I'd venture to guess that it will grow somewhat old when you get to Prueba99. Can we do better?
Yes we can, but let's answer another question first. How come your compilation command knows about -std=c++0x?
This is because you added this flag to a built-in macro CXXFLAGS, and the built-in rule uses this macro. By the way you don't need to specify -std=c++0x twice.
Is there a way to treat the libraries similarly to compiler flags? Absolutely! There are two built in macros LDLIBS and LDFLAGS. If you define them this way:
LDLIBS := ../lib/x64/libLeap.so
LDFLAGS := -Wl,-rpath,../lib/x64
or (alternatively)
LDLIBS := -lLeap
LDFLAGS := -L ../lib/x64 -Wl,-rpath,../lib/x64
your makefile should be able to build any C++ program against libLeap (if it is written as a single C++ source file).
It is probably wise to add -I../include to CPPFLAGS since the Sample rule uses it. Your compilation seems to work without it but it may fail if you e.g. change your working directory.

Getting unexpected "undefined reference to" errors when compiling with a static library

I've been trying to make a static library out of this: https://github.com/onlinecity/cpp-smpp , as I'd like to make a single file executable that uses it.
So far I have gone into src/smpp/ and created the .o files with:
g++-5 -c *.cpp -std=c++11 -I.
Then made them into an .a file with:
ar rvs libsmpp.a *.o
Then I'm trying to compile a small main.cpp file that uses the library with this:
g++-5 main.cpp -I/usr/local/include -static libsmpp.a -lboost_system -lboost_regex -lboost_date_time -lpthread -lm -lglog -lgflags -std=c++11
And I get some undefined reference errors:
/usr/lib/gcc/x86_64-linux-gnu/5/libstdc++.a(condition_variable.o): In function `std::condition_variable::~condition_variable()':
(.text._ZNSt18condition_variableD2Ev+0x1): undefined reference to `pthread_cond_destroy'
/usr/lib/gcc/x86_64-linux-gnu/5/libstdc++.a(condition_variable.o): In function `std::condition_variable::wait(std::unique_lock<std::mutex>&)':
(.text._ZNSt18condition_variable4waitERSt11unique_lockISt5mutexE+0x8): undefined reference to `pthread_cond_wait'
libsmpp.a(smppclient.o): In function `smpp::SmppClient::sendPdu(smpp::PDU&)':
smppclient.cpp:(.text+0x22a1): undefined reference to `google::LogMessage::LogMessage(char const*, int)'
smppclient.cpp:(.text+0x22b0): undefined reference to `google::LogMessage::stream()'
smppclient.cpp:(.text+0x22d4): undefined reference to `google::LogMessage::~LogMessage()'
smppclient.cpp:(.text+0x2534): undefined reference to `google::LogMessage::~LogMessage()'
libsmpp.a(smppclient.o): In function `smpp::SmppClient::readPdu(bool const&)':
smppclient.cpp:(.text+0x29d8): undefined reference to `google::LogMessage::LogMessage(char const*, int)'
smppclient.cpp:(.text+0x29e7): undefined reference to `google::LogMessage::stream()'
smppclient.cpp:(.text+0x2a0b): undefined reference to `google::LogMessage::~LogMessage()'
smppclient.cpp:(.text+0x2a48): undefined reference to `google::LogMessage::~LogMessage()'
libsmpp.a(smppclient.o): In function `boost::asio::detail::posix_event::~posix_event()':
smppclient.cpp:(.text._ZN5boost4asio6detail11posix_eventD2Ev[_ZN5boost4asio6detail11posix_eventD5Ev]+0x14): undefined reference to `pthread_cond_destroy'
libsmpp.a(smppclient.o): In function `boost::asio::detail::posix_event::posix_event()':
smppclient.cpp:(.text._ZN5boost4asio6detail11posix_eventC2Ev[_ZN5boost4asio6detail11posix_eventC5Ev]+0x2e): undefined reference to `pthread_cond_init'
libsmpp.a(smppclient.o): In function `void boost::asio::detail::posix_event::wait<boost::asio::detail::scoped_lock<boost::asio::detail::posix_mutex> >(boost::asio::detail::scoped_lock<boost::asio::detail::posix_mutex>&)':
smppclient.cpp:(.text._ZN5boost4asio6detail11posix_event4waitINS1_11scoped_lockINS1_11posix_mutexEEEEEvRT_[_ZN5boost4asio6detail11posix_event4waitINS1_11scoped_lockINS1_11posix_mutexEEEEEvRT_]+0x5f): undefined reference to `pthread_cond_wait'
libsmpp.a(timeformat.o): In function `boost::date_time::month_formatter<boost::gregorian::greg_month, boost::date_time::iso_format<char>, char>::format_month(boost::gregorian::greg_month const&, std::ostream&)':
timeformat.cpp:(.text._ZN5boost9date_time15month_formatterINS_9gregorian10greg_monthENS0_10iso_formatIcEEcE12format_monthERKS3_RSo[_ZN5boost9date_time15month_formatterINS_9gregorian10greg_monthENS0_10iso_formatIcEEcE12format_monthERKS3_RSo]+0x33): undefined reference to `boost::gregorian::greg_month::as_short_string() const'
timeformat.cpp:(.text._ZN5boost9date_time15month_formatterINS_9gregorian10greg_monthENS0_10iso_formatIcEEcE12format_monthERKS3_RSo[_ZN5boost9date_time15month_formatterINS_9gregorian10greg_monthENS0_10iso_formatIcEEcE12format_monthERKS3_RSo]+0x56): undefined reference to `boost::gregorian::greg_month::as_long_string() const'
collect2: error: ld returned 1 exit status
It compiles fine when I link to a dynamic version of the smpp library, although that's made using the cmake files included with the smpp lib. I didn't know how to modify them to output a static library, so I just used the g++ command at the top, and added the libraries listed in them (like glog) in the main.cpp compile command.
The "undefined reference to google::logMessage" seems especially strange, as I'm pretty sure thats part of glog, which is definitely loaded and included in the smppclient.cpp file itself.
Any ideas? Thanks.

Why am I getting such error message in Installing Package?

I am currently running Ubuntu 12.04.
I am looking to install This Package.
I have already installed packages:
'fftw2', 'fftw-dev', 'fftw-doc', 'fftw-3.3.4'
However, when I try to root#ubuntu:~/spectrum-master# make:
cc -lm -lasound -L/usr/lib/x86_64-linux-gnu -lSDL -lfftw3f -lm spectrum.o mmap_file.o pcm.o wav.o alsa.o window.o stft.o cqt.o trans.o -o spectrum
spectrum.o: In function handle_events': /home/userKum/spectrum-master/spectrum.c:27: undefined reference toSDL_PollEvent'
spectrum.o: In function srgb': /home/userKum/spectrum-master/spectrum.c:78: undefined reference to__powf_finite'
/home/userKum/spectrum-master/spectrum.c:76: undefined reference to __powf_finite' /home/userKum/spectrum-master/spectrum.c:77: undefined reference to__powf_finite'
spectrum.o: In function main': /home/userKum/spectrum-master/spectrum.c:126: undefined reference toSDL_Init'
/home/userKum/spectrum-master/spectrum.c:127: undefined reference to SDL_SetVideoMode' /home/userKum/spectrum-master/spectrum.c:143: undefined reference toSDL_WM_SetCaption'
/home/userKum/spectrum-master/spectrum.c:144: undefined reference to SDL_EnableKeyRepeat' /home/userKum/spectrum-master/spectrum.c:199: undefined reference to__log10f_finite'
/home/userKum/spectrum-master/spectrum.c:157: undefined reference to SDL_Flip' /home/userKum/spectrum-master/spectrum.c:158: undefined reference toSDL_Delay'
alsa.o: In function write_alsa': /home/userKum/spectrum-master/alsa.c:71: undefined reference tosnd_pcm_writei'
/home/userKum/spectrum-master/alsa.c:72: undefined reference to snd_pcm_prepare' alsa.o: In functionread_alsa':
/home/userKum/spectrum-master/alsa.c:54: undefined reference to snd_pcm_readi' /home/userKum/spectrum-master/alsa.c:55: undefined reference tosnd_pcm_prepare'
alsa.o: In function close_alsa': /home/userKum/spectrum-master/alsa.c:26: undefined reference tosnd_pcm_drain'
/home/userKum/spectrum-master/alsa.c:27: undefined reference to snd_pcm_close' alsa.o: In functionopen_alsa_read':
/home/userKum/spectrum-master/alsa.c:92: undefined reference to snd_pcm_hw_params_sizeof' /home/userKum/spectrum-master/alsa.c:92: undefined reference tosnd_pcm_hw_params_sizeof'
/home/userKum/spectrum-master/alsa.c:94: undefined reference to snd_pcm_open' /home/userKum/spectrum-master/alsa.c:100: undefined reference tosnd_pcm_hw_params_any'
/home/userKum/spectrum-master/alsa.c:107: undefined reference to snd_pcm_hw_params_set_access' /home/userKum/spectrum-master/alsa.c:114: undefined reference tosnd_pcm_hw_params_set_format'
/home/userKum/spectrum-master/alsa.c:121: undefined reference to snd_pcm_hw_params_set_rate_resample' /home/userKum/spectrum-master/alsa.c:130: undefined reference tosnd_pcm_hw_params_set_rate_min'
/home/userKum/spectrum-master/alsa.c:109: undefined reference to snd_pcm_close' /home/userKum/spectrum-master/alsa.c:137: undefined reference tosnd_pcm_hw_params'
/home/userKum/spectrum-master/alsa.c:144: undefined reference to snd_pcm_hw_params_get_rate' /home/userKum/spectrum-master/alsa.c:151: undefined reference tosnd_pcm_hw_params_get_channels'
alsa.o: In function open_alsa_write': /home/userKum/spectrum-master/alsa.c:177: undefined reference tosnd_pcm_hw_params_sizeof'
/home/userKum/spectrum-master/alsa.c:177: undefined reference to snd_pcm_hw_params_sizeof' /home/userKum/spectrum-master/alsa.c:179: undefined reference tosnd_pcm_open'
/home/userKum/spectrum-master/alsa.c:185: undefined reference to snd_pcm_hw_params_any' /home/userKum/spectrum-master/alsa.c:192: undefined reference tosnd_pcm_hw_params_set_access'
/home/userKum/spectrum-master/alsa.c:199: undefined reference to snd_pcm_hw_params_set_format' /home/userKum/spectrum-master/alsa.c:206: undefined reference tosnd_pcm_hw_params_set_rate_resample'
/home/userKum/spectrum-master/alsa.c:213: undefined reference to snd_pcm_hw_params_set_rate_near' /home/userKum/spectrum-master/alsa.c:218: undefined reference tosnd_pcm_hw_params_set_channels_near'
/home/userKum/spectrum-master/alsa.c:223: undefined reference to snd_pcm_hw_params' /home/userKum/spectrum-master/alsa.c:194: undefined reference tosnd_pcm_close'
window.o: In function sinc': /home/userKum/spectrum-master/window.c:14: undefined reference tosinf'
window.o: In function hann': /home/userKum/spectrum-master/window.c:24: undefined reference tocosf'
window.o: In function hamming': /home/userKum/spectrum-master/window.c:29: undefined reference tocosf'
window.o: In function sinc': /home/userKum/spectrum-master/window.c:14: undefined reference tosinf'
window.o: In function gauss': /home/userKum/spectrum-master/window.c:38: undefined reference to__expf_finite'
stft.o: In function free_stft': /home/userKum/spectrum-master/stft.c:44: undefined reference tofftwf_destroy_plan'
stft.o: In function get_stft': /home/userKum/spectrum-master/stft.c:38: undefined reference tocabsf'
stft.o: In function create_stft': /home/userKum/spectrum-master/stft.c:66: undefined reference tofftwf_plan_dft_r2c_1d'
stft.o: In function slide_stft': /home/userKum/spectrum-master/stft.c:31: undefined reference tofftwf_execute'
cqt.o: In function get_cqt': /home/userKum/spectrum-master/cqt.c:33: undefined reference tocabsf'
cqt.o: In function free_cqt': /home/userKum/spectrum-master/cqt.c:47: undefined reference tofftwf_destroy_plan'
cqt.o: In function create_cqt': /home/userKum/spectrum-master/cqt.c:65: undefined reference to__logf_finite'
/home/userKum/spectrum-master/cqt.c:65: undefined reference to __expf_finite' /home/userKum/spectrum-master/cqt.c:66: undefined reference to__log2_finite'
/home/userKum/spectrum-master/cqt.c:87: undefined reference to fftwf_plan_dft_1d' /home/userKum/spectrum-master/cqt.c:98: undefined reference tocexpf'
/home/userKum/spectrum-master/cqt.c:103: undefined reference to fftwf_execute' /home/userKum/spectrum-master/cqt.c:57: undefined reference tocabsf'
/home/userKum/spectrum-master/cqt.c:57: undefined reference to cabsf' /home/userKum/spectrum-master/cqt.c:115: undefined reference tocabsf'
/home/userKum/spectrum-master/cqt.c:117: undefined reference to cabsf' /home/userKum/spectrum-master/cqt.c:117: undefined reference tocabsf'
/home/userKum/spectrum-master/cqt.c:57: undefined reference to __powf_finite' /home/userKum/spectrum-master/cqt.c:139: undefined reference tofftwf_destroy_plan'
/home/userKum/spectrum-master/cqt.c:146: undefined reference to fftwf_plan_dft_r2c_1d' cqt.o: In functionslide_cqt':
/home/userKum/spectrum-master/cqt.c:30: undefined reference to `fftwf_execute'
collect2: ld returned 1 exit status
make: *** [spectrum] Error 1
I have no idea what these undefined reference is all about...... It looks it is missing a linkage to '-lasound' during compilation. What should I do so that I can solve this issue?
As requested by some of the viewer, the MakeFile is as follows:
CFLAGS = -g -D_GNU_SOURCE=1 -W -Wall -O3 -std=c99 -fno-math-errno -ffinite-math-only -fno-rounding-math -fno-signaling-nans -fno-trapping-math -fcx-limited-range -fsingle-precision-constant $(shell sdl-config --cflags) $(shell pkg-config fftw3f --cflags)
LDFLAGS = -lm -lasound $(shell sdl-config --libs) $(shell pkg-config fftw3f --libs)
all: spectrum
clean:
rm -f spectrum *.o
spectrum: spectrum.o mmap_file.o pcm.o wav.o alsa.o window.o stft.o cqt.o trans.o
Another classic case of "libraries need to come after the objects":
Your libraries, defined by
LDFLAGS = -lm -lasound $(shell sdl-config --libs) $(shell pkg-config fftw3f --libs)
Given that (according to here) the rule for linking is:
$(CC) $(LDFLAGS) n.o $(LOADLIBES) $(LDLIBS)
I would expect that
LDLIBS = -lm -lasound $(shell sdl-config --libs) $(shell pkg-config fftw3f --libs)
would do the trick, although I prefer to actually write my own linker line, as inevitably I end up wanting to know exactly what is linked...
(Unix linkers are rather simplistic in their dealing with libraries, so if you list -lsomething x.o to the linker, the linker will not take anything from -lsomething, and complaim that somethingFunc1(which can be found in libsomething.a) is missing because it wasn't found AFTER x.o.