Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem building MeshIO in Ubuntu docker #9

Closed
mh-9 opened this issue Jun 14, 2024 · 11 comments
Closed

Problem building MeshIO in Ubuntu docker #9

mh-9 opened this issue Jun 14, 2024 · 11 comments
Labels
Linux This is a Linux-only issue unconfirmed An unconfirmed bug

Comments

@mh-9
Copy link

mh-9 commented Jun 14, 2024

Describe the bug
I'm wanting to use CloudCompare with your MeshIO plugin inside of a docker container.
So far I managed to build CloudCompare and run some of its functions in a ubuntu:focal container.
When I try to enable the MeshIO plugin in ubuntu:focal I get the following message:
"CMake Error at plugins/private/MeshIO/extern/assimp/CMakeLists.txt:41 (CMAKE_MINIMUM_REQUIRED):
CMake 3.22 or higher is required. You are running version 3.16.3"
Then I tried to build everything with cmake 3.22.0 built from scratch. Again CloudCompare works without the MeshIO plugin enabled, but running with the plugin gives me the following message:
"/CloudCompare/plugins/private/MeshIO/src/mioUtils.cpp: In function 'void {anonymous}::_assignMaterialProperties(aiMaterial*, ccMaterial::Shared&)':
/CloudCompare/plugins/private/MeshIO/src/mioUtils.cpp:131:29: error: 'clamp' is not a member of 'std'
property = std::clamp( property, 0.0f, 128.0f );"

After a bit of googling I found out that std:clamp was added with C++ 17.

So I tried to set the C++ version to C++ 17, by using the following commands on the CMakeLists.txt of CloudCompare and the MeshIO plugin:
"sed -i '1i set(CMAKE_CXX_STANDARD 17)\nset(CMAKE_CXX_STANDARD_REQUIRED ON)\nset(CMAKE_CXX_EXTENSIONS OFF)' CMakeLists.txt"

Now I get the following error:
"/usr/bin/ld: /usr/lib/x86_64-linux-gnu/libz.a(deflate.o): relocation R_X86_64_PC32 against symbol `z_errmsg' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: bad value"

But I'm getting the fealing that I'm following the wrong lead, so my main question is the following:
How am I suppossed to build the MeshIO plugin in ubuntu?
Should I use a different linux distribution?
Or did I make another mistake?

How To Reproduce
I'm running the following Dockerfile:

FROM ubuntu:focal
RUN apt-get update
RUN apt-get install -y build-essential
RUN apt-get install -y git
RUN apt-get install -y libgl1-mesa-dev
RUN apt-get install -y libgl1-mesa-glx
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y qt5-default
RUN apt-get install -y qtbase5-dev
RUN apt-get install -y qtchooser
RUN apt-get install -y qt5-qmake
RUN apt-get install -y qtbase5-dev-tools
RUN apt-get install -y qttools5-dev
RUN apt-get install -y qttools5-dev-tools
RUN apt-get install -y libqt5svg5-dev
RUN apt-get install -y libqt5opengl5-dev
RUN apt-get install -y libqt5websockets5-dev
RUN apt-get install -y libxcb-xinerama0
RUN apt-get install -y xvfb
RUN apt-get install -y dbus-x11
RUN apt-get install -y libxerces-c-dev
RUN apt-get install -y zlib1g-dev
RUN apt-get install -y wget
RUN apt-get install -y libssl-dev
RUN rm -rf /var/lib/apt/lists/*

COPY ./data/input ./data

RUN git clone --recursive https://github.com/cloudcompare/CloudCompare.git
WORKDIR /CloudCompare/plugins
RUN mkdir private
WORKDIR /CloudCompare/plugins/private
RUN git clone --recursive https://github.com/asmaloney/MeshIO.git

WORKDIR /
RUN git clone --recursive --depth 1 --branch v3.22.0 https://github.com/Kitware/CMake.git
WORKDIR /CMake
RUN ./bootstrap
RUN make
RUN make install

RUN sed -i '1i set(CMAKE_CXX_STANDARD 17)\nset(CMAKE_CXX_STANDARD_REQUIRED ON)\nset(CMAKE_CXX_EXTENSIONS OFF)' /CloudCompare/CMakeLists.txt
RUN sed -i '1i set(CMAKE_CXX_STANDARD 17)\nset(CMAKE_CXX_STANDARD_REQUIRED ON)\nset(CMAKE_CXX_EXTENSIONS OFF)' /CloudCompare/plugins/private/MeshIO/CMakeLists.txt

WORKDIR /CloudCompare
RUN mkdir build
WORKDIR /CloudCompare/build
RUN cmake -DPLUGIN_IO_QE57=ON -DPLUGIN-3rdParty_MESH_IO=ON ..
RUN cmake --build .
RUN cmake --install .

ENV QT_QPA_PLATFORM offscreen
ENV XDG_RUNTIME_DIR /tmp/runtime-cloud9
ENV QT_DEBUG_PLUGINS 1

COPY /docker/entrypoint.sh /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]

The /data folder simply contains files of different formats, .ply .e57 .ifc .bin etc.
The entrypoint.sh script has the following content:

#!/bin/bash

mkdir -p /tmp/runtime-test
chmod 0700 /tmp/runtime-test
xvfb-run -a --server-args="-screen 0 1024x768x24" CloudCompare -SILENT -c_export_fmt e57 -o /data/input/<file>.e57 -o /data/input/<file>.bin -c2m_dist

Expected behavior
As far as I understand I followed the build instructions for CloudCompare and MeshIO so I would expect it to build properly.

Additional context
I'm also using the e57_plugin as can be seen in the Dockerfile.

Your Environment

  • CloudCompare version (git hash/tag): used the master branch at the following commit: a8a93f0
  • OS & Version: Docker container of Ubuntu focal
  • Qt Version: 5
@mh-9 mh-9 added the unconfirmed An unconfirmed bug label Jun 14, 2024
@asmaloney
Copy link
Owner

Thanks for the good report.

(Clearly I've never built it on Linux.)

  1. I will add CMAKE_MINIMUM_REQUIRED to this plugin so at least the error points here rather than at assimp. I will also add it to the README.
  2. I will make sure the plugin uses C++17 (assimp already does) & add the requirement to the README.
  3. -fPIC I'm not 100% sure about since that's mainly a Linux thing, but I can try something to fix this.

asmaloney added a commit that referenced this issue Jun 14, 2024
This just means that instead of getting an error related to assimp, you'll get one related to this plugin which should be clearer.

Part of #9
asmaloney added a commit that referenced this issue Jun 14, 2024
We use std::clamp which is a C++17 function.

Part of #9
asmaloney added a commit that referenced this issue Jun 14, 2024
This is an attempt to fix a Linux build problem.

Also turns on interprocedural optimization in release mode.

Part of #9
@asmaloney
Copy link
Owner

Those commits should handle (1) & (2) and attempt to handle (3) (assuming it's coming from MeshIO)...

@asmaloney asmaloney added the Linux This is a Linux-only issue label Jun 14, 2024
@mh-9
Copy link
Author

mh-9 commented Jun 18, 2024

Thank you very much for your quick reply and your fast fixes.
I built everything again, using the newest version of the MeshIO plugin.
As you mentioned (1) & (2) work now, but (3) still remains a problem.
I get the exact same error message with "-fPIC" as before.

@asmaloney
Copy link
Owner

Can you give more context around that "relocation R_X86_64_PC32" error? It doesn't tell us what's being linked. Probably something to do with the assimp lib.

@mh-9
Copy link
Author

mh-9 commented Jun 18, 2024

Yes sure, here is an excerpt of the stacktrace:

412.8 [ 61%] Linking CXX static library ../lib/libassimp.a
413.3 [ 61%] Built target assimp
413.4 [ 61%] Automatic MOC and UIC for target MeshIO
413.6 [ 61%] Built target MeshIO_autogen
413.6 [ 62%] Automatic RCC for MeshIO.qrc
413.6 [ 62%] Building CXX object plugins/private/MeshIO/CMakeFiles/MeshIO.dir/MeshIO_autogen/mocs_compilation.cpp.o        
415.1 [ 62%] Building CXX object plugins/private/MeshIO/CMakeFiles/MeshIO.dir/src/COLLADA.cpp.o
416.4 [ 62%] Building CXX object plugins/private/MeshIO/CMakeFiles/MeshIO.dir/src/glTF.cpp.o
417.7 [ 62%] Building CXX object plugins/private/MeshIO/CMakeFiles/MeshIO.dir/src/IFC.cpp.o
419.1 [ 63%] Building CXX object plugins/private/MeshIO/CMakeFiles/MeshIO.dir/src/MeshIO.cpp.o
420.5 [ 63%] Building CXX object plugins/private/MeshIO/CMakeFiles/MeshIO.dir/src/mioAbstractLoader.cpp.o
422.3 [ 63%] Building CXX object plugins/private/MeshIO/CMakeFiles/MeshIO.dir/src/mioUtils.cpp.o
424.4 [ 63%] Building CXX object plugins/private/MeshIO/CMakeFiles/MeshIO.dir/MeshIO_autogen/EWIEGA46WW/qrc_MeshIO.cpp.o   
424.5 [ 63%] Linking CXX shared library libMeshIO.so
427.6 /usr/bin/ld: /usr/lib/x86_64-linux-gnu/libz.a(deflate.o): relocation R_X86_64_PC32 against symbol `z_errmsg' can not be used when making a shared object; recompile with -fPIC
427.6 /usr/bin/ld: final link failed: bad value
427.6 collect2: error: ld returned 1 exit status
427.6 make[2]: *** [plugins/private/MeshIO/CMakeFiles/MeshIO.dir/build.make:234: plugins/private/MeshIO/libMeshIO.so] Error 1
427.6 make[1]: *** [CMakeFiles/Makefile2:2564: plugins/private/MeshIO/CMakeFiles/MeshIO.dir/all] Error 2
427.6 make: *** [Makefile:136: all] Error 2
------
failed to solve: process "/bin/sh -c cmake --build ." did not complete successfully: exit code: 2

So my guess would be that the problem has something to do with the libMeshIO.so

@asmaloney
Copy link
Owner

So my guess would be that the problem has something to do with the libMeshIO.so

Yes, but it links with assimp statically which is the thing including libz. I just wanted to make sure it wasn't something else.

The first thing I will do is update assimp to the latest release, though it doesn't look like there are any changes relevant to this.

@asmaloney
Copy link
Owner

Does your output show cmake running at the top with all its output?

I'm looking for this information:

-- Found private plugin: /path/CloudCompare/CloudCompareGIT/plugins/private/MeshIO
-- Added io plugin: MeshIO
-- Shared libraries disabled
-- Looking for ZLIB...

If you have it, can you just copy the whole cmake output here? It will be long, so please use a collapsible section in the GitHub markdown to keep it reasonable.

And then anything about assimp in the build which should be something like this:

[ 52%] Automatic MOC for target assimp
[ 52%] Built target assimp_autogen
... <- all this stuff
[ 68%] Built target assimp
[ 68%] Built target MeshIO_autogen_timestamp_deps
[ 68%] Automatic MOC and UIC for target MeshIO

@mh-9
Copy link
Author

mh-9 commented Jun 18, 2024

Here are the full logs from the cmake commands of my Dockerfile.
The assimp lines are also included.

docker.log

@asmaloney
Copy link
Owner

Ah - it's finding a local lib and using that:

#44 0.981 -- Found ZLIB: optimized;/usr/lib/x86_64-linux-gnu/libz.a;debug;/usr/lib/x86_64-linux-gnu/libz.a

It's possible libz.a needs to be built with -fPIC, which means you can't use the installed one.

I'm having a hard time with all the mutually-exclusive zlib-related options in assimp, but it looks like you can set the cmake option ASSIMP_BUILD_ZLIB to include the zlib source in the compilation which might solve it?

@mh-9
Copy link
Author

mh-9 commented Jun 20, 2024

Thank you so much for your help!

ASSIMP_BUILD_ZLIB was the correct option. Now I could finally build CloudCompare with the MeshIO plugin enabled. I could already use CloudCompare with IFC files, so I can confirm that it works!

The updated Dockerfile for reference and future use:

FROM ubuntu:focal
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
    build-essential \
    git \
    qt5-default \
    qttools5-dev \
    qttools5-dev-tools \
    libqt5svg5-dev \
    libqt5opengl5-dev \
    libqt5websockets5-dev \
    libssl-dev \
    libxerces-c-dev \
    xvfb \
    && rm -rf /var/lib/apt/lists/*

# Build CMake 3.22.0
WORKDIR /
RUN git clone --recursive --depth 1 --branch v3.22.0 https://github.com/Kitware/CMake.git
WORKDIR /CMake
RUN ./bootstrap
RUN make
RUN make install

# Clone CloudCompare and the MeshIO Plugin
WORKDIR /
RUN git clone --recursive https://github.com/cloudcompare/CloudCompare.git
WORKDIR /CloudCompare/plugins
RUN mkdir private
WORKDIR /CloudCompare/plugins/private
RUN git clone --recursive https://github.com/asmaloney/MeshIO.git

# Build CloudCompare
WORKDIR /CloudCompare
RUN mkdir build
WORKDIR /CloudCompare/build
RUN cmake -DASSIMP_BUILD_ZLIB=ON -DPLUGIN_IO_QE57=ON -DPLUGIN-3rdParty_MESH_IO=ON ..
RUN cmake --build .
RUN cmake --install .

COPY ./data/input /data

COPY /docker/entrypoint.sh /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]

The entrypoint.sh script contains the following lines:

#!/bin/bash

xvfb-run -a --server-args="-screen 0 1024x768x24" CloudCompare -SILENT -c_export_fmt e57 -o /data/input/<file_name>.e57 -o /data/input/<file_name>.ifc -c2m_dist

@mh-9 mh-9 closed this as completed Jun 20, 2024
@asmaloney
Copy link
Owner

Great! Thanks for letting me know.

I will change the plugin so ASSIMP_BUILD_ZLIB is always on for Linux.

asmaloney added a commit that referenced this issue Jun 20, 2024
Linux needs zlib built with -fPIC, so build it from the source.

Reference: #9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Linux This is a Linux-only issue unconfirmed An unconfirmed bug
Projects
None yet
Development

No branches or pull requests

2 participants