{"id":421,"date":"2015-07-20T22:08:38","date_gmt":"2015-07-20T22:08:38","guid":{"rendered":"https:\/\/blog.afach.de\/?page_id=421"},"modified":"2021-07-01T17:57:31","modified_gmt":"2021-07-01T17:57:31","slug":"hdf5-auto-compile-script","status":"publish","type":"page","link":"https:\/\/blog.afach.de\/?page_id=421","title":{"rendered":"HDF5 Static (with \/MT flag) compilation Auto compile script &#8211; Visual Studio"},"content":{"rendered":"<p>This is a compile script that compiles HDF5 libraries from source statically with multithread support, i.e., &#8220;\/MT&#8221; flag in Visual Studio. automatically.<\/p>\n<h3>Warning<\/h3>\n<p>After discussing with one of the programmers\u00a0of HDF5, it was made clear that <span style=\"color: #ff0000;\">linking statically works safely only in the condition HDF5 library\u00a0wasn&#8217;t compiled with parallel support.<\/span><\/p>\n<h3>The script<\/h3>\n<p>The script involves going to the file<\/p>\n<pre>config\\cmake\\UserMacros\\Windows_MT.cmake<\/pre>\n<p>and copying the file&#8217;s contents to &#8220;UserMacros.cmake&#8221;. The same is also done for ZLib and SZip after extracting them, and rezipping them again.<\/p>\n<pre>@echo off\n::The following is the name of the folder of HDF5 source\nset \"hdffolder=hdf5-1.8.16\"\n\n::add a new line then add \/MT compilation options\ncall echo &amp; echo. &gt;&gt; %hdffolder%\\UserMacros.cmake\ncat %hdffolder%\\config\\cmake\\UserMacros\\Windows_MT.cmake &gt;&gt; %hdffolder%\\UserMacros.cmake\nfor %%i in (%hdffolder%\\UserMacros.cmake) do sed -i \"s\/\\\"Build With Static CRT Libraries\\\" OFF\/\\\"Build With Static CRT Libraries\\\" ON\/g\" %%i\n\n::add a new line then add \/MT to SZip after extracting it, and then recompress it\ngzip -dc SZip.tar.gz | tar -xf -\nmv SZip.tar.gz SZip-dynamic.tar.gz\ncall echo &amp; echo. &gt;&gt; UserMacros.cmake\ncat SZip\\config\\cmake\\UserMacros\\Windows_MT.cmake &gt;&gt;SZip\\UserMacros.cmake\nfor %%i in (SZip\\UserMacros.cmake) do sed -i \"s\/\\\"Build With Static CRT Libraries\\\" OFF\/\\\"Build With Static CRT Libraries\\\" ON\/g\" %%i\ntar cf SZip.tar SZip\ngzip SZip.tar\nrm -r SZip\n\n::do the same to ZLib\ngzip -dc ZLib.tar.gz | tar -xf -\nmv ZLib.tar.gz ZLib-dynamic.tar.gz\ncall echo &amp; echo. &gt;&gt; UserMacros.cmake\ncat ZLib\\config\\cmake\\UserMacros\\Windows_MT.cmake &gt;&gt;ZLib\\UserMacros.cmake\nfor %%i in (ZLib\\UserMacros.cmake) do sed -i \"s\/\\\"Build With Static CRT Libraries\\\" OFF\/\\\"Build With Static CRT Libraries\\\" ON\/g\" %%i\ntar cf ZLib.tar ZLib\ngzip ZLib.tar\nrm -r ZLib\n\nbuild-VS2013-32.bat<\/pre>\n<h3>Requirements<\/h3>\n<p>1- <a href=\"http:\/\/www.cmake.org\/download\/\">CMake<\/a> (add its executable folder to path)<br \/>\n2- <a href=\"https:\/\/github.com\/bmatzelle\/gow\/downloads\">GOW<br \/>\n<\/a>3- <a href=\"https:\/\/www.visualstudio.com\/en-us\/products\/visual-studio-express-vs.aspx\">Visual Studio or C++ Express<\/a>\u00a0(this you can get for free from Microsoft, but I assume you know enough about this already since you&#8217;re here)<\/p>\n<p>Note: If CMake won&#8217;t show in path in command prompt, run prompt as administrator, or use this command to add the path you want to the environment variable %PATH%<\/p>\n<pre><code>set PATH=C:\\Program Files (x86)\\CMake\\bin;%PATH%<\/code><\/pre>\n<p>Gow is GNU tools for windows, like tar, gzip and sed. These are important for the script.<\/p>\n<p>Whether you&#8217;d like to have a 32-bit or 64-bit version of visual studio used depends on the environment variables that are defined.\u00a0The easiest way is to run the run command prompt for the version you want. For example, in Visual Studio 2013, if one goes to Start, then types in quick search &#8220;Visual&#8221;, you&#8217;ll find a folder called &#8220;Visual Studio Tools&#8221;. This folder will have both command prompts with the relevant environment variables. The following shows this folder:<\/p>\n<p><a href=\"https:\/\/blog.afach.de\/wp-content\/uploads\/2015\/07\/VisualStudioCMDShortcuts.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-400 size-full\" src=\"https:\/\/blog.afach.de\/wp-content\/uploads\/2015\/07\/VisualStudioCMDShortcuts.jpg\" alt=\"VisualStudioCMDShortcuts\" width=\"2179\" height=\"1034\" srcset=\"https:\/\/blog.afach.de\/wp-content\/uploads\/2015\/07\/VisualStudioCMDShortcuts.jpg 2179w, https:\/\/blog.afach.de\/wp-content\/uploads\/2015\/07\/VisualStudioCMDShortcuts-300x142.jpg 300w, https:\/\/blog.afach.de\/wp-content\/uploads\/2015\/07\/VisualStudioCMDShortcuts-1024x486.jpg 1024w\" sizes=\"auto, (max-width: 2179px) 100vw, 2179px\" \/><\/a><\/p>\n<h3>Prepare to run the script<\/h3>\n<p>Go to <a href=\"https:\/\/support.hdfgroup.org\/HDF5\/release\/\" target=\"_blank\" rel=\"noopener\">this page<\/a>, and download the CMake source. Extract it; put the script in a file there; if the version you want to compile is different than the one in the script, modify the folder name; and finally run the script. After the script is finished, you&#8217;ll have a compressed zip file with compiled source and an installer executable.<\/p>\n<p><a href=\"https:\/\/blog.afach.de\/wp-content\/uploads\/2015\/07\/HDF5FolderLook.gif\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-423 size-full\" src=\"https:\/\/blog.afach.de\/wp-content\/uploads\/2015\/07\/HDF5FolderLook.gif\" alt=\"HDF5FolderLook\" width=\"2230\" height=\"1067\" \/><\/a>The file HDF5CompileScript.bat is where I copied the script of compile that I created. Just run this script through the command prompt of visual studio and it&#8217;ll compile.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is a compile script that compiles HDF5 libraries from source statically with multithread support, i.e., &#8220;\/MT&#8221; flag in Visual Studio. automatically. Warning After discussing with one of the programmers\u00a0of HDF5, it was made clear that linking statically works safely only in the condition HDF5 library\u00a0wasn&#8217;t compiled with parallel support. The script The script involves &hellip; <a href=\"https:\/\/blog.afach.de\/?page_id=421\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">HDF5 Static (with \/MT flag) compilation Auto compile script &#8211; Visual Studio<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":397,"menu_order":0,"comment_status":"open","ping_status":"open","template":"","meta":{"footnotes":"","_links_to":"","_links_to_target":""},"class_list":["post-421","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/blog.afach.de\/index.php?rest_route=\/wp\/v2\/pages\/421","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.afach.de\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/blog.afach.de\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/blog.afach.de\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.afach.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=421"}],"version-history":[{"count":7,"href":"https:\/\/blog.afach.de\/index.php?rest_route=\/wp\/v2\/pages\/421\/revisions"}],"predecessor-version":[{"id":847,"href":"https:\/\/blog.afach.de\/index.php?rest_route=\/wp\/v2\/pages\/421\/revisions\/847"}],"up":[{"embeddable":true,"href":"https:\/\/blog.afach.de\/index.php?rest_route=\/wp\/v2\/pages\/397"}],"wp:attachment":[{"href":"https:\/\/blog.afach.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=421"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}