歡迎您光臨本站 登入註冊首頁

概述

一參照手冊例子建立helloword.cpp------------------------------#include<qapplication.h>#include<qpushb……

一 參照手冊例子建立helloword.cpp
------------------------------
#include<qapplication.h>
#include<qpushbutton.h>

int main(int argc,char **argv)
{
        QApplication a(argc,argv);
        QPushButton hello("Hello world!",0);
        hello.resize(100,30);

        a.setMainWidget(&hello);
        hello.show();
        int result=a.exec();
        return result;
}
--------------------------
二 設置環境變數:(這裡我直接使用在安裝Qt時使用的set-env配置,埋下了隱患)
export QTDIR=$PWD/qt
export QPEDIR=$PWD/qtopia
export TMAKEDIR=$PWD/tmake
export TMAKEPATH=$TMAKEDIR/lib/qws/linux-generic-g++
export PATH=$QTDIR/bin:$QPEDIR/bin:$TMAKEDIR/bin:$PATH
建立tmake工程文件:
#progen -n helloword -o helloword.pro
產生makefile文件:
#tmake helloword.pro -o makefile
#make
g++ -c -pipe -DQWS -fno-exceptions -fno-rtti -Wall -W -O2 -DNO_DEBUG -I/home/chinazjn/armsys2410/qt_x86/qt/include -o helloword.o helloword.cpp
gcc  -o helloword helloword.o   -L/home/chinazjn/armsys2410/qt_x86/qt/lib -lqte
/home/chinazjn/armsys2410/qt_x86/qt/lib/libqte.so:對‘cos’未定義的引用
/home/chinazjn/armsys2410/qt_x86/qt/lib/libqte.so:對‘sin’未定義的引用
/home/chinazjn/armsys2410/qt_x86/qt/lib/libqte.so:對‘pow’未定義的引用
collect2: ld returned 1 exit status
make: *** [helloword] 錯誤 1
----------------------------------------------------------------
#vi makefile
..........................
CXXFLAGS=       -pipe -DQWS -fno-exceptions -fno-rtti -Wall -W -O2 -DNO_DEBUG
INCPATH =       -I$(QTDIR)/include
LINK    =       gcc     //此處修改為g++
............................
#make   編譯成功!

三  運行測試
#qvfb&
#./helloword -qws
./helloword: error while loading shared libraries: libqte.so.2: cannot open shared object file: No such file or directory

環境變數設置有問題,重新設置:
------------------
pathmunge () {
        if ! echo $PATH | /bin/egrep -q "(^|:)$1($|:)" ; then
           if [ "$2" = "after" ] ; then
             _PATH=$PATH:$1
           else
              PATH=$1:$PATH
           fi
        fi
}

export QTDIR=$PWD/qt
export QPEDIR=$PWD/qtopia
export TMAKEDIR=$PWD/tmake
export TMAKEPATH=$TMAKEDIR/lib/qws/linux-generic-g++

unset LD_LIBRARY_PATH
export LD_LIBRARY_PATH=$QTDIR/lib/:$QPEDIR/lib/

pathmunge  $QTDIR/bin
pathmunge  $QPEDIR/bin
pathmunge  $TMAKEDIR/bin
-------------
之後可以正常運行了。初學linux,環境變數感覺挺麻煩的,都是windows把我們給害的,抽空要學習一下。


[admin via 研發互助社區 ] QT/Qtopia環境變數設置與編譯運行問題已經有2896次圍觀

http://cocdig.com/docs/show-post-42225.html