#include "G4IAEAphspWriter.hh" error

Dear all:
I’ve recently been learning how to use phase space files, and according to the manual, if I want to write my own phase space file, I should include the header file G4IAEAphspWriter.hh in the RunAction.cc file.

But when I wrote #include “G4IAEAphspWriter.hh” in the B1 example of RunAction.cc, my program started reporting errors and prompting me that I cannot open the file G4IAEAphspWriter.hh.

I would like to ask if there is something I did wrong? Thank you all for your replies.

It sounds like the path to the location of the G4IAEAphspWriter.hh header hasn’t been declared to the build. As it’s not part of the toolkit, where is it located on your system, or has it been copied alongside the sources of your application?

Dear @Jodie_Comer,

You need to copy the G4IAEAphsp* classes, and the specific IAEA routines, into your application code. Once done, as @bmorgan points out, you must ensure that your build properly “sees” the files copied.

Thank you for your reply. Is it because G4IAEAphspWriter.hh is not included in the G4 toolkit? I included G4IAEAphspWriter.hh directly in the B1 program without doing the rest of the work, I thought G4IAEAphspWriter.hh was a header file inside G4 and could be used directly like G4Box. So if I want to use G4IAEAphspWriter.hh what do I need to do?

Thanks for the quick reply, I’ll give it a try

Yes, these are external. Please have a look at:
and get the files from Index of /phsp/Geant4 (use v1.1).

I must warn that this code is obsolete, which means that it only works under sequential mode and you will need to update some lines (such as exceptions, etc.). I am currently trying to provide an updated version, but it’s being difficult for me to find enough time for this.

1 Like

Thank you so much, this really helped me a lot, cheers!

Hi, according to the advice you gave me yesterday, I added the header file and source file of G4IAEAphspWriter to my project, then I found that the file iaea_phsp.h is used in the source file of G4IAEAphspWriter. I downloaded an example from the official website and found the iaea_phsp.h file in this example, how should I use this file, do I copy this file directly to the project’s include folder?

Hi, added the following paragraph to the cmakelist file.
file(GLOB headers ${PROJECT_SOURCE_DIR}/include/*.h)
This helped me to solve the problem of the include file still giving me errors, then I started to compile my project but after using the make -j command I got the following error.

/usr/bin/ld: CMakeFiles/exampleB1.dir/src/G4IAEAphspWriter.cc.o: in function G4IAEAphspWriter::UpdateHeaders()': G4IAEAphspWriter.cc:(.text+0x218): undefined reference to iaea_update_header’
/usr/bin/ld: CMakeFiles/exampleB1.dir/src/G4IAEAphspWriter.cc.o: in function G4IAEAphspWriter::StoreIAEAParticle(G4Step const*, int)': G4IAEAphspWriter.cc:(.text+0x4ab): undefined reference to iaea_write_particle’
/usr/bin/ld: CMakeFiles/exampleB1.dir/src/G4IAEAphspWriter.cc.o: in function G4IAEAphspWriter::EndOfRunAction(G4Run const*)': G4IAEAphspWriter.cc:(.text+0xa2d): undefined reference to iaea_print_header’
/usr/bin/ld: G4IAEAphspWriter.cc:(.text+0xa44): undefined reference to iaea_destroy_source' /usr/bin/ld: CMakeFiles/exampleB1.dir/src/G4IAEAphspWriter.cc.o: in function G4IAEAphspWriter::BeginOfRunAction(G4Run const*)‘:
G4IAEAphspWriter.cc:(.text+0x168d): undefined reference to iaea_new_source' /usr/bin/ld: G4IAEAphspWriter.cc:(.text+0x16e6): undefined reference to iaea_set_constant_variable’
/usr/bin/ld: G4IAEAphspWriter.cc:(.text+0x16f6): undefined reference to iaea_set_total_original_particles' /usr/bin/ld: G4IAEAphspWriter.cc:(.text+0x1724): undefined reference to iaea_set_extra_numbers’
/usr/bin/ld: G4IAEAphspWriter.cc:(.text+0x1752): undefined reference to `iaea_set_type_extralong_variable’
collect2: error: ld returned 1 exit status

Please tell me where the problem might be. thank you

This means that the “G4IAEAphshWriter” class depends on other functions in other classes in that G4IAEA (?) package. You either need to build that package as a separate library, and specify to link that library into your application, or you need to copy the whole package into your application.

Since the G4IAEA packge is not part of Geant4, you probably need to contact the developers of that package directly. Does the G4IAEA documentation provide any guidance?

Thanks for your reply, the only information I can find about G4IAEA is the URL provided by mcortes above, if he is part of an external library then I should link to this library first?

Good news, I seem to have found the problem, I forgot to copy some files to my project. According to the official manual I just copied the header files (.h or .hh) but forgot to copy the source files (.cc or .cpp). I feel like I was really careless!

The source files are where the actual functions are defined, so if it’s done this way, you need the .cc files to get the “object symbols” into your library, and then the places where you (or something) calls those functions will be able to find them.

From reading those earlier posts, my interpretation is that this was somebody’s specific project, and it seemed useful enough to let others copy it. But it’s not really packaged up as an external library or tool that you could link to.

Glad you were able to get it working!