Compile program in GNU GuixSD with cmake

cmakedynamic-linkingguixguixsdld

I am trying to compile Xash3D on GuixSD v1.0.0 and gcc 8.3.0.

As is shown below, ld (GNU Linker) is giving me errors, that ctr1.o and ctri.o are missing. These files exist elsewhere under multiple directories, within /gnu/store/{specificProgramName}, however, I surprisingly wasn't able to make a symbolic link to ~/.guix_profile, where other libraries sit, even with root access. There are multiple versions of them with different sizes so I would assume that they are only compatible with their respective programs. Furthermore. ~/.guix_profile seems to emulate the root directory of a Unix system, however in GuixSD /usr is missing from both the root directory, and ~/.guix_profile, so I would not know where to link the c objects even if I had the actual files.

In essence, ld cannot find crt1.o, crti.o, and libgcc_s.so, and it is quite possible that just like before, after linking or installing these 2 c objects and libgcc, cmake will halt with yet a further error regarding other other dependencies.

Anyways, here is what is printed/logged by the following command (which is instructed as the recommended way of installing Xash3D)

sudo cmake -DHL_SDK_DIR=../hlsdk -DXASH_SDL=yes -DXASH_VGUI=yes -DCMAKE_C_FLAGS="-m32" -DCMAKE_CXX_FLAGS="-m32" -DCMAKE_EXE_LINKER_FLAGS="-m32" ../ && sudo make
-- The C compiler identification is GNU 9.1.0
-- The CXX compiler identification is GNU 9.1.0
-- Check for working C compiler: /home/nick/.guix-profile/bin/gcc
-- Check for working C compiler: /home/nick/.guix-profile/bin/gcc -- broken
CMake Error at /gnu/store/nrsbv2df55abwji1gsb1ilf22n3rc1xa-cmake-3.13.1/share/cmake-3.13/Modules/CMakeTestCCompiler.cmake:52 (message):
  The C compiler

    "/home/nick/.guix-profile/bin/gcc"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /home/nick/xash3d/build/CMakeFiles/CMakeTmp
    Run Build Command:"/home/nick/.guix-profile/bin/make" "cmTC_7635d/fast"
    /home/nick/.guix-profile/bin/make -f CMakeFiles/cmTC_7635d.dir/build.make CMakeFiles/cmTC_7635d.dir/build
    make[1]: Entering directory '/home/nick/xash3d/build/CMakeFiles/CMakeTmp'
    Building C object CMakeFiles/cmTC_7635d.dir/testCCompiler.c.o
    /home/nick/.guix-profile/bin/gcc   -m32    -o CMakeFiles/cmTC_7635d.dir/testCCompiler.c.o   -c /home/nick/xash3d/build/CMakeFiles/CMakeTmp/testCCompiler.c
    Linking C executable cmTC_7635d
    /gnu/store/nrsbv2df55abwji1gsb1ilf22n3rc1xa-cmake-3.13.1/bin/cmake -E cmake_link_script CMakeFiles/cmTC_7635d.dir/link.txt --verbose=1
    /home/nick/.guix-profile/bin/gcc -m32     -rdynamic CMakeFiles/cmTC_7635d.dir/testCCompiler.c.o  -o cmTC_7635d 
    /home/nick/.guix-profile/bin/ld: cannot find crt1.o: No such file or directory
    /home/nick/.guix-profile/bin/ld: cannot find crti.o: No such file or directory
    /home/nick/.guix-profile/bin/ld: skipping incompatible /gnu/store/69x60a1pn0mf5jv68al8awjfkyp1miwi-gcc-8.3.0-lib/lib/gcc/x86_64-unknown-linux-gnu/8.3.0/libgcc.a when searching for -lgcc
    /home/nick/.guix-profile/bin/ld: cannot find -lgcc
    /home/nick/.guix-profile/bin/ld: skipping incompatible /gnu/store/69x60a1pn0mf5jv68al8awjfkyp1miwi-gcc-8.3.0-lib/lib/gcc/x86_64-unknown-linux-gnu/8.3.0/../../../libgcc_s.so.1 when searching for libgcc_s.so.1
    /home/nick/.guix-profile/bin/ld: cannot find libgcc_s.so.1
    /home/nick/.guix-profile/bin/ld: skipping incompatible /gnu/store/69x60a1pn0mf5jv68al8awjfkyp1miwi-gcc-8.3.0-lib/lib/gcc/x86_64-unknown-linux-gnu/8.3.0/libgcc.a when searching for -lgcc
    /home/nick/.guix-profile/bin/ld: cannot find -lgcc
    collect2: error: ld returned 1 exit status
    make[1]: *** [CMakeFiles/cmTC_7635d.dir/build.make:87: cmTC_7635d] Error 1
    make[1]: Leaving directory '/home/nick/xash3d/build/CMakeFiles/CMakeTmp'
    make: *** [Makefile:121: cmTC_7635d/fast] Error 2

Much like Debian, Guix has a bash command for package installation: "guix install $PACKAGE" however its library of ~10,000 does not include one with the name 'gcc-multilib' which would have fixed the problem in Debian. Perhaps there is an alternative package that includes this and other libraries?

I am looking for a solution that does not involve using Wine. Solving the libgcc problem alone might not be sufficient, so in order to arrive at a genuine solution, I will be trying any advice left in the comments (there is no danger to me, the OS is installed in an isolated environment on a USB key).

Here is what my $PATH looks like:

/gnu/store/hk4f641r18vpj44m42pny6rp1nwg3d4w-glib-2.56.3-bin/bin
/run/setuid-programs
/home/nick/.config/guix/current/bin
/home/nick/.guix-profile/bin
/home/nick/.guix-profile/sbin
/run/current-system/profile/bin
/run/current-system/profile/sbin

The two packages that should be installed are named gcc-multilib and libc-dev in Debian-based OS's. These packages (or their elements) should exist somewhere in the Guix library of packages, but under different name(s).

I have tried binding various paths for LIBRARY_PATH in the shell, including:

$HOME/.guix-profile/lib
$HOME/.guix-profile/lib/gcc/x86_64-unknown-linux-gnu/4.8.2
## Containing many c object/shared object and header files
/gnu/store/aqv6njg05w2yqh8krgrjy0wcbfxb4nn3-gcc-toolchain-9.1.0/lib/crt1.o
## Containing crt1.o and crti.o

Best Answer

Write a package. This is a rough outline, and it needs improvement:

(define-module (gnu packages xash3d)
  #:use-module (guix packages)
  #:use-module (guix git-download)
  #:use-module (guix utils)
  #:use-module (guix build-system cmake)
  #:use-module ((guix licenses) #:select (gpl3))
  #:use-module (gnu packages))

(define-public xash3d
  (package
    (name "xash3d")
    (version "0.19.2")
    (let (commit (string-append "v" version))
          (revision "1")) 
    (source (origin
              (method git-fetch)
              (uri (git-reference
                   (url (string-append "https://github.com/FWGS/" name "/"))
                   (commit commit)))))
    (build-system cmake-build-system)
    (synopsis "Xash3D FWGS Engine.")
    (description "Xash3D Engine is a custom Gold Source engine rewritten from scratch.")
    (home-page "https://xash.su/")
    (license gpl3)))

Resource: https://www.gnu.org/software/guix/manual/en/html_node/Defining-Packages.html

Related Question