Linking Issue When Using "make"

Hello. I’ve only been using Geant4 for a few months now and am attempting to build my own simple program within G4. The purpose of this is to output a list of solar spectra data. I’ve modeled the application structure after the examples provided, as shown below:

: /mnt/c/Users/namth/Desktop/Research/GEANT4/geant4-install/share/Geant4-10.6.1/G4EXOP$ ls
B1test B1test-build solarData solarData-build

: …/GEANT4/geant4-install/share/Geant4-10.6.1/G4EXOP/solarData$ ls
CMakeLists.txt include solarData.cc solarData.cc.o solarData.out src

: …/GEANT4/geant4-install/share/Geant4-10.6.1/G4EXOP/solarData/include$ ls
kurucz_irradiance.hh kurucz_resid_flux.hh solarData.cc.o

: …/GEANT4/geant4-install/share/Geant4-10.6.1/G4EXOP/solarData/src$ ls
KuruczFluxResid.txt KuruczIrradiance.txt kurucz_irradiance.cpp kurucz_resid_flux.cpp solarData.cc solarData.cc.o

Now, I’ve also rewritten CMakeLists.txt to what I believe should be the correct format given the specifics of my application. Using the DGeant4_DIR cmake command in my build directory works fine. However, when I use the “make” command inside my build directory, I receive the following errors:

Clearly this appears to be a linking issue where CMakeFiles/solarData.dir/solarData.cc.o cannot find my header/source files to be able to access the functions in the main program. I do not know how to fix this. I’ve been trying to use commands to establish a link from solarData.cc.o to ./src or ./include such as “ld” but it gives the same errors. Any help with this would be fantastic.

Thanks for your time.

Where is SolarFluxResid defined? Looks like something in solarData.cc tries to use the SolarFluxResid functions but they have not been defined/compiled as part of the project.

Is it in kurucz_resid_flux.cpp? Is that file referenced in you CMakeLists.txt file?

@php1ic Thank you for the reply. The SolarFluxResid class is defined inside kurucz_resid_flux.hh, with the member functions being defined inside the kurucz_resid_flux.cpp.

In my CMakeLists.txt file, the headers are compiled using the command include_directories(${PROJECT_SOURCE_DIR}/include)
and I believe then located and linked using
file(GLOB headers ${PROJECT_SOURCE_DIR}/include/*.hh)
add_executable(solarData solarData.cc ${sources} ${headers})

I did not change the above when adapting the CMakeLists.txt, but I’ve pasted the commands from CMakeLists.txt below which I did edit. Perhaps I’ve made a mistake here that I cannot seem to find. The “project” in the CMakeLists file is solarD, as seen below. In add_executable, do I need to include solarData if solarData.cc is the actual main executable?

add_executable(solarData solarData.cc ${sources} ${headers})
target_link_libraries(solarData ${Geant4_LIBRARIES})

set(SOLARDATA_SCRIPTS
solarData.out
)

add_custom_target(solarD DEPENDS solarData)

install(TARGETS solarData DESTINATION bin)

How is the sources variable defined? If it is the same way as in a ‘normal’ geant4 CMakeLists.txt file, i.e.

file(GLOB sources ${PROJECT_SOURCE_DIR}/src/*.cc)

Then it will not be picking up the .cpp file.

Also, in the snippet you posted, you have missed the $ sign to actually access the sources and headers variable. Is this just a typo?

@php1ic This was the exact issue. I changed the suffixes from .cpp to .cc and it worked like a charm. Figures it was something that small. I very much appreciate your help.

1 Like