2

I am linking against the flatbuffers library in my c++ project with cmake. My CMakeLists.txt looks like:

set(FLATBUFFERS_SRC_DIR /root/src/git/flatbuffers)
set(FLATBUFFERS_BUILD_TESTS "Off")

add_subdirectory(${FLATBUFFERS_SRC_DIR}
        ${CMAKE_CURRENT_BINARY_DIR}/flatbuffers-build
        EXCLUDE_FROM_ALL)

  target_link_libraries(MyApp
          flatbuffers
          )

I am doing it by the book. https://google.github.io/flatbuffers/flatbuffers_guide_building.html

This worked fine on centos7 but on 8 I get an error:

Linking CXX static library libflatbuffers.a
Error running link command: No such file or directory

Im using this in a podman container:

FROM centos:8

USER root

RUN dnf -y --disablerepo '*' --enablerepo=extras swap centos-linux-repos centos-stream-repos
RUN dnf -y distro-sync

RUN yum update -y

# git and python3 for cmake
RUN yum install -y \
    git  \
    python3 \
    wget

RUN yum groupinstall -y "Development Tools"

# Install
RUN yum install -y gcc-toolset-11
RUN echo "source /opt/rh/gcc-toolset-11/enable" >> /etc/bashrc

## Install cmake
RUN yum install -y openssl-devel
RUN wget https://cmake.org/files/v3.24/cmake-3.24.0.tar.gz
RUN tar zxvf cmake-3.* && \
    cd cmake-3.24.0 && \
    ./bootstrap --prefix=/usr/local && \
    make -j$(nproc) && \
    make install

WORKDIR /app

With build command:

cd ~/src
podman run -it  \
 -e CC=/opt/rh/gcc-toolset-11/root/usr/bin/cc \
 -e CXX=/opt/rh/gcc-toolset-11/root/usr/bin/g++ \
 -v $(pwd)/myapp/MyApp:/app \
 -v $(pwd)/git/flatbuffers:/root/src/git/flatbuffers \
  myapp /bin/bash -c "cmake /app; cmake --build /app"

After running make VERBOSE=1 I see some output that indicates cmake is using devtoolset-7 when it should be using 11. Will try to debug that further.

[ 14%] Linking CXX static library libflatbuffers.a

cd /app/MyApp/flatbuffers-build && /usr/local/bin/cmake -P CMakeFiles/flatbuffers.dir/cmake_clean_target.cmake

cd /app/MyApp/flatbuffers-build && /usr/local/bin/cmake -E cmake_link_script CMakeFiles/flatbuffers.dir/link.txt --verbose=1

/opt/rh/devtoolset-7/root/usr/bin/ar qc libflatbuffers.a CMakeFiles/flatbuffers.dir/src/idl_parser.cpp.o CMakeFiles/flatbuffers.dir/src/idl_gen_text.cpp.o CMakeFiles/flatbuffers.dir/src/reflection.cpp.o CMakeFiles/flatbuffers.dir/src/util.cpp.o
Error running link command: No such file or directory

make[2]: *** [MyApp/flatbuffers-build/CMakeFiles/flatbuffers.dir/build.make:146: MyApp/flatbuffers-build/libflatbuffers.a] Error 2

Strange that the directory doesn't exist: ls: cannot access '/opt/rh/devtoolset-7': No such file or directory

Im not sure if this is related to the main problem or not.

BAR
  • 15,909
  • 27
  • 97
  • 185
  • I just tried your code verbatim at the latest version on github, and it worked fine. The only thing I had to do was `cmake -G "whatever" -DFLATBUFFERS_BUILD_TESTS=Off` since there was a problem with copying symlink files (shouldn't be related to your issue though). Can you provide any more error output? What version of CMake? – Moop Sep 10 '22 at 07:09
  • Build the project with `make VERBBOSE=1` and inspect the linker command line which fails. Most likely is is about `CMAKE_AR-NOTFOUND`, like in [that bugreport](https://github.com/opencv/opencv/issues/7594). – Tsyvarev Sep 10 '22 at 11:07
  • @Moop cmake version 3.24.0. I updated the post with a Dockerfile, maybe its related to volume mounting the library? But I doubt it. – BAR Sep 10 '22 at 20:09
  • @Tsyvarev Output is at bottom. Might be getting closer. – BAR Sep 10 '22 at 20:11
  • Looks like your environment is configured for use compiler tools from `/opt/rh/devtoolset-7`. You overwrite CC and CXX variables for use C and C++ compilers from `/opt/rh/gcc-toolset-11`, but other tools (`ar` in your case) are still taked from `/opt/rh/devtoolset-7`. You could specify path to `ar` tool via `CMAKE_AR` CMake variable. – Tsyvarev Sep 15 '22 at 08:03
  • I'm talking through my hat here (no experience with centos/rh-linux) so what I say could very well be completely irrelevant, but maybe reading through these other threads you could learn something useful?: [CMakeFindBinUtils discussion](https://gitlab.kitware.com/cmake/cmake/-/issues/18087#note_422289), [mailing list with similar sounding topic](https://cmake.org/pipermail/cmake/2015-July/061210.html). If this isn't relevant let me know and I'll delete this comment. – starball Sep 16 '22 at 00:46

1 Answers1

-2

From the description you mention in question and error snippet provided, it seems issue is, you are using dirty build directory. In other word you are using same build directory for centos7 and centos8, and that is on your host os. Changing your build command as below will definitely helps. But before that make sure your should code directory on host os is clean(i.e. no file generated by cmake should be present)

For centos 7

/bin/bash -c "cmake -S /app -B /app/centos7build/; cmake --build /app/centos7build/"

For centos 8

/bin/bash -c "cmake -S /app -B /app/centos8build/; cmake --build /app/centos8build/"

Manthan Tilva
  • 3,135
  • 2
  • 17
  • 41