Cmake multiple definitions when linking

I’m trying to update roxterm to the latest version.

The build system has changed from the previous version, and I am trying fight with getting the new cmake-based build system working.

Here’s the derivation I have:

{ stdenv, fetchurl, pkgconfig, wrapGAppsHook, cmake, gtk3, dbus, dbus-glib, vte
, pcre, harfbuzz, libpthreadstubs, libXdmcp, utillinuxMinimal, glib
, hicolor-icon-theme, docbook_xsl, xmlto, libselinux, libsepol, libxkbcommon, epoxy, at-spi2-core, libXtst, libtasn1, p11-kit, libxslt
}:

stdenv.mkDerivation rec {
  pname = "roxterm";
  version = "3.7.5";

  src = fetchurl {
    url = "https://github.com/realh/roxterm/archive/${version}.tar.gz";
    sha256 = "157sk0n8pzq35mywg343c40i17037as0y7syxh395xg3366j3gss";
  };

  nativeBuildInputs = [ cmake pkgconfig wrapGAppsHook libxslt ];

  buildInputs =
    [ gtk3 dbus dbus-glib vte pcre harfbuzz libpthreadstubs libXdmcp
      utillinuxMinimal glib hicolor-icon-theme docbook_xsl xmlto libselinux libsepol 
      libxkbcommon epoxy at-spi2-core libXtst libtasn1 p11-kit ];

  cmakeFlags = [
    "-DCMAKE_BUILD_TYPE=Release"
  ];

  meta = with stdenv.lib; {
    homepage = http://roxterm.sourceforge.net/;
    license = licenses.gpl3;
    description = "Tabbed, VTE-based terminal emulator";
    longDescription = ''
      Tabbed, VTE-based terminal emulator. Similar to gnome-terminal without
      the dependencies on Gnome.
    '';
    maintainers = with maintainers; [ cdepillabout ];
    platforms = platforms.linux;
  };
}

When I try to build it, I get strange errors about functions being included twice:

$ nix-build -A roxterm
these derivations will be built:
  /nix/store/zc1rlqyflyzbm9ra7fxfg8m0nkw48j6y-roxterm-3.7.5.drv
building '/nix/store/zc1rlqyflyzbm9ra7fxfg8m0nkw48j6y-roxterm-3.7.5.drv'...
unpacking sources
unpacking source archive /nix/store/4cfd5aggs2lny5yhs3rizg4amgfws5xs-3.7.5.tar.gz
source root is roxterm-3.7.5
setting SOURCE_DATE_EPOCH to timestamp 1560011074 of file roxterm-3.7.5/version.sh
patching sources
configuring
fixing cmake files...
cmake flags: -DCMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY=ON -DCMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY=ON -DCMAKE_EXPORT_NO_PACKAGE_REGISTRY=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_SKIP_BUILD_RPATH=ON -DBUILD_TESTING=OFF -DCMAKE_INSTALL_LOCALEDIR=/nix/store/0kngar5xjm79havpnfj29l6bmn7vf46p-roxterm-3.7.5/share/locale -DCMAKE_INSTALL_LIBEXECDIR=/nix/store/0kngar5xjm79havpnfj29l6bmn7vf46p-roxterm-3.7.5/libexec -DCMAKE_INSTALL_LIBDIR=/nix/store/0kngar5xjm79havpnfj29l6bmn7vf46p-roxterm-3.7.5/lib -DCMAKE_INSTALL_DOCDIR=/nix/store/0kngar5xjm79havpnfj29l6bmn7vf46p-roxterm-3.7.5/share/doc/ -DCMAKE_INSTALL_INFODIR=/nix/store/0kngar5xjm79havpnfj29l6bmn7vf46p-roxterm-3.7.5/share/info -DCMAKE_INSTALL_MANDIR=/nix/store/0kngar5xjm79havpnfj29l6bmn7vf46p-roxterm-3.7.5/share/man -DCMAKE_INSTALL_OLDINCLUDEDIR=/nix/store/0kngar5xjm79havpnfj29l6bmn7vf46p-roxterm-3.7.5/include -DCMAKE_INSTALL_INCLUDEDIR=/nix/store/0kngar5xjm79havpnfj29l6bmn7vf46p-roxterm-3.7.5/include -DCMAKE_INSTALL_SBINDIR=/nix/store/0kngar5xjm79havpnfj29l6bmn7vf46p-roxterm-3.7.5/sbin -DCMAKE_INSTALL_BINDIR=/nix/store/0kngar5xjm79havpnfj29l6bmn7vf46p-roxterm-3.7.5/bin -DCMAKE_INSTALL_NAME_DIR=/nix/store/0kngar5xjm79havpnfj29l6bmn7vf46p-roxterm-3.7.5/lib -DCMAKE_POLICY_DEFAULT_CMP0025=NEW -DCMAKE_OSX_DEPLOYMENT_TARGET= -DCMAKE_OSX_SYSROOT= -DCMAKE_FIND_FRAMEWORK=last -DCMAKE_STRIP=/nix/store/mgdjnsrkqgmxqjaqaxgqyqm7fwyi96fk-binutils-2.31.1/bin/strip -DCMAKE_RANLIB=/nix/store/mgdjnsrkqgmxqjaqaxgqyqm7fwyi96fk-binutils-2.31.1/bin/ranlib -DCMAKE_AR=/nix/store/mgdjnsrkqgmxqjaqaxgqyqm7fwyi96fk-binutils-2.31.1/bin/ar -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_INSTALL_PREFIX=/nix/store/0kngar5xjm79havpnfj29l6bmn7vf46p-roxterm-3.7.5 -DCMAKE_BUILD_TYPE=Release
-- The C compiler identification is GNU 7.4.0
-- Check for working C compiler: /nix/store/hpzj855nkgjvg58nrhq4910sb9q3kss1-gcc-wrapper-7.4.0/bin/gcc
...
-- Checking for module 'vte-2.91>=0.52'
--   Found vte-2.91, version 0.56.3
-- Configuring done
WARNING: Target "roxterm" requests linking to directory "/nix/store/zhzgdnnaf34imjw6cf057fjdvl8nnfa6-gtk+3-3.24.10/lib".  Targets may link only to libraries.  CMake is dropping the item.
WARNING: Target "roxterm" requests linking to directory "/nix/store/0zqsskz8z8pir370pdvyng46hkhm5bmf-atk-2.32.0/lib".  Targets may link only to libraries.  CMake is dropping the item.
WARNING: Target "roxterm" requests linking to directory "/nix/store/f9skp1y3jr0658b2vgnnj3ginvj71x9p-glib-2.60.4/lib".  Targets may link only to libraries.  CMake is dropping the item.
WARNING: Target "roxterm" requests linking to directory "/nix/store/km0cihvqkdh18bfxv4vq6j3wfyxhvfxj-cairo-1.16.0/lib".  Targets may link only to libraries.  CMake is dropping the item.
WARNING: Target "roxterm" requests linking to directory "/nix/store/2d3rkijizp97am419pzlfnnwzm8vb6jr-gdk-pixbuf-2.38.1/lib".  Targets may link only to libraries.  CMake is dropping the item.
WARNING: Target "roxterm" requests linking to directory "/nix/store/2bks73r7ja5y1vm076pm4h5qa32bhdjj-pango-1.43.0/lib".  Targets may link only to libraries.  CMake is dropping the item.
WARNING: Target "roxterm" requests linking to directory "/nix/store/f5941c1q64n8kwa8jx4pfc8y1xvf1r7d-dbus-1.12.16-lib/lib".  Targets may link only to libraries.  CMake is dropping the item.
...
[ 91%] Building C object src/CMakeFiles/roxterm.dir/session-file.c.o
/nix/store/mgdjnsrkqgmxqjaqaxgqyqm7fwyi96fk-binutils-2.31.1/bin/ld: CMakeFiles/rtlib.dir/colourscheme.c.o: in function `colour_scheme_reset_cached_data':
colourscheme.c:(.text+0x1f0): multiple definition of `colour_scheme_reset_cached_data'; CMakeFiles/rtlib.dir/colourscheme.c.o:colourscheme.c:(.text+0x1f0): first defined here
/nix/store/mgdjnsrkqgmxqjaqaxgqyqm7fwyi96fk-binutils-2.31.1/bin/ld: CMakeFiles/rtlib.dir/colourscheme.c.o: in function `colour_scheme_lookup_and_ref':
colourscheme.c:(.text+0x260): multiple definition of `colour_scheme_lookup_and_ref'; CMakeFiles/rtlib.dir/colourscheme.c.o:colourscheme.c:(.text+0x260): first defined here
/nix/store/mgdjnsrkqgmxqjaqaxgqyqm7fwyi96fk-binutils-2.31.1/bin/ld: CMakeFiles/rtlib.dir/colourscheme.c.o: in function `colour_scheme_unref':
colourscheme.c:(.text+0x2c0): multiple definition of `colour_scheme_unref'; CMakeFiles/rtlib.dir/colourscheme.c.o:colourscheme.c:(.text+0x2c0): first defined here
/nix/store/mgdjnsrkqgmxqjaqaxgqyqm7fwyi96fk-binutils-2.31.1/bin/ld: CMakeFiles/rtlib.dir/colourscheme.c.o: in function `colour_scheme_get_palette':
colourscheme.c:(.text+0x380): multiple definition of `colour_scheme_get_palette'; CMakeFiles/rtlib.dir/colourscheme.c.o:colourscheme.c:(.text+0x380): first defined here
...
collect2: error: ld returned 1 exit status
make[2]: *** [src/CMakeFiles/roxterm.dir/build.make:284: src/roxterm] Error 1
make[1]: *** [CMakeFiles/Makefile2:164: src/CMakeFiles/roxterm.dir/all] Error 2
make: *** [Makefile:130: all] Error 2
builder for '/nix/store/zc1rlqyflyzbm9ra7fxfg8m0nkw48j6y-roxterm-3.7.5.drv' failed with exit code 2
error: build of '/nix/store/zc1rlqyflyzbm9ra7fxfg8m0nkw48j6y-roxterm-3.7.5.drv' failed

There are two suspicious things:

  1. At the end of the configure phase, there are warnings like the following:

    WARNING: Target "roxterm" requests linking to directory "/nix/store/zhzgdnnaf34imjw6cf057fjdvl8nnfa6-gtk+3-3.24.10/lib".  Targets may link only to libraries.  CMake is dropping the item.
    ...
    

    Why would this be happening? Is this cause for concern?

  2. These seem to be the errors that are causing the build to fail. This appears to be happening when finally linking the executables:

    [100%] Linking C executable roxterm
    /nix/store/mgdjnsrkqgmxqjaqaxgqyqm7fwyi96fk-binutils-2.31.1/bin/ld: CMakeFiles/rtlib.dir/colourscheme.c.o: in function `colour_scheme_reset_cached_data':
    colourscheme.c:(.text+0x1f0): multiple definition of `colour_scheme_reset_cached_data'; CMakeFiles/rtlib.dir/colourscheme.c.o:colourscheme.c:(.text+0x1f0): first defined here
    ...
    

    What could be causing cmake to include the same .c file multiple times? Is there any way to stop this?

It doesn’t seem like anyone else has reported this on the roxterm issue tracker. Also, there is already an AUR package for roxterm. So I am thinking this is probably a Nix issue.

You can build the above derivation if you save it to a file called roxterm.nix and run the following command:

$ nix-build -E 'with (import <nixpkgs> {}); callPackage ./roxterm.nix {}'

I tried building it against nixpkgs-unstable. I’m not sure if it will build against nixpkgs-19.03.

I have no idea what’s going on there… I will note that you shouldn’t add to "-DCMAKE_BUILD_TYPE=Release" to cmakeFlags because this should be added by the standard environment.

Have you ever built a certain software from source? I mean within a nix-shell or with any workflow suggested in this rather popular post? I personally use direnv and this version of use_nix but whatever…

The reason I’m asking, is that I think you should try to compile it in a nix-shell with all of the dependencies available in that shell environment.

Then it will be easier to debug this and catch exactly where the errors are coming from. Since it’s a cmake project, I’d try to do the standard mkdir build && cd build && cmake .. && make procedure and see how’s that going.

I’d also use git clone and git checkout ${version} instead of the tar ball so I could make changes on the release tag and use git diff to suggest changes upstream or patch it in our end.

1 Like

@doronbehar Thanks a lot for this post!

I had tried to manually compile roxterm from with nix-shell, and I was getting the same error, so I thought it was a nix problem.

However, trying with the upstream repository was a good idea! I figured out that the latest commit on the repo built correctly, but the released version I was trying to use above didn’t work.

This was the patch that was needed to get the released version building:

https://github.com/realh/roxterm/commit/f7c38fd48bd1810e16d82794bdfb61a9760a2fe1


I was able to get everything working and I sent a PR updating roxterm:

https://github.com/NixOS/nixpkgs/pull/67807

When I got this kind of error, used:

env.NIX_CFLAGS_COMPILE = toString [ "-fcommon" ];

and it solved that issue.