KTX-Software icon indicating copy to clipboard operation
KTX-Software copied to clipboard

Linkage error on Linux Garuda

Open adihodos opened this issue 4 years ago • 7 comments

Building the latest version from master fails on my machine with this linkage error: [ 91%] Building CXX object tools/ktxsc/CMakeFiles/ktxsc.dir/ktxsc.cpp.o [ 91%] Linking CXX executable ktxsc /usr/bin/ld: ../../libktx.a(astc_encode.cpp.o): in function ktxTexture2_CompressAstcEx': astc_encode.cpp:(.text+0x288): undefined reference to astcenc_config_init(astcenc_profile, unsigned int, unsigned int, unsigned int, float, unsigned int, astcenc_config*)' /usr/bin/ld: astc_encode.cpp:(.text+0x2b7): undefined reference to astcenc_context_alloc(astcenc_config const*, unsigned int, astcenc_context**)' /usr/bin/ld: astc_encode.cpp:(.text+0x31d): undefined reference to astcenc_context_free(astcenc_context*)' /usr/bin/ld: astc_encode.cpp:(.text+0x4bb): undefined reference to astcenc_compress_image(astcenc_context*, astcenc_image*, astcenc_swizzle const*, unsigned char*, unsigned long, unsigned int)' /usr/bin/ld: astc_encode.cpp:(.text+0x584): undefined reference to astcenc_compress_reset(astcenc_context*)' /usr/bin/ld: astc_encode.cpp:(.text+0x5d5): undefined reference to astcenc_get_error_string(astcenc_error)' /usr/bin/ld: astc_encode.cpp:(.text+0x6ba): undefined reference to astcenc_context_free(astcenc_context*)' /usr/bin/ld: ../../libktx.a(astc_encode.cpp.o): in function compressionWorkloadRunner(int, int, void*)': astc_encode.cpp:(.text+0x2ccb): undefined reference to astcenc_compress_image(astcenc_context*, astcenc_image*, astcenc_swizzle const*, unsigned char*, unsigned long, unsigned int)' clang-14: error: linker command failed with exit code 1 (use -v to see invocation) make[2]: *** [tools/ktxsc/CMakeFiles/ktxsc.dir/build.make:103: tools/ktxsc/ktxsc] Error 1 make[1]: *** [CMakeFiles/Makefile2:1456: tools/ktxsc/CMakeFiles/ktxsc.dir/all] Error 2 make: *** [Makefile:166: all] Error 2

Configuration used: ╭─adi@B5X64 in repo: KTX-Software/build on  master [!] via C v12.2.0-gcc via △ v3.25.0 took 6ms ╰─λ cmake .. -DKTX_FEATURE_DOC=OFF -DKTX_FEATURE_LOADTEST=OFF -DKTX_FEATURE_STATIC_LIBRARY=ON -DKTX_FEATURE_TESTS=OFF -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ - DCMAKE_BUILD_TYPE=Release ../

Clang/cmake versions used: ` ╭─adi@B5X64 in repo: KTX-Software/build on  master [!] via C v12.2.0-gcc via △ v3.25.0 took 1m37s [🔴] × clang -v clang version 14.0.6 Target: x86_64-pc-linux-gnu Thread model: posix InstalledDir: /usr/bin Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-pc-linux-gnu/11.3.0 Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-pc-linux-gnu/12.2.0 Found candidate GCC installation: /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/11.3.0 Found candidate GCC installation: /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/12.2.0 Selected GCC installation: /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/12.2.0 Candidate multilib: .;@m64 Candidate multilib: 32;@m32 Selected multilib: .;@m64 Found CUDA installation: /opt/cuda, version

╭─adi@B5X64 in repo: KTX-Software/build on  master [!] via C v12.2.0-gcc via △ v3.25.0 took 15ms ╰─λ clang++ -v clang version 14.0.6 Target: x86_64-pc-linux-gnu Thread model: posix InstalledDir: /usr/bin Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-pc-linux-gnu/11.3.0 Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-pc-linux-gnu/12.2.0 Found candidate GCC installation: /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/11.3.0 Found candidate GCC installation: /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/12.2.0 Selected GCC installation: /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/12.2.0 Candidate multilib: .;@m64 Candidate multilib: 32;@m32 Selected multilib: .;@m64 Found CUDA installation: /opt/cuda, version

╭─adi@B5X64 in repo: KTX-Software/build on  master [!] via C v12.2.0-gcc via △ v3.25.0 took 16ms ╰─λ uname -ar Linux B5X64-Linux 6.0.8-zen1-1-zen #1 ZEN SMP PREEMPT_DYNAMIC Thu, 10 Nov 2022 21:14:22 +0000 x86_64 GNU/Linux

╭─adi@B5X64 in repo: KTX-Software/build on  master [!] via C v12.2.0-gcc via △ v3.25.0 took 1ms ╰─λ cmake --version cmake version 3.25.0

CMake suite maintained and supported by Kitware (kitware.com/cmake). `

adihodos avatar Nov 28 '22 14:11 adihodos

It looks like it didn't build the ASTC encoder for some reason. I need to see the output from the CMake config step that shows which version of the encoder was selected. Here is an example of the output you should see:

  AVX2 backend     - ON
  SSE4.1 backend   - OFF
  SSE2 backend     - OFF
  NEON backend     - OFF
  NONE backend     - OFF
  NATIVE backend   - OFF
  Universal bin    - OFF
  Decompressor     - OFF
  No invariance    - OFF
  Diagnostics      - OFF
  ASAN             - OFF
  Unit tests       - OFF

MarkCallow avatar Nov 30 '22 07:11 MarkCallow

This is the output from the configure step. `cmake -DKTX_FEATURE_DOC=OFF -DKTX_FEATURE_LOADTEST=OFF -DKTX_FEATURE_STATIC_LIBRARY=ON -DKTX_FEATURE_TESTS=OFF -DCMAKE_BUILD_TYPE=Release ../ -- Found Bash: /usr/bin/bash
-- The C compiler identification is GNU 12.2.0 -- The CXX compiler identification is GNU 12.2.0 -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working C compiler: /usr/bin/cc - skipped -- Detecting C compile features -- Detecting C compile features - done -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: /usr/bin/c++ - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done -- Looking for CL_VERSION_3_0 -- Looking for CL_VERSION_3_0 - found -- Found OpenCL: /usr/lib/libOpenCL.so (found version "3.0") -- Found Vulkan: /lib/libvulkan.so (found version "1.3.235") found components: glslc glslangValidator -- Found Perl: /usr/bin/perl (found version "5.36.0") -- Performing Test CMAKE_HAVE_LIBC_PTHREAD -- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success -- Found Threads: TRUE
-- AVX2 backend - ON -- SSE4.1 backend - OFF -- SSE2 backend - OFF -- NEON backend - OFF -- NONE backend - OFF -- NATIVE backend - OFF -- Decompressor - OFF -- No invariance - OFF -- Diagnostics - OFF -- ASAN - OFF -- Unit tests - OFF -- Configuring done -- Generating done CMake Warning: Manually-specified variables were not used by the project:

KTX_FEATURE_LOADTEST

-- Build files have been written to: /home/adi/projects/c_plus_plus/KTX-Software/build`

adihodos avatar Nov 30 '22 11:11 adihodos

The build is correctly identifying the ASTC encoder library to build.

You are building a static library. In that case the build combines the ASTC encoder library into libktx so applications only have one target to link to. This is done with libtool. I suspect libtool has changed in Garuda so the combine operation is failing. Here is the current CMakeLists code to add the Post Build command that runs it: https://github.com/KhronosGroup/KTX-Software/blob/7d576397278088ae83af673d9526ce58f63fa0bd/CMakeLists.txt#L834-L846

Look in your build log for any output fromlibtool and see if you can identify the problem.

MarkCallow avatar Dec 04 '22 05:12 MarkCallow

I have a VirtualBox machine with Ubuntu on it and I tried to build it there and it failed with the exact same error as on my workstation. Since I am kinda pressed on time I modified the CMakeLists.txt to build and link ASTC like it does on Windows and the build was successfull.

adihodos avatar Dec 06 '22 10:12 adihodos

Not that it affected my reply but I 'd assumed Garuda was an Ubuntu release. Now that I look I see they skipped over G and H going from F to J. I also see that Garuda is a specific ArchLinux-based distribution.

@06393993 submitted PR #635 to add necessary arguments for GNU libtool saying that is what is typically used on Linux. @adihodos please answer the following questions if want progress made in this issue:

  1. Is the build trying to run libtool?
  2. What happens when the build attempts to run libtool is run? Are you seeing errors?
  3. Which Ubuntu release are you running on Virtual Box?
  4. Ubuntu contains libtool in the package libtool-bin. Is this installed on your Ubuntu/VBox? I don't know if this package is installed by default or not.
  5. The ArchLinux user repo. contains libtool.git Is this included in Garuda?

@06393993 any thoughts?

MarkCallow avatar Dec 07 '22 06:12 MarkCallow

I also encountered with this issue, reproduced both on Ubuntu 22.04 and Arch linux, as a standalone build or vcpkg port. My reproduction:

$ libtool --version         
libtool (GNU libtool) 2.4.7-dirty
Written by Gordon Matzigkeit, 1996

Copyright (C) 2014 Free Software Foundation, Inc.

$ cmake .. -DKTX_FEATURE_STATIC_LIBRARY=ON -DKTX_FEATURE_TESTS=OFF -DCMAKE_BUILD_TYPE=Release && make VERBOSE=1
...
libtool --mode=link --tag=CC cc -static -o /home/sergei/Projects/KTX-Software/build/libktx.a /home/sergei/Projects/KTX-Software/build/libktx.a /home/sergei/Projects/KTX-Software/build/lib/astc-encoder/Source/libastcenc-avx2-static.a
libtool: link: ar cr /home/sergei/Projects/KTX-Software/build/libktx.a /home/sergei/Projects/KTX-Software/build/libktx.a /home/sergei/Projects/KTX-Software/build/lib/astc-encoder/Source/libastcenc-avx2-static.a 
libtool: link: ranlib /home/sergei/Projects/KTX-Software/build/libktx.a
...
/usr/bin/ld: ../../libktx.a(astc_encode.cpp.o): in function «compressionWorkloadRunner(int, int, void*)»:
astc_encode.cpp:(.text+0x3b): undefined reference to «astcenc_compress_image(astcenc_context*, astcenc_image*, astcenc_swizzle const*, unsigned char*, unsigned long, unsigned int)»
...

So there is no explicit errors after libtool command, however, astcenc_* symbols are actually undefined in libktx.a:

$ nm libktx.a --demangle | grep astcenc 
                 U astcenc_config_init(astcenc_profile, unsigned int, unsigned int, unsigned int, float, unsigned int, astcenc_config*)
                 U astcenc_context_free(astcenc_context*)
                 U astcenc_context_alloc(astcenc_config const*, unsigned int, astcenc_context**)
                 U astcenc_compress_image(astcenc_context*, astcenc_image*, astcenc_swizzle const*, unsigned char*, unsigned long, unsigned int)
                 U astcenc_compress_reset(astcenc_context*)
                 U astcenc_get_error_string(astcenc_error)
nm: libktx.a: File format not recognized
nm: libastcenc-avx2-static.a: File format not recognized

And there are also interesting remarks about unrecognized file format of libktx.a, libastcenc-avx2-static.a. I've found investigation of the similar problem: https://stackoverflow.com/questions/11344547/how-do-i-compile-a-static-library/16070483#16070483, and my current understanding of this is following:

There are two different tools - libtool from apple's binutils and GNU libtool on linux (that is called glibtool on mac), they have different CLI and work differently. For apple's libtool, command libtool -static -o libktx.a libktx.a libastcenc-avx2-static.a actually produces combined static library, but GNU libtool has special semantics if output file extension is .a or .lib:

$ libtool --mode=link --help
...
If OUTPUT-FILE ends in '.a' or '.lib', then a standard library is created
using 'ar' and 'ranlib', or on Windows using 'lib'.

So it just pushes .a archives into output file, not corresponding .o files -- to do this, we should manually unpack object files with ar tool and then make static library from them using ar and ranlib, but I'm not sure if it's worth doing or we can just link them like for Windows platform. It looks like #635 has fixed command line interface mismatch between GNU and Apple libtool, but astcenc_* symbols still were not resolved, and problem is manifested when we try to build ktxsc tool.

kachkov98 avatar Jan 04 '23 15:01 kachkov98

Closed by PR #664.

MarkCallow avatar Jan 09 '23 07:01 MarkCallow