Segmentation fault - BeamOn()

Hi, I am new to Geant4 and I have been trying recently to prepare a Bremsstrahlung simulation.
I managed to compile and run Example B1 from the basic.
However I do not fully understand its macros yet, so I don’t know which of them my code requires.
For that reason I tried to run it in what the website http://geant4-userdoc.web.cern.ch/geant4-userdoc/UsersGuides/ForApplicationDeveloper/html/GettingStarted/executeProgram.html calls ‘Hard-coded’ Batch Mode.

My main code goes past the command runManager->Initialize(), printing a similar output to example B1 (up to where the file “run1.mac” has the command line /control/verbose 2). But right after that I get the segmentation fault.
I am not sure how to understand its source, so far what I did was add G4cout<<"test"<<endl; between the code lines to see at which point the segmentation fault error appears before test.
And found that it happened right after the command runManager->Initialize() and right before:

    G4int nevents=1;//0000
    runManager->BeamOn(nevents);

Do you have any suggestion on how I can diagnose this error?
Does it have to do with not using the macros?
Thanks