我正在Windows 7 64bit上的VirtualBox上的Ubuntu 14.4 64位上运行Qt Creator 3.0.1(基于Qt 5.2.1(GCC 4.8.2,64位)) 我正在尝试交叉编译到Raspberry Pi并运行非常简单的程序:
MainWindow.h:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
protected slots:
void ButtonClicked();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
LinuxProject4.cpp:
#include "MainWindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
MainWindow.cpp:
#include "MainWindow.h"
#include "ui_MainWindow.h"
#include <QMessageBox>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::ButtonClicked()
{
QMessageBox msgBox;
msgBox.setText("Hello, World!");
msgBox.setWindowTitle("VisualGDB Qt Demo");
msgBox.exec();
}
MainWindow.ui:
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>LinuxProject4</string>
</property>
<widget class="QWidget" name="centralWidget">
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>160</x>
<y>120</y>
<width>75</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>Press me</string>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>25</height>
</rect>
</property>
</widget>
<widget class="QToolBar" name="mainToolBar">
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
</widget>
<widget class="QStatusBar" name="statusBar"/>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections>
<connection>
<sender>pushButton</sender>
<signal>clicked()</signal>
<receiver>MainWindow</receiver>
<slot>ButtonClicked()</slot>
<hints>
<hint type="sourcelabel">
<x>199</x>
<y>89</y>
</hint>
<hint type="destinationlabel">
<x>279</x>
<y>230</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>ButtonClicked()</slot>
</slots>
</ui>
OrianFirstTest.pro:
#-------------------------------------------------
Project created by QtCreator 2015-04-20T19:02:59
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = OrianFirstTest
target.files = OrianFirstTest
target.path = /home/pi
INSTALLS = target
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES +=
MainWindow.cpp
LinuxProject4.cpp
FORMS +=
MainWindow.ui
HEADERS +=
MainWindow.h
运行qmake很好并且也可以构建它。 当我尝试运行它时,我会在一瞬间看到GUI,我在PC上收到此消息:
/ home / pi / OrianFirstTest:符号查找错误:/ home / pi / OrianFirstTest:未定义符号:_ZN7QWidget8qwsEventEP8QWSEvent 应用程序以退出代码127完成。
在Raspberry Pi上运行:“ldd OrianFirstTest”返回:“不是动态可执行文件”。
在Raspberry Pi上运行:“echo _ZN7QWidget8qwsEventEP8QWSEvent | c ++ filt”返回:“QWidget :: qwsEvent(QWSEvent *)”。
在Raspberry Pi上运行:“readelf -d OrianFirstTest”返回:
偏移量0x400c处的动态部分包含32个条目:
标签类型名称/值
0x000000 01(NEEDED)共享库:[libQtGui.so.4]
0x00000001(NEEDED)共享库:[libQtNetwork.so.4]
0x00000001(NEEDED)共享库:[libQtCore.so.4]
0x00000001(NEEDED)共享库:[libpthread.so.0]
0x00000001(NEEDED)共享库:[libstdc ++。so.6]
0x00000001(NEEDED)共享库:[libm.so.6]
0x00000001(NEEDED)共享库:[libgcc_s.so.1]
0x00000001(NEEDED)共享库:[libc.so.6]
0x0000000f(RPATH)库rpath:[/ opt / qt / lib]
0x0000000c(INIT)0x9f64
0x0000000d(FINI)0xb74c
0x00000019(INIT_ARRAY)0x14000
0x0000001b(INIT_ARRAYSZ)4(字节)
0x0000001a(FINI_ARRAY)0x14004
0x0000001c(FINI_ARRAYSZ)4(字节)
0x00000004(HASH)0x8168
0x00000005(STRTAB)0x8c04
0x00000006(SYMTAB)0x84c4
0x0000000a(STRSZ)3806(字节)
0x0000000b(SYMENT)16(字节)
0x00000015(DEBUG)0x0
0x00000003(PLTGOT)0x14134
0x00000002(PLTRELSZ)776(字节)
0x00000014(PLTREL)REL
0x00000017(JMPREL)0x9c5c
0x00000011(REL)0x9c3c
0x00000012(RELSZ)32(字节)
0x00000013(RELENT)8(字节)
0x6ffffffe(已发布)0x9bcc
0x6fffffff(VERNEEDNUM)3
0x6ffffff0(VERSYM)0x9ae2
0x00000000(NULL)0x0
请帮助我并指导我解决它。 非常感谢, Orian。