简体   繁体   English

在Raspberry上编译Qt5 App

[英]Compiling Qt5 App on Raspberry

I'd like to compile a program on my Raspberry Pi 3 . 我想在我的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. 我已经按照本手册中的说明安装了最新的Raspbian和交叉编译的Qt 5.8 ,然后尝试构建GST在板上运行。 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 : 据我了解,没有引用QApplication ,但是我在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. 我还尝试了qmake -project以获取项目文件,然后进行qmake和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? 您是否尝试通过将Qt安装的/ lib文件夹添加到ld.so.conf来让Pi找到库? In your case this would maybe look like echo /opt/Qt5.8/lib | sudo tee /etc/ld.so.conf.d/qt5pi.conf 在您的情况下,这可能看起来像echo /opt/Qt5.8/lib | sudo tee /etc/ld.so.conf.d/qt5pi.conf 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 之后,您必须使用sudo ldconfig重新加载ld.so.conf。

Now the linker can find the Qt-Libs without any additions to your Makefile. 现在,链接器可以找到Qt-Lib,而无需在Makefile中添加任何内容。 Maybe this will help you. 也许这会对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM