Description
When using the compile code feature, GDB produces the following error:
Could not load libcc1.so: libcc1.so: cannot open shared object file: No such file or directory
Steps To Reproduce
Steps to reproduce the behavior:
- Make a simple program:
#include <stdio.h>
int main() {
printf("Hello, world!\n");
return 0;
}
- Compile it
gcc -O0 -g main.c
- Open the compiled result in GDB
gdb a.out
- Place a breakpoint in the program
b main
- Run the program
r
- Try compiling and running some code from within GDB
compile code printf("Hello from GDB!\n")
- GDB produces the error listed above
Expected behavior
GDB should compile and execute the code written in the compile code command. You can test this on your system through distrobox if you want.
Screenshots

Additional context
First, some background on libcc1.
libcc1 is a plugin for gdb that lets it compile C and C++ code through its compile code command.
libcc1 is part of gcc, and gdb is supposed to dlopen() it when compile code is called.
- gcc in nixpkgs has an option called
disableGdbPlugin that causes libcc1 to not be compiled, although I think it's false by default.
Now that we're on the same page, let's continue.
gdb dlopen()s libcc1.so (defined here for C and here for c++), which it can't find under NixOS. I tried patching gdb with overrideAttrs (patch is below) to make it open libcc1.so from the nix store, including patching gcc to tell it to include the lib output in the outputsToInstall , which is the output that contains libcc1.so. This seems to get closer to working result, but produces the error Could not find a compiler matching "^(x86_64|i.86)(-[^-]*)?-linux(-gnu[^-]*)?-gcc$", which I found is produced by libcc1 by searching binary files in my nix store with ripgrep for Could not find a compiler matching.
Interestingly, I have noticed that there seem to be a few other places that I find libcc1.so in my nix store:
/nix/store/(sha256)-x86_64-unknown-linux-musl-gcc-13.3.0/lib/gcc/x86_64-unknown-linux-musl/13.3.0/plugin/libcc1plugin.so
/nix/store/(sha256)-gcc-13.2.0/lib/gcc/x86_64-unknown-linux-gnu/13.2.0/plugin/libcc1plugin.so
These are in addition to the path that I'm using in my patch below at /nix/store/(sha256)-gcc-13.2.0-lib/lib/libcc1.so (aka ${pkgs.gcc-unwrapped.lib}/lib/libcc1.so). You'll notice that these places call the file libcc1plugin.so rather than libcc1.so, so I'm not convinced it is the same file or a valid replacement, but I wasn't able to test this because something in the build process replaces the -linux- part of the path with just -l- whenever I set gdb's GCC_C_FE_LIBCC and GCC_CP_FE_LIBCC variables to point to that location. I'm not sure how to disable this behavior or what is causing it, so I don't know how to test this. (Although I presume it's nix.)
Are there any ideas as to what we can do to help it locate it? I would really like to get this functionality working. As I mentioned earlier, it works on other distros, including Arch Linux through distrobox.
(gdb.overrideAttrs (new: {
buildInputs = pkgs.gdb.buildInputs ++ [ gcc-unwrapped ];
# nativeBuildInputs = pkgs.gdb.nativeBuildInputs ++ [ gcc libcxx ];
env.NIX_LDFLAGS = lib.optionalString stdenv.hostPlatform.isLinux "-rpath ${lib.makeLibraryPath [ gcc-unwrapped ]}";
dontPatchELF = true; # needed or nix will try to optimize the binary by removing "useless" rpath
patches = [
(pkgs.substituteAll {
gcc = "${((pkgs.gcc-unwrapped.override {
disableGdbPlugin = false;
}).overrideAttrs (oldAttrs: {
meta.outputsToInstall = oldAttrs.meta.outputsToInstall ++ [ "lib" ];
})).lib}";
# gcc = pkgs.gcc;
src =
(writeText "libcc-fix.patch" ''
diff --git a/include/gcc-c-interface.h b/include/gcc-c-interface.h
index 700d7483a4a..b5c800d3a44 100644
--- a/include/gcc-c-interface.h
+++ b/include/gcc-c-interface.h
@@ -191,7 +191,7 @@ struct gcc_c_context
/* The name of the .so that the compiler builds. We dlopen this
later. */
-#define GCC_C_FE_LIBCC libcc1.so
+#define GCC_C_FE_LIBCC @gcc@/lib/libcc1.so
/* The compiler exports a single initialization function. This macro
holds its name as a symbol. */
diff --git a/include/gcc-cp-interface.h b/include/gcc-cp-interface.h
index 15b911cb216..cf69c4f3d4f 100644
--- a/include/gcc-cp-interface.h
+++ b/include/gcc-cp-interface.h
@@ -473,7 +473,7 @@ struct gcc_cp_context
/* The name of the .so that the compiler builds. We dlopen this
later. */
-#define GCC_CP_FE_LIBCC libcc1.so
+#define GCC_CP_FE_LIBCC @gcc@/lib/libcc1.so
/* The compiler exports a single initialization function. This macro
holds its name as a symbol. */
'');
})
];
}))
Notify maintainers
Pinging gcc and gdb maintainers since I'm not sure whether this should be fixed in GCC or GDB (could be both).
GDB:
GCC:
Metadata
Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.
[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"
- system: `"x86_64-linux"`
- host os: `Linux 6.10.9, NixOS, 24.11 (Vicuna), 24.11.20240910.1355a0c`
- multi-user?: `yes`
- sandbox: `yes`
- version: `nix-env (Nix) 2.18.5`
- channels(blake): `""`
- channels(root): `"nixos"`
- nixpkgs: `/nix/store/qpg5mwsind2hy35b9vpk6mx4jimnypw0-source`
Add a 👍 reaction to issues you find important.
Description
When using the
compile codefeature, GDB produces the following error:Steps To Reproduce
Steps to reproduce the behavior:
gcc -O0 -g main.cgdb a.outb mainrcompile code printf("Hello from GDB!\n")Expected behavior
GDB should compile and execute the code written in the
compile codecommand. You can test this on your system through distrobox if you want.Screenshots
Additional context
First, some background on
libcc1.libcc1is a plugin for gdb that lets it compile C and C++ code through itscompile codecommand.libcc1is part of gcc, and gdb is supposed todlopen()it whencompile codeis called.disableGdbPluginthat causeslibcc1to not be compiled, although I think it'sfalseby default.Now that we're on the same page, let's continue.
gdb
dlopen()slibcc1.so(defined here for C and here for c++), which it can't find under NixOS. I tried patching gdb with overrideAttrs (patch is below) to make it openlibcc1.sofrom the nix store, including patching gcc to tell it to include theliboutput in theoutputsToInstall, which is the output that containslibcc1.so. This seems to get closer to working result, but produces the errorCould not find a compiler matching "^(x86_64|i.86)(-[^-]*)?-linux(-gnu[^-]*)?-gcc$", which I found is produced bylibcc1by searching binary files in my nix store with ripgrep forCould not find a compiler matching.Interestingly, I have noticed that there seem to be a few other places that I find
libcc1.soin my nix store:These are in addition to the path that I'm using in my patch below at
/nix/store/(sha256)-gcc-13.2.0-lib/lib/libcc1.so(aka${pkgs.gcc-unwrapped.lib}/lib/libcc1.so). You'll notice that these places call the filelibcc1plugin.sorather thanlibcc1.so, so I'm not convinced it is the same file or a valid replacement, but I wasn't able to test this because something in the build process replaces the-linux-part of the path with just-l-whenever I set gdb'sGCC_C_FE_LIBCCandGCC_CP_FE_LIBCCvariables to point to that location. I'm not sure how to disable this behavior or what is causing it, so I don't know how to test this. (Although I presume it's nix.)Are there any ideas as to what we can do to help it locate it? I would really like to get this functionality working. As I mentioned earlier, it works on other distros, including Arch Linux through distrobox.
Notify maintainers
Pinging gcc and gdb maintainers since I'm not sure whether this should be fixed in GCC or GDB (could be both).
GDB:
GCC:
Metadata
Please run
nix-shell -p nix-info --run "nix-info -m"and paste the result.Add a 👍 reaction to issues you find important.