I want to debug my c++ code which is a simulation running on remage/Geant4.
I need to activate the apptainer container based on the gipert remage-base:latest docker container, which is created by the command apptainer build remage-base_latest.sif docker://gipert/remage-base:latest
.
My code is compiled by cmake. I create a build folder in my working directory (wd), go inside and use cmake ..
and make
to compile my code. Then I start the program with wd/build/Simulation -m run.mac -l
.
Now I want to do everything in vscode to use the debugger with breakpoints. For that I wrote a launch.json to run the Simulation in debugging mode using gdb, and a tasks.json to start the apptainer container and compile the code in debugging mode.
launch.json
"version": "0.2.0",
"configurations": [
{
"type": "cmake",
"request": "launch",
"name": "CMake: Configure project",
"cmakeDebugType": "configure",
"clean": false,
"configureAll": false
},
{
"name": "C++ Debugging in Apptainer",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/MySimulation",
"args": [
"-m",
"${workspaceFolder}/run.mac",
"-l"
],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb",
"setupCommands": [
{
"description": "GDB Pretty Printing",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "build: cmake & make"
}
]
}
tasks.json
"version": "2.0.0",
"tasks": [
{
"label": "build: cmake & make",
"type": "shell",
"command": "apptainer",
"args": [
"exec",
"../../remage02/remage-base.sif",
"bash",
"-c",
"cmake -DCMAKE_BUILD_TYPE:STRING=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE -DCMAKE_C_COMPILER:FILEPATH=/usr/bin/gcc -DCMAKE_CXX_COMPILER:FILEPATH=/usr/bin/g++ --no-warn-unused-cli -S ${workspaceFolder} -B ${workspaceFolder}/build && make -C ${workspaceFolder}/build"
],
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": [
"$gcc"
],
"detail": "Run CMake and Make in the Apptainer container"
}
]
}
It doesn't work. The code gets compiled, but afterwards an error appears: error while loading shared libraries: libG4run.so: cannot open shared object file: No such file or directory [1] + Done "/usr/bin/gdb" --interpreter=mi --tty=${DbgTerm} 0<"/tmp/Microsoft-MIEngine-In-a0wh0kw5.tvp" 1>"/tmp/Microsoft-MIEngine-Out-0vw3qdd4.4l5"
My guess is that the debugger should run in the apptainer itself, as the libraries were pulled from the apptainer during compilation. I don't think this works with my launch.json. To run gbd in the container, the container itself must contain gbdserver to communicate with vscode via a port. However, I don't want to have to change the gipert docker image.
What are the possibilities to compile c++ code with cmake in an apptainer container and then debug the code with vscode while the apptainer environment is still needed when running the program?