用了一天多时间,终于一步步建立起了qtopia的交叉编译环境,过程之繁琐,以前还没有遇见过。
平台:ubuntu 10.10 arm-linux-gcc-4.3.2
参考资料:《嵌入式linux应用开发完全手册》 韦东山
下面开始arm版本Qtopia2.2.0版本的编译
如果您还没有安装arm-linux-gcc-4.4.1 交叉编译器,请先安装该交叉编译器到/usr/local/arm 下面,把arm-linux-gcc-4.4.1压缩包解压到该目录即可完成安装。
需要注意的是:
1 编译Qtopia时确保您的Ubantu9.10环境中安装了GNU g++编译器,Qtopia编译过程中用这个编译器用来编译一些工具在PC上运行.
2 注意您的Ubantu中要安装X11的SDK库,Qtopia编译过程中需要使用X11SDK里面的一些头文件,使用以下命令即可安装需要的文件
#apt-get install libx11-dev libxext-dev libxtst-dev
另外需要安装工具uuid(Universally Unique Identifier,)和 xmu库文件, 编译Qtopia2.2.0时需要这些在PC上运行的工具和第三方库文件
apt-get install uuid-dev
apt-get install libxmu-dev libxmu6
如果不安装 uuid和xmu将会出现下面的错误:
没有安装xmu时,编译提示:
/usr/bin/ld:cannot find -lXmu
没有安装uuid时,编译提示:
Creating pngscale...make[1]: Entering directory `/root/yizhi/qtopia-free-2.2.0/qtopia/util/pngscale'
..make[1]: *** [../../bin/pngscale] Error 1
make[1]: Leaving directory `/root/yizhi/qtopia-free-2.2.0/qtopia/util/pngscale'
Failed to make pngscale
3 编译时 虚拟机中的ARM-qtopia-free-src-2.2.0.tar.gz 文件不能放在与Windows共享的目录中,否则会编译出错.
说明:以下的错误信息是按照
先后顺序 发现和处理的,用户可以根据自己的错误类型信息,自己进行修改.
这些错误是自己经历并解决的,也参考了其他网友的一些办法,总结一下,与大家分享
1 编译错误:open函数参数不够
/usr/include/bits/fcntl2.h:51: error: call to ‘__open_missing_mode’ declared with attribute error: open with O_CREAT in second argument needs 3 arguments
解决办法:
在Ubuntu 9.10上, gcc会严格检查open()的参数传递,如果第二个参数为O_CREAT的话(就像qtopia-2.2.0- Friendly
ARM/qt2/src /tools/qmemoryfile_unix.cpp的143行这样),必须传入第三个参数mode。因此,手动修改x86-qtopia- 2.2.0/qt2/src/tools/qmemoryfile_unix.cpp 143行将
if (!f)
f = open(tmpFile.latin1(), O_CREAT | O_WRONLY);
修改为
if (!f)
f = open(tmpFile.latin1(), O_CREAT | O_WRONLY, 0666);
2 使用未定义的类
error: ‘QWSInputMethod’ has not been declared
修正方法:
cd $QTDIR/src/kernel
gedit qwindowsystem_qws.h
在前面增加以下两行
class QWSInputMethod;
class QWSGestureMethod;
该文件中使用了这两个类,C++允许在文件中这样声明其他地方定义的类,减少头文件的相互包含关系,加快编译速度
3 缺少头文件
错误信息:
kernel/qpixmapcache.cpp:125:57: error: asm/page.h: No such file or directory
kernel/qpixmapcache.cpp: In constructor ‘QSharedMemoryManager::QSharedMemoryManager()’:
kernel/qpixmapcache.cpp:539: error: ‘PAGE_SIZE’ was not declared in this scope
kernel/qpixmapcache.cpp:539: error: ‘PAGE_MASK’ was not declared in this scope
kernel/qpixmapcache.cpp: In member function ‘void QSharedMemoryManager::internal_free(QSMemPtr)’:
kernel/qpixmapcache.cpp:773: error: ‘PAGE_SIZE’ was not declared in this scope
kernel/qpixmapcache.cpp:773: error: ‘PAGE_MASK’ was not declared in this scope
make[1]: *** [tmp/release-shared-linux-generic-g++-no-keypad/kernel/qpixmapcache.o] Error 1
make[1]: Leaving directory `/root/yizhi/host/qtopFolder[
解决办法:2.6内核中不再含有asm-i386的page.h 修改qt2/src/kernel/qpixmapcache.cpp 文件
#ifdef THROW_AWAY_UNUSED_PAGES
# include
// madvise
#define PAGE_SHIFT 12 //new add 2010-12-10
#define PAGE_SIZE (1UL << PAGE_SHIFT) //new add 2010-12-10
#define PAGE_MASK (~(PAGE_SIZE-1)) //new add 2010-12-10
//# include // PAGE_SIZE,PAGE_MASK,PAGE_ALIGN //注释掉,不需要此行 2010-12-10
还有其他地方也用到了该头文件,同样需要去掉。
转至 ./qtopia-free-2.2.0/qt2/tools/qvfb/qvfbview.cpp
第39行,#include 这行注释掉就行了。
4 类型转换错误
/home/work/armqt/qtlibsource/qt-x11/include/qvalue stack.h: In member function 'T QValueStack::pop() [with T = QMap]':
xml/qxml.cpp:513: instantiated from here
/home/work/armqt/qtlibsource/qt-x11/include/qvalue stack.h:57: 错误:不能从'QValueListIterator >'转换到'const char*',为实参'1'(属于'int remove(const char*)')
/home/work/armqt/qtlibsource/qt-x11/include/qvalue stack.h: In member function 'T QValueStack::pop() [with T = QString]':
xml/qxml.cpp:2502: instantiated from here
/home/work/armqt/qtlibsource/qt-x11/include/qvalue stack.h:57: 错误:不能从'QValueListIterator'转换到'const char*',为实参'1'(属于'int remove(const char*)') 解决办法:vi include/qvaluestack.h
解决办法:
template
class Q_EXPORT QValueStack : public QValueList
{
public:
QValueStack() {}
~QValueStack() {}
void push( const T& d ) { append(d); }
T pop()
{
T elem( this->last() );
if ( !this->isEmpty() )
this->remove( this->fromLast() );// add "this->" 2010-12-10
return elem;
}
5 没有找到uic工具 错误提示:
make[5]: /root/yizhi/host/qtopia-free-2.2.0/qt2/bin/uic: Command not found
make[5]: *** [../../../include/qtopia/private/passwordbase_p.h] Error 127
解决办法:
cd到你的qtopia-free-2.2.0目录下, find ./ -name uic 会看到其他的目录下已经有了uic,我把qt3/bin
目录下的uic拷贝到 qt2/bin下面,即可
6 多余的符号错误,即类的成员函数在头文件中不需要加类名
qdawg.cpp:294: error: extra qualification ‘QDawgPrivate::’ on member ‘QDawgPrivate’
make[5]: *** [.obj/release-shared/qdawg.o]o o
解决办法:
qtopia-free-2.2.0/qtopia/src/libraries/qtopia/qdawg.cpp 里面的
QDawgPrivate::~QDawgPrivate()
{
delete memoryFile;
}
修改为:
~QDawgPrivate() // delete "QDawgPrivate::~" 2010-12-10
{
delete memoryFile;
}
7
指针类型转换出错:
backend/vobject.cpp: In function ‘VObject* addGroup(VObject*, const char*)’:
backend/vobject.cpp:419: error: invalid conversion from ‘const char*’ to ‘char*’
backend/vobject.cpp: In function ‘void writeEncString(OFi
解决办法:
修改 qtopia-free-2.2.0/qtopia/src/libraries/qtopia/backend/vobject.cpp 文件149行
char *dot = strrchr(g,'.'); 修改为 char *dot = (char *)strrchr(g,'.');
8
错误:编译器找不到QSizePolicy类的五个参数的构造函数
ui/release-shared/passwordbase_p.cpp:35: error: no matching function for call to ‘QSizePolicy::QSizePolicy(QSizePolicy::SizeType, QSizePolicy::SizeType, int, int, bool)’
/root/yizhi/host/qtopia-free-2.2.0/qt2/include/qsizepolicy.h:93: note: candidates are: QSizePolicy::QSizePolicy(int)
/root/yizhi/host/qtopia-free-2.2.0/qt2/include/qsizepolicy.h:99: note: QSizePolicy::QSizePolicy(QSizePolicy::SizeType, QSizePolicy::SizeType, bool)
/root/yizhi/host/qtopia-free-2.2.0/qt2/include/qsizepolicy.h:63: note: QSizePolicy::QSizePolicy()
/root/yizhi/host/qtopia-free-2.2.0/qt2/include/qsizepolicy.h:46: note: QSizePolicy::QSizePolicy(const QSizePolicy & )
解决办法:
qtopia-free-2.2.0/qtopia/src/libraries/qtopia/.ui/release-shared/passwordbase_p.cpp 文件中的38行位置
prompt = new QLabel( this, "prompt" );
prompt->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)7, (QSizePolicy::SizeType)1, 0, 0, prompt->sizePolicy().hasHeightForWidth() ) );
修改为:
prompt = new QLabel( this, "prompt" );
prompt->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)7, (QSizePolicy::SizeType)1, prompt->sizePolicy ().hasHeightForWidth() ) );
即去掉0,0 两个参数
9 g++编译器提示 有多余的符号在成员函数前 ,有些编译器规定C++成员函数前不需要再加这个类的名字,与第6处错误雷同
thumbnailview_p.h: At global scope:
thumbnailview_p.h:81: error: extra qualification ‘ThumbnailItem::’ on member ‘paintItem’
make[5]: *** [.obj/release-shared/imageselector.o] Eopia/src
解决办法 :
qtopia-free-2.2.0/qtopia/src/libraries/qtopia2/thumbnailview_p.h文件中第81行:
修改 void ThumbnailItem::paintItem( QPainter*, const QColorGroup& );
修改后 void paintItem( QPainter*, const QColorGroup& );
继续编译后会出现类似的错误
abtable_p.h:276: error: extra qualification ‘PhoneTypeSelector::’ on member ‘addType’
make[5]: *** [.obj/release-shared/abtable.o] Error 1
make[5]: Leaving directory `/root/yizhi/host/qtopia-free-2.2.0/qtopia/src/libraries/qtopiapim'
make[4]: *** [all] Error 2
解决办法:
修改 qtopia-free-2.2.0/qtopia/src/libraries/qtopiapim/abtable_p.h 文件中276行
QListViewItem* PhoneTypeSelector::addType(QListViewItem* prevItem,
QString number, const char* pixmapName, PimContact::ContactFields phoneType);
修改为:
QListViewItem* addType(QListViewItem* prevItem,QString number, const char* pixmapName, PimContact::ContactFields phoneType);
也就是去掉 PhoneTypeSelector::
继续编译:
../../../include/qtopia/pim/private/../../../../src/libraries/qtopiapim/numberentry_p.h: At global scope:
../../../include/qtopia/pim/private/../../../../src/libraries/qtopiapim/numberentry_p.h:106: error: extra qualification ‘NumberEntryDialog::’ on member ‘eventFilter’
make[5]: *** [.obj/release-shared/numberentry.o] Error 1
make[5]: Leaving directory `/root/yizhi/host/qtopia-free-2.2.0/qtopia/src/libraries/qtopiapim'
make[4]: *** [all] Error 2
解决办法:
修改 qtopia-free-2.2.0/qtopia/src/libraries/qtopiapim/numberentry_p.h 第106行
bool NumberEntryDialog::eventFilter(QObject *o, QEvent *e);
修改为 bool eventFilter(QObject *o, QEvent *e);
继续:
make[5]: Leaving directory `/root/yizhi/host/qtopia-free-2.2.0/qtopia/src/libraries/mediaplayer'
make[4]: *** [all] Error 2
make[4]: Leaving directory `/root/yizhi/host/qtopia-free-2.2.0/qtopia/src/libraries/mediaplayer'
修改 qtopia-free-2.2.0/qtopia/src/libraries/mediaplayer/videoviewer.cpp 文件 52行
SimpleVideoWidget::SimpleVideoWidget(QWidget *parent);
修改后:
SimpleVideoWidget(QWidget *parent); //构造函数
继续编译
In file included from addressbook.cpp:40:
ablabel.h: At global scope:
ablabel.h:78: error: extra qualification ‘AbLabel::’ on member ‘decodeHref"
解决办法:
修改 qtopia-free-2.2.0/qtopia/src/applications/addressbook/ablabel.h 78行
bool AbLabel::decodeHref(const QString& href, ServiceRequest* req, QString* pm) const;
修改为 bool decodeHref(const QString& href, ServiceRequest* req, QString* pm) const;
10 又一处未经定义的构造函数错误提示:
.ui/release-shared/emaildlg.cpp: In constructor ‘EmailDialogBase::EmailDialogBase(QWidget*, const char*, bool, uint)’:
.ui/release-shared/emaildlg.cpp:65: error: no matching function for call to ‘QSizePolicy::QSizePolicy(QSizePolicy::SizeType, QSizePolicy::SizeType, int, int, bool)’
/root/yizhi/host/qtopia-free-2.2.0/qt2/include/qsizepolicy.h:93: note: candidates are: QSizePolicy::QSizePolizePolicj 4
修改 qtopia-free-2.2.0/qtopia/src/applications/addressbook/.ui/release-shared/emaildlg.cpp 文件第65行
okButton = new QPushButton( this, "okButton" );
okButton->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, 0, 0, okButton->sizePolicy().hasHeightForWidth() ) );
Layout2->addWidget( okButton );
cancelButton = new QPushButton( this, "cancelButton" );
cancelButton->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0, 0, 0, cancelButton->sizePolicy().hasHeightForWidth() ) );
Layout2->addWidget( cancelButton );
修改为
okButton = new QPushButton( this, "okButton" );
okButton->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0,okButton->sizePolicy().hasHeightForWidth() ) );
Layout2->addWidget( okButton );
cancelButton = new QPushButton( this, "cancelButton" );
cancelButton->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)3, (QSizePolicy::SizeType)0,cancelButton->sizePolicy().hasHeightForWidth() ) );
Layout2->addWidget( cancelButton );
继续编译:
错误提示:.ui/release-shared/camerabase.cpp:41: error: no matching function for call to ‘QSizePolicy::QSizePolicy(QSizePolicy::SizeType, QSizePolicy::SizeType, int, int, bool)’
/root/yizhi/host/qtopia-free-2.2.0/qt2/include/qsizepolicy.h:93: note: candidates are: QSizePolicy::QSizePolicy(int)
解决办法:
编辑 qtopia-free-2.2.0/qtopia/src/applications/camera/.ui/release-shared/camerabase.cpp 文件的第41行
videocaptureview->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)7, (QSizePolicy::SizeType)7, 0, 0, videocaptureview->sizePolicy().hasHeightForWidth() ) );
修改为:
videocaptureview->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)7, (QSizePolicy::SizeType)7, videocaptureview->sizePolicy().hasHeightForWidth() ) );
继续编译。同样是这个类型的错误,这里就不再列出了,用户可以仿照上面的方法,根据错误提示信息,自己进行修改,修改后保存,继续编译。
这里的情况是每次只能修改一个文件,改完后编译,才能进行下一个文件。所以,很费时间,不知道有没有好的方法?
11
/usr/local/arm/4.1.2/bin/../lib/gcc/arm-angstrom-linux-gnueabi/4.1.2/../../../../arm-angstrom-linux-gnueabi/bin/ld: warning: libts-0.0.so.0, needed by /home/stillwater/4.1.2/qt-everywhere-opensource-src-4.6.0/lib/libQtGui.so, not found (try using -rpath
or -rpath-link)
/home/stillwater/4.1.2/qt-everywhere-opensource-src-4.6.0/lib/libQtGui.so: undefined reference to `ts_read_raw'
/home/stillwater/4.1.2/qt-everywhere-opensource-src-4.6.0/lib/libQtGui.so: undefined reference to `ts_open'
/home/stillwater/4.1.2/qt-everywhere-opensource-src-4.6.0/lib/libQtGui.so: undefined reference to `ts_fd'
/home/stillwater/4.1.2/qt-everywhere-opensource-src-4.6.0/lib/libQtGui.so: undefined reference to `ts_config'
/home/stillwater/4.1.2/qt-everywhere-opensource-src-4.6.0/lib/libQtGui.so: undefined reference to `ts_close'
/home/stillwater/4.1.2/qt-everywhere-opensource-src-4.6.0/lib/libQtGui.so: undefined reference to `ts_read'
collect2: ld returned 1 exit status
make[2]: *** [deform] Error 1
make[2]: Leaving directory `/home/stillwater/4.1.2/qt-everywhere-opensource-src-4.6.0/demos/deform'
make[1]: *** [sub-deform-make_default] Error 2
make[1]: Leaving directory `/home/stillwater/4.1.2/qt-everywhere-opensource-src-4.6.0/demos'
make: *** [sub-demos-make_default-ordered] Error 2
解决办法:
修改qt-everywhere-opensource-src-4.6.0/mkspecs/qws/linux-arm-g++/qmake.conf 文件(添加lts参数):
QMAKE_CC = arm-linux-gcc -lts
QMAKE_CXX = arm-linux-g++ -lts
QMAKE_LINK = arm-linux-g++ -lts
QMAKE_LINK_SHLIB = arm-linux-g++ -lts