DrTimothyAldenDavis / SuiteSparse

The official SuiteSparse library: a suite of sparse matrix algorithms authored or co-authored by Tim Davis, Texas A&M University.
https://people.engr.tamu.edu/davis/suitesparse.html
Other
1.15k stars 259 forks source link

undefined reference to `GB_JITpackage_nfiles` #729

Closed jschueller closed 7 months ago

jschueller commented 8 months ago

Describe the bug graphblas fails to link when cross-compiling, it seems some native target generating that source file is not triggered: https://github.com/DrTimothyAldenDavis/SuiteSparse/blob/dev/GraphBLAS/JITpackage/CMakeLists.txt#L68

To Reproduce use mingw from linux

Expected behavior links succeeds

Screenshots

[ 95%] Linking C shared library libgraphblas.dll
/usr/lib/gcc/i686-w64-mingw32/13.2.1/../../../../i686-w64-mingw32/bin/ld: CMakeFiles/GraphBLAS.dir/objects.a(GB_jitifyer.c.obj):GB_jitifyer.c:(.text+0x218e): undefined reference to `GB_JITpackage_nfiles'
/usr/lib/gcc/i686-w64-mingw32/13.2.1/../../../../i686-w64-mingw32/bin/ld: CMakeFiles/GraphBLAS.dir/objects.a(GB_jitifyer.c.obj):GB_jitifyer.c:(.text+0x21a7): undefined reference to `GB_JITpackage_index'
/usr/lib/gcc/i686-w64-mingw32/13.2.1/../../../../i686-w64-mingw32/bin/ld: CMakeFiles/GraphBLAS.dir/objects.a(GB_jitifyer.c.obj):GB_jitifyer.c:(.text+0x21d4): undefined reference to `GB_JITpackage_nfiles'
/usr/lib/gcc/i686-w64-mingw32/13.2.1/../../../../i686-w64-mingw32/bin/ld: CMakeFiles/GraphBLAS.dir/objects.a(GB_jitifyer.c.obj):GB_jitifyer.c:(.text+0x21e5): undefined reference to `GB_JITpackage_index'
/usr/lib/gcc/i686-w64-mingw32/13.2.1/../../../../i686-w64-mingw32/bin/ld: CMakeFiles/GraphBLAS.dir/objects.a(GB_jitifyer.c.obj):GB_jitifyer.c:(.text+0x2279): undefined reference to `GB_JITpackage_nfiles'
collect2: error: ld returned 1 exit status

Desktop (please complete the following information):

Additional context configuring with cmake -DSUITESPARSE_DEMOS=OFF -DBUILD_TESTING=OFF -DBLA_VENDOR=Generic ..., make install

succeeds if I disable jit: cmake -DGRAPHBLAS_USE_JIT=OFF

/cc @mmuetzel

mmuetzel commented 8 months ago

Hmmm... Another wild guess: To check if it is any of the flags added in x86_64-w64-mingw32-cmake, does replacing /usr/bin/x86_64-w64-mingw32-cmake with cmake -DCMAKE_TOOLCHAIN_FILE=/usr/share/mingw/toolchain-x86_64-w64-mingw32.cmake -DCMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES:PATH=/usr/x86_64-w64-mingw32/include make a difference?

That's based on the file found here: https://aur.archlinux.org/cgit/aur.git/tree/mingw-cmake.sh?h=mingw-w64-cmake

jschueller commented 8 months ago

I can even configure directly with: cmake -DCMAKE_TOOLCHAIN_FILE=/usr/share/mingw/toolchain-x86_64-w64-mingw32.cmake . but the error is the same

mmuetzel commented 8 months ago

Does it work if you "fake" a cross-compilation? I.e., something like (no actual cross-compilers involved):

cmake -DCMAKE_SYSTEM_NAME="Linux" .
make GB_JITpackage
jschueller commented 8 months ago

this one works

mmuetzel commented 8 months ago

Ok. Another wild guess: Could that be a consequence of set (CMAKE_FIND_ROOT_PATH /usr/@TRIPLE@) in combination with set (CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) in the toolchain file? Does it work if you comment out the latter line in the toolchain file?

jschueller commented 8 months ago

oh yes that's totally it

mmuetzel commented 8 months ago

Nice.

I kind of understand why the ArchLinux packagers chose to add that line to their toolchain file. But I'm not sure if it's a good idea to set the CMAKE_FIND_ROOT_PATH_MODE_* variables to ONLY for everyone...

jschueller commented 8 months ago

I guess it can be useful not to pick config files from the host environment when not available in the target environment

mmuetzel commented 8 months ago

Might also be an issue in CMake. Reading the documentation doesn't immediately tell that PATHS hints are ignored when it it set to ONLY: https://cmake.org/cmake/help/latest/variable/CMAKE_FIND_ROOT_PATH_MODE_PACKAGE.html

Maybe, report upstream?

As a workaround it might be possible to override that flag from the toolchain file with -DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=BOTH in the configure flags?

jschueller commented 8 months ago

on the other end it says that ONLY_CMAKE_FIND_ROOT_PATH only search in CMAKE_STAGING_PREFIX but I guess thats a typo and they meant CMAKE_FIND_ROOT_PATH, so its consistent with what we're seeing

mmuetzel commented 8 months ago

The documentation also says: https://cmake.org/cmake/help/latest/command/find_package.html#command:find_package

The default behavior can be adjusted by setting CMAKE_FIND_ROOT_PATH_MODE_PACKAGE. This behavior can be manually overridden on a per-call basis using options:

CMAKE_FIND_ROOT_PATH_BOTH Search in the order described above.

NO_CMAKE_FIND_ROOT_PATH Do not use the CMAKE_FIND_ROOT_PATH variable.

ONLY_CMAKE_FIND_ROOT_PATH Search only the re-rooted directories and directories below CMAKE_STAGING_PREFIX.

And then:

If NO_DEFAULTPATH is specified all NO* options are enabled.

So, iiuc, whatever value CMAKE_FIND_ROOT_PATH_MODE_PACKAGE has, it should not apply for that find_package command...

jschueller commented 7 months ago

i dont understand, could you maybe open a bug at cmake repo ?

DrTimothyAldenDavis commented 7 months ago

Is this fixed now, except for perhaps a bug in cmake itself?

jschueller commented 7 months ago

yes, maybe it could be worth to be reported at cmake to see if its a bug from their side