educelab / vc-deps

CMake project for building Volume Cartographer dependencies from source
GNU Affero General Public License v3.0
1 stars 0 forks source link

Link error building VC #9

Closed spelufo closed 6 months ago

spelufo commented 6 months ago

After managing to build vc-deps, building vc fails to link. It looks like libtiff wants libdeflate and isn't being linked against it.

...
[ 65%] Built target vc_projection
[ 65%] Built target VC_autogen_timestamp_deps
[ 65%] Built target VC_autogen
[ 66%] Linking CXX executable ../../bin/VC
/usr/bin/ld: volume-cartographer/vc-deps/deps/lib/libtiff.a(tif_zip.c.o): in function `ZIPCleanup':
tif_zip.c:(.text+0xe4): undefined reference to `libdeflate_free_decompressor'
/usr/bin/ld: tif_zip.c:(.text+0xf5): undefined reference to `libdeflate_free_compressor'
/usr/bin/ld: volume-cartographer/vc-deps/deps/lib/libtiff.a(tif_zip.c.o): in function `ZIPEncode':
tif_zip.c:(.text+0x2be): undefined reference to `libdeflate_zlib_compress_bound'
/usr/bin/ld: tif_zip.c:(.text+0x2f3): undefined reference to `libdeflate_zlib_compress'
/usr/bin/ld: tif_zip.c:(.text+0x388): undefined reference to `libdeflate_alloc_compressor'
/usr/bin/ld: volume-cartographer/vc-deps/deps/lib/libtiff.a(tif_zip.c.o): in function `ZIPDecode':
tif_zip.c:(.text+0x78d): undefined reference to `libdeflate_zlib_decompress'
/usr/bin/ld: tif_zip.c:(.text+0x8ce): undefined reference to `libdeflate_alloc_decompressor'
/usr/bin/ld: volume-cartographer/vc-deps/deps/lib/libtiff.a(tif_zip.c.o): in function `ZIPVSetField':
tif_zip.c:(.text+0xad4): undefined reference to `libdeflate_free_compressor'
collect2: error: ld returned 1 exit status
make[2]: *** [apps/VC/CMakeFiles/VC.dir/build.make:352: bin/VC] Error 1
make[1]: *** [CMakeFiles/Makefile2:2472: apps/VC/CMakeFiles/VC.dir/all] Error 2
make: *** [Makefile:156: all] Error 2
csparker247 commented 6 months ago

vc-deps behavior is extremely environment specific, particularly for things that are often packaged with the system like Zip/Deflate and LZW. Some projects (e.g. VTK) will pick up extra libs in the environment automatically and add linkage transitively in a way which breaks our builds. On macOS, for example, I brew unlink pretty much everything but cmake and qt before I try to build vc-deps. So one thing to consider is what your system environment is like and what you can temporarily disable. What OS are you building on?

You can try adding -Dzlib=OFF or -Dzip=OFF (I can't remember the specific flag) to the libtiff cmake building file here and see if it helps: https://github.com/educelab/vc-deps/blob/develop/cmake%2FBuildTIFF.cmake

You'll probably have to clear the build and deps directories so cmake doesn't cache anything.

csparker247 commented 6 months ago

If Debian/Ubuntu, if might also be useful to look at the base Dockerfile in ci-docker: https://github.com/educelab/ci-docker/tree/main

spelufo commented 6 months ago

I'm on Archlinux. I've managed to build VC now. Here's what I did:


# Install VC's dependencies, except ITK and ACVD. Those we build ourselves. We
# could also build others but I'd rather spare the build times and debugging.
# Specially VTK, which is big and takes a long time to build.
 $ sudo pacman -Syu cmake opencv-cuda vtk libtiff eigen spdlog boost boost-libs qt6 doxygen nlohmann-json

# Install the [build time dependencies](https://gitlab.archlinux.org/archlinux/packaging/packages/vtk/-/blob/main/PKGBUILD?ref_type=heads#L24-82)
# of arch's build of VTK. When building VC against the system's VTK through
# cmake's find_package, the build will fail because VTK's cmake scripts in
# /usr/lib/cmake/vtk require all of these dependencies.
# VC probably doesn't need them all but the vtk scripts assume they are required.
# Perhaps VC's cmake script should specify only the required components from VTK, if that's possible.
 $ sudo pacman -Syu adios2 cgns cli11 expat fast_float ffmpeg fmt freetype2 gdal git gl2ps glew hdf5 jsoncpp libharu libjpeg-turbo liblas libogg libpng libtheora libxml2 libxt lz4 netcdf opencascade openimagedenoise openmpi openvdb openvr openxr ospray pdal postgresql-libs proj python-mpi4py qt5-base qt5-declarative sqlite tk unixodbc utf8cpp verdict wget xz zfp zlib

# Configure and build vc-deps.
 $ cd vc-deps
 $ rm -rf build && cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -GNinja -DVCDEPS_BUILD_BOOST=off -DVCDEPS_BUILD_EIGEN=off -DVCDEPS_BUILD_OPENCV=off -DVCDEPS_BUILD_SPDLOG=off -DVCDEPS_BUILD_TIFF=off -DVCDEPS_BUILD_VTK=off -DVCDEPS_BUILD_ZLIB=off
 $ cmake --build build
# This will give a couple of compilation errors introduced by GCC 13 (https://gcc.gnu.org/gcc-13/porting_to.html), which I fixed by adding `#include <cstdint>` in a
# couple of places in the ITK source code.
# There's also an error from a call to a function that changed to pass by pointer between VTK versions.
# I did both fixes inside the build directory and rerun `cmake --build build`
# after each until there were no more errors.

 $ cd ..
 $ rm -rf build && cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DVC_PREBUILT_LIBS=ON -DVC_BUILD_JSON=off -DSMGL_BUILD_JSON=off
 $ cmake --build build
# Again there are a couple of GCC 13 / `#include <cstdint>` error to fix and
# rerun `cmake --build build`. After that, the build succeeded.

 $ ./build/bin/vc_version 
volume-cartographer 2.25.0 (65390bd4c68bbfb1392ac6b34a373acf61542d5a)
 $ ./build/bin/VC
csparker247 commented 6 months ago

Glad you got it working. I'm betting the ITK build issue will be fixed with #8. What's the deal with VTK? We might need to upgrade the VTK ref in this repo to take care of that.

All of the cstdint issues in VC should be fixed by this PR. Are you building the main repo or your fork?

spelufo commented 6 months ago

That was my fork, yes. I've just tried building with the same commands the latest commit from the develop branch in the educelab repo, and pointing the submodule to vc-deps/7-fix-itk-gcc13 and it built without any manual patching, so the upgrades solve all the issues I had encountered. Thanks.