Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1016301
  • 博文数量: 244
  • 博客积分: 6820
  • 博客等级: 准将
  • 技术积分: 3020
  • 用 户 组: 普通用户
  • 注册时间: 2008-09-09 21:33
文章分类

全部博文(244)

文章存档

2013年(1)

2012年(16)

2011年(132)

2010年(3)

2009年(12)

2008年(80)

我的朋友

分类: LINUX

2008-09-12 18:10:50

QT/Qtopia环境变量设置与编译运行问题

一 参照手册例子建立helloword.cpp
------------------------------
#include
#include

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把我们给害的,抽空要学习一下

阅读(1990) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~