【转】VC2015下安装Geant4

转自:http://blog.sina.com.cn/s/blog_5de5580a0102w7qg.html#commonComment

平台:

    windows10,VC2015社区版。

安装软件:

    CMake3.3.2,Geant4.10.2.b01,Qt5.5.0,

设置环境变量:

用户:

G4SYSTEM=WIN32-VC

G4INSTALL=D:\Geant4\install

G4INCLUDE=D:\Geant4\install\include\Geant4

G4LIB=D:\Geant4\install\lib

PATH=D:\Geant4\install\bin;%PATH%

QTDIR=D:\Qt\5.5.0

QT_PLUGIN_PATH=D:\Qt\5.5.0\plugins

LD_LIBRARY_PATH=D:\Qt\5.5.0\lib

系统:

Path=D:\Qt\5.5.0\bin;%Path%

 

(Qt5.6版提供编译版本,建议直接下载安装)

一、下载Qt5.5.0并安装

(5.5.1版已经发布,依然没有VC2015编译版)。

从源码编译:

1. 从http://www.activestate.com/activeperl/downloads 下载并安装ActivePerl,从http://www.activestate.com/activeperl/downloads 。

2. 下载并安装python2.7

3. 其它参考:http://doc.qt.io/qt-5/windows-requirements.html

  Install Ruby from here and add the installation location to your PATH in order to be able to build Qt WebKit.

4. 批处理命令:

call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat"

set QT5_DIR=D:\Qt\qt-5

set PATH=%PATH%;%QT5_DIR%\bin;%QT5_DIR%\qtbase\bin;%QT5_DIR%\gnuwin32\bin

set QT_INSTALL=D:\Qt\5.5.0

cd %QT5_DIR%

configure -prefix %QT_INSTALL% -mp -opensource -confirm-license -developer-build -platform win32-msvc2015  -c++11 -opengl desktop -nomake examples  -nomake tests 

nmake

nmake install 

nmake clean

这里源码目录在qt-5,安装目录是5.5.0,命令在Qt下。

编译选项:

     -release ........... Compile and link Qt with debugging turned off.  

 *  -debug ............. Compile and link Qt with debugging turned on.  

 + -debug-and-release . Compile and link two Qt libraries, with and without   

                         debugging turned on.   

     -force-debug-info .. Create symbol files for release builds.  

     -developer-build ... Compile and link Qt with Qt developer options   

                         (including auto-tests exporting)  

-opengl 为了Geant4使用Qt可视化驱动。

不用webkit,相应的文件夹可从源码目录下删除。  

执行批处理编译。namke如不执行,键入即可。

 

二、下载CMake并安装。

三、下载Geant4及Data文件

四、 CMake构建VC2015解决方案。

CMake选项:

-MP 多处理编译加到CMAKE_CXX_FLAG

CMAKE_INSTALL_PREFIX设置为环境变量G4INSTALL的值:D:\Geant4\install

GEANT4选项:

勾选:TRAJCTORY;VERBOSE;OPENGL;QT5

DATADIR设置为解压的数据文件所在目录。

其它:都没选。

windows平台不选MULTITHREAD:Multithreading of Geant4 is currently not supported on the Windows platform.

配置构建。

 

五、VC2015编译生成解决方案

 

1.编译错误及修改:

1>------ 已启动生成: 项目: G4geomUSolids-static, 配置: Release Win32 ------

2>------ 已启动生成: 项目: G4expat-static, 配置: Release Win32 ------

3>------ 已跳过生成: 项目: uninstall, 配置: Release Win32 ------

3>没有为此解决方案配置选中要生成的项目 

4>------ 已跳过生成: 项目: validate_sources, 配置: Release Win32 ------

4>没有为此解决方案配置选中要生成的项目 

1>  UVoxelizer.cc

2>  xmlparse.cc

2>D:\Geant4\geant4_10\source\externals\expat\src\xmlparse.cc(1912): error C3688: 文本后缀“L”无效;未找到文文本运算符或文本运算符模板“operator """"L”

1>C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\xtree(2022): error C3848: 具有类型“const UVoxelComparator”的表达式会丢失一些 const-volatile 限定符以调用“bool UVoxelComparator::operator ()(int,int)”

1>C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\xtree(2027): error C3848: 具有类型“const UVoxelComparator”的表达式会丢失一些 const-volatile 限定符以调用“bool UVoxelComparator::operator ()(int,int)”

1>C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include\xtree(2037): error C3848: 具有类型“const UVoxelComparator”的表达式会丢失一些 const-volatile 限定符以调用“bool UVoxelComparator::operator ()(int,int)”

5>------ 已跳过生成: 项目: PACKAGE, 配置: Release Win32 ------

5>没有为此解决方案配置选中要生成的项目 

6>------ 已跳过生成: 项目: INSTALL, 配置: Release Win32 ------

6>没有为此解决方案配置选中要生成的项目 

========== 生成: 成功 0 个,失败 2 个,最新 35 个,跳过 4 个 ==========

 

解决办法:

D:\Geant4\geant4_10\source\externals\expat\src\xmlparse.cc

1909 1910 行

#define V1(a,b,c) XML_L(#a)XML_L(".")XML_L(#b)XML_L(".")XML_L(#c)

#define V2(a,b,c) XML_L(" expat_")V1(a,b,c)

加空格

#define V1(a,b,c) XML_L(#a) XML_L(".") XML_L(#b) XML_L(".") XML_L(#c)

#define V2(a,b,c) XML_L(" expat_") V1(a,b,c)

 

D:\Geant4\geant4_10\source\externals\usolids\src\UVoxelizer.cc

468行 to:

bool operator()(int l, int r) const

2. 问题

   到此编译下去生成Geant4库release版是没有问题的,测试例子B1,使用Qt程序运行不了。

为了解决这个花了很多时间。先尝试编译debug版,无法生成processes库,库内对象太多超出限制。

   LINK : fatal error LNK1189: library limit of 65535 objects exceeded

尝试编译Granular库也不成功,最后把processes库分割成三个库,编译成功。调试找到了问题所在。

   D:\Geant4\geant4_10\source\interfaces\basic\src\G4UIQt.cc

   196行: masterG4coutDestination = this;

在网上搜索这个,找到了答案。

修改为:

#ifdef G4MULTITHREADED

 masterG4coutDestination = this;

#endif

237行:masterG4coutDestination = 0;

修改为:

#ifdef G4MULTITHREADED

    masterG4coutDestination = 0;

#endif

 

这是多线程语句。所以先行改吧。

 

库编好后CMake构建实例。提示Qt4

D:\Geant4\install\lib\Geant4-10.2.0\Geant4Config.cmake

243行:

find_package(Qt4 REQUIRED)

修改为:

find_package(Qt5 REQUIRED Core Gui Widgets OpenGL PrintSupport)

 

到此测试B1,B5,成功。

测试B3,执行不了。

D:\Geant4\test\B3\src\B3DetectorConstruction.cc

240,241行修改为:

//logicRing->SetVisAttributes (G4VisAttributes::Invisible);

//logicDetector->SetVisAttributes (G4VisAttributes::Invisible);  

 

OK!

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值