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.