QT/Qtopia环境变量设置与编译运行问题
2012-12-14
chinazjn
标签: QT

一 参照手册例子建立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 "(^|:) ($|:)" ; then

if [ "$2" = "after" ] ; then

_PATH=$PATH:

else

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

可能会用到的工具/仪表
本站简介 | 意见建议 | 免责声明 | 版权声明 | 联系我们
CopyRight@2024-2039 嵌入式资源网
蜀ICP备2021025729号