Sublime Text and Geant4

Hello,

I am trying to figure out how I can compile and run Geant4 Applications with Sublime Text 3. For testing I am trying it with the “Example B1”. Maybe someone is using Sublime Text and can help? I am using a Mac.

To include all header files I just passed the locations of them in my build system. It now looks like this:

{

	"shell_cmd": "g++ \"${file}\" -o \"${file_path}/${file_base_name}\" \"-I/Users/myname/Geant4/geant4-install/include/Geant4\" \"-I${file_path}/include\" ",

	"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
	"working_dir": "${file_path}",
	"selector": "source.c++",

	"variants":
	[
		{
			"name": "Run",
			"shell_cmd": "g++ \"${file}\" -o \"${file_path}/${file_base_name}\" && \"${file_path}/${file_base_name}\""
		}
	]
}

It is basically the default c++ build system and I added both include folders from the Example B1 and the Geant4 Install Folder with the option “-I/…”.

When I now try to run “exampleB1.cc” I get error messages like

In file included from /Users/myname/Geant4_new/geant4-install/include/Geant4/CLHEP/Units/PhysicalConstants.h:41:
/Users/myname/Geant4_new/geant4-install/include/Geant4/CLHEP/Units/SystemOfUnits.h:53:20: error: expected unqualified-id
  static constexpr double     pi  = 3.14159265358979323846;

or

In file included from /Users/myname/Geant4_new/geant4-install/include/Geant4/G4GeomSplitter.hh:41:
/Users/myname/Geant4_new/geant4-install/include/Geant4/G4AutoLock.hh:330:68: error: expected ';' at end of declaration list
    G4TemplateAutoLock(mutex_type& _mutex, std::defer_lock_t _lock) noexcept

And many more of that sort. What could be the problem? I am fairly new to all of this. Thank you!

Hello. I don’t have a quick answer, but I’m interested too in trying to figure out a way.

I can see two ways forward: hooking into the build system of Geant4 by launching the cmake-generated build. Or figuring out the exact command line to use per file, as you are trying to do.

From emacs I have used the first way for many years: I simply say M-x compile and have it execute “cd build_directory; make exampleB1” and the compilation/link is launched, errors are parsed by emacs; then a simple " ^x ` " will land me on the next error.

I am not familiar enough with the Sublime Text build system to create something similar or understand whether that it could parse the errors from multiple files ok. I tried it a couple of years ago, but could not progress.

For the second approach, which your code indicates you took, I would run the build too (“make” or “ninja”) in verbose mode and attempt to replicate the command line.

I would guess that one of the current problem is that you have not replicated the ‘standard’ compilation flags used by Geant4 - in particular “-std-cxx-11”.

When I look for the compilation flags with clang on MacOS, using “ninja -v exampleB2b” I get a large set of compilation flags, in particular

-stdlib=libc++ -pthread -ftls-model=initial-exec -std=c++11 -W -Wall -pedantic -Wno-non-virtual-dtor -Wno-long-long -Wwrite-strings -Wpointer-arith -Woverloaded-virtual -Wno-variadic-macros -Wshadow -pipe -Qunused-arguments -DGL_SILENCE_DEPRECATION -stdlib=libc++ -pthread -ftls-model=initial-exec

I suggest that you do something similar to identify the complete set of compilation flags required.

It should be possible also to extract them by making some ‘print’ additions to the Geant4 CMakeFile. I will see if I could get something like this to work, to create something that is a bit more robust (and hopefully portable.)