用scons构建cppcheck的GUI程序

关于linux上下载cppcheck及配置Qt环境等信息,可

参见我的上一篇文章 《64位centos上用Qt编译生成c/c++代码检查工具cppchek的GUI》

假定cppcheck下载后,存放在本地的路径为:/usr/tools/cppcheck-1.44

 

scons构建脚本文件目录结构如图所示

cppcheck-1.44  sconstruct文件

|

|---cli    sconscript文件

|

|---gui  sconscript文件

|

|---test sconscript文件

|

|---....

 

1、sconstruct文件,内容如下:

#!/usr/bin/python
import os
bin = '#bin'
myhome = os.getcwd()
env = Environment(
                  tools=['default','qt'],
                  ENV = os.environ,
                  CXXFLAGS = '-O2 -DNDEBUG -Wall -Ilib',
                  BINDIR = bin,
                  LIBS=[],
                  #QTDIR='/opt/qtsdk/qt'                 
                                               )
                                              
Export('env','myhome')

subdir = ['./test','./cli','./gui']
for i in subdir:
 env.SConscript('%s/sconscript' %(i) )

 

2、cli/sconscript文件,内容如下:

#!/usr/bin/python
import os
Import('env','myhome')

lib_files = Glob('%s/lib/*.cpp' %(myhome))
cli_files = Glob('%s/cli/*.cpp' %(myhome))


bin_cppcheck = env.Program(target='cppcheck',         
                           source=[cli_files,lib_files],
                           CPPPATH= '%s/lib' %(myhome)  )                
                                                                      
cppcheck_install = env.Install('$BINDIR', bin_cppcheck)
env.Default(cppcheck_install);

 

3、gui/sconscript文件,内容如下:

#!/usr/bin/python
import os
import glob
Import('env','myhome')

def recursiveDirs(root) :
 return filter( (lambda a : a.rfind( "SVN")==-1 ),  [ a[0] for a in os.walk(root)]  )

def unique(list) :
 return dict.fromkeys(list).keys()

def scanFiles(dir, accept=["*.cpp"], reject=[]) :
 sources = []
 paths = recursiveDirs(dir)
 for path in paths :
  for pattern in accept :
   sources+=glob.glob(path+"/"+pattern)
 for pattern in reject :
  sources = filter( (lambda a : a.rfind(pattern)==-1 ),  sources )
 return unique(sources)


lib_files = Glob('%s/lib/*.cpp' %(myhome))
temp_files = Glob('temp/*.cpp')
gui_files = Glob('*.cpp')
cpp_path = ['/opt/qtsdk/qt/mkspecs/linux-g++-64',
     '/opt/qtsdk/qt/include',
           '/opt/qtsdk/qt/include/QtCore',
           '/opt/qtsdk/qt/include/QtGui',
           '/opt/qtsdk/qt/include/QtXml',          
           '%s/gui/temp' %(myhome),'%s/gui' %(myhome)
                              ]
lib_path = ['/opt/qtsdk/qt/lib','/usr/lib','/usr/X11R6/lib64']

ui_dir=['resultsview','application','main','settings','file','about']
for ui in ui_dir:
 env.Execute("/opt/qtsdk/qt/bin/uic -o %s/gui/temp/ui_%s.h %s/gui/%s.ui" %(myhome,ui,myhome,ui))
 #  env.Uic(target="%s/gui/temp/ui_%s" %(myhome,ui),source=ui) 注:执行Uic接口有点问题

 

#for qrc in scanFiles('/usr/tools/cppcheck-1.44/gui', ['*.qrc']):
   #print "hua:"+qrc
   #env.Qrc(qrc, QT4_QRCFLAGS='-name '+'gui gui.qrc')

env.Execute('/opt/qtsdk/qt/bin/rcc -name gui gui.qrc -o temp/qrc_gui.cpp')

bin_gui = env.Program(target='gui',    
                   source=[lib_files,gui_files,temp_files],                     
                      CPPPATH = cpp_path,                                            
                      LIBPATH = lib_path,
                    LIBS=['QtGui','QtCore','QtXml','pthread']
                                              )  
gui_install = env.Install('$BINDIR', bin_gui)
env.Default(gui_install);

 

4、test/sconscript文件,内容如下:

#!/usr/bin/python
import os
Import('env','myhome')

lib_files = Glob('%s/lib/*.cpp' %(myhome))
cli_files = '%s/cli/threadexecutor.cpp' %(myhome)
test_files = Glob('*.cpp')+Glob('tinyxml/*.cpp')

bin_testrunner = env.Program(target='testrunner',         
                             source=[test_files,lib_files,cli_files],                
                             CPPPATH = ['%s/cli' %(myhome)])
test_install = env.Install('$BINDIR', bin_testrunner)
env.Default(test_install);

 

5、执行构建脚本

$cd /usr/tools/cppcheck-1.44

$scons即可

 

6、解决gui可执行程序运行不成功

在编译成功gui,生成可执行文件后,运行该可执行文件,系统提示错误信息:“error while loading shared libraries: libQtGui.so.4: cannot open shared object file: No such file or directory”

解决办法:

(1)查找libQtGui.so.4所在目录

$find /opt/qtsdk |grep  libQtGui.so.4

/opt/qtsdk/qt/lib/libQtGui.so.4
/opt/qtsdk/qt/lib/libQtGui.so.4.6.3
/opt/qtsdk/qt/lib/libQtGui.so.4.6
/opt/qtsdk/lib/libQtGui.so.4
/opt/qtsdk/lib/libQtGui.so.4.7.0

 

(2)ld文件配置

$vi /etc/ld.so.conf

include id.so.conf.d/*.conf //里面只有一行,表示到id.so.conf.d目录中寻找配置信息

$cd /etc/ld.so.conf.d //转到Id.so.conf.d目录下

在该目录下会看到qt-i386.conf

修改Id路径

$vi qt-i386.conf //编辑qt-i386.conf文件

#/usr/lib/qt-3.3/lib   //屏蔽默认指向qt-3.3的语句
/opt/qtsdk/qt/lib      //增加指向qt4.6.3所在的目录

 

(3)设置完ld路径后,需要运行ldconfig命令,更新缓存

做完上述后,即可运行成功gui程序

 

 

你可能感兴趣的:(UI,linux,python,OS,qt)