isl-org / Open3D

Open3D: A Modern Library for 3D Data Processing
http://www.open3d.org
Other
11.55k stars 2.32k forks source link

Cannot add Open3D to simple Qt5 app #6334

Open crosswick opened 1 year ago

crosswick commented 1 year ago

Checklist

Steps to reproduce the issue

I first cloned Open3D by:

git clone https://github.com/isl-org/Open3D.git
cd Open3D

Then, I built Open3D (on macOS 12.6.7) with:

mkdir build
cd build
cmake -DBUILD_PYTHON_MODULE=OFF ..
make -j$(sysctl -n hw.physicalcpu)

This gave errors, leading me to comment out a bunch of unused variables in Feature.cpp, see https://github.com/isl-org/Open3D/issues/6268

then make install

then build this simple cmake Qt5 example:

git clone https://github.com/ArthurSonzogni/cmake-Qt5-example.git
cd cmake-Qt5-example/
mkdir build
cd build
cmake ..
make
./myApplication

which succesfully runs this simple app.

Then, adding Open3D to this the CMakeLists.txt of this app:

# ┌──────────────────────────────────────────────────────────────────┐
# │  Open3D                                                          │
# └──────────────────────────────────────────────────────────────────┘

find_package(Open3D REQUIRED)
if (Open3D_FOUND)
    message(STATUS "Found Open3D ${Open3D_VERSION}")

    # Link directories
    link_directories(${Open3D_LIBRARY_DIRS})

    # Include directories
    include_directories(${Open3D_INCLUDE_DIRS})

else (Open3D_FOUND)
    message(STATUS "Open3D not found, skipping...")
endif (Open3D_FOUND)

Error message

In file included from /Users/steven/cmake-Qt5-example/build/myApplication_autogen/mocs_compilation.cpp:2:
In file included from /Users/steven/cmake-Qt5-example/build/myApplication_autogen/2TYNM7PALD/moc_MainWindow.cpp:10:
In file included from /Users/steven/cmake-Qt5-example/build/myApplication_autogen/2TYNM7PALD/../../../src/interface/MainWindow.hpp:4:
In file included from /usr/local/opt/qt@5/lib/QtWidgets.framework/Headers/QMainWindow:1:
In file included from /usr/local/opt/qt@5/lib/QtWidgets.framework/Headers/qmainwindow.h:43:
In file included from /usr/local/include/QtWidgets/qtwidgetsglobal.h:7:
In file included from /usr/local/include/QtGui/qtguiglobal.h:7:
In file included from /usr/local/include/QtCore/qglobal.h:46:
/usr/local/include/QtCore/qtypeinfo.h:25:73: error: expected '(' for function-style cast or type construction
inline constexpr bool qIsRelocatable =  std::is_trivially_copyable_v<T> && std::is_trivially_destructible_v<T>;
                                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
/usr/local/include/QtCore/qtypeinfo.h:25:81: error: no template named 'is_trivially_destructible_v' in namespace 'std'; did you mean 'is_trivially_destructible'?
inline constexpr bool qIsRelocatable =  std::is_trivially_copyable_v<T> && std::is_trivially_destructible_v<T>;
                                                                           ~~~~~^
/Library/Developer/CommandLineTools/SDKs/MacOSX13.1.sdk/usr/include/c++/v1/type_traits:3411:50: note: 'is_trivially_destructible' declared here
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_destructible
                                                 ^
In file included from /Users/steven/cmake-Qt5-example/build/myApplication_autogen/mocs_compilation.cpp:2:
In file included from /Users/steven/cmake-Qt5-example/build/myApplication_autogen/2TYNM7PALD/moc_MainWindow.cpp:10:
In file included from /Users/steven/cmake-Qt5-example/build/myApplication_autogen/2TYNM7PALD/../../../src/interface/MainWindow.hpp:4:
In file included from /usr/local/opt/qt@5/lib/QtWidgets.framework/Headers/QMainWindow:1:
In file included from /usr/local/opt/qt@5/lib/QtWidgets.framework/Headers/qmainwindow.h:43:
In file included from /usr/local/include/QtWidgets/qtwidgetsglobal.h:7:
In file included from /usr/local/include/QtGui/qtguiglobal.h:7:
In file included from /usr/local/include/QtCore/qglobal.h:46:
/usr/local/include/QtCore/qtypeinfo.h:25:111: error: expected '(' for function-style cast or type construction
inline constexpr bool qIsRelocatable =  std::is_trivially_copyable_v<T> && std::is_trivially_destructible_v<T>;
                                                                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
/usr/local/include/QtCore/qtypeinfo.h:35:14: error: no template named 'is_scalar_v' in namespace 'std'; did you mean 'is_scalar'?
        std::is_scalar_v<T> && !std::is_member_object_pointer_v<T>;
        ~~~~~^
/Library/Developer/CommandLineTools/SDKs/MacOSX13.1.sdk/usr/include/c++/v1/type_traits:1198:29: note: 'is_scalar' declared here
struct _LIBCPP_TEMPLATE_VIS is_scalar : _BoolConstant<__is_scalar(_Tp)> { };
                            ^
In file included from /Users/steven/cmake-Qt5-example/build/myApplication_autogen/mocs_compilation.cpp:2:
In file included from /Users/steven/cmake-Qt5-example/build/myApplication_autogen/2TYNM7PALD/moc_MainWindow.cpp:10:
In file included from /Users/steven/cmake-Qt5-example/build/myApplication_autogen/2TYNM7PALD/../../../src/interface/MainWindow.hpp:4:
In file included from /usr/local/opt/qt@5/lib/QtWidgets.framework/Headers/QMainWindow:1:
In file included from /usr/local/opt/qt@5/lib/QtWidgets.framework/Headers/qmainwindow.h:43:
In file included from /usr/local/include/QtWidgets/qtwidgetsglobal.h:7:
In file included from /usr/local/include/QtGui/qtguiglobal.h:7:
In file included from /usr/local/include/QtCore/qglobal.h:46:
/usr/local/include/QtCore/qtypeinfo.h:35:29: error: expected '(' for function-style cast or type construction
        std::is_scalar_v<T> && !std::is_member_object_pointer_v<T>;
        ~~~~~~~~~~~~~~~~~~~ ^
/usr/local/include/QtCore/qtypeinfo.h:35:38: error: no template named 'is_member_object_pointer_v' in namespace 'std'; did you mean 'is_member_object_pointer'?
        std::is_scalar_v<T> && !std::is_member_object_pointer_v<T>;
                                ~~~~~^
/Library/Developer/CommandLineTools/SDKs/MacOSX13.1.sdk/usr/include/c++/v1/type_traits:1092:29: note: 'is_member_object_pointer' declared here
struct _LIBCPP_TEMPLATE_VIS is_member_object_pointer
                            ^
In file included from /Users/steven/cmake-Qt5-example/build/myApplication_autogen/mocs_compilation.cpp:2:
In file included from /Users/steven/cmake-Qt5-example/build/myApplication_autogen/2TYNM7PALD/moc_MainWindow.cpp:10:
In file included from /Users/steven/cmake-Qt5-example/build/myApplication_autogen/2TYNM7PALD/../../../src/interface/MainWindow.hpp:4:
In file included from /usr/local/opt/qt@5/lib/QtWidgets.framework/Headers/QMainWindow:1:
In file included from /usr/local/opt/qt@5/lib/QtWidgets.framework/Headers/qmainwindow.h:43:
In file included from /usr/local/include/QtWidgets/qtwidgetsglobal.h:7:
In file included from /usr/local/include/QtGui/qtguiglobal.h:7:
In file included from /usr/local/include/QtCore/qglobal.h:46:
/usr/local/include/QtCore/qtypeinfo.h:35:67: error: expected '(' for function-style cast or type construction
        std::is_scalar_v<T> && !std::is_member_object_pointer_v<T>;
                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
/usr/local/include/QtCore/qtypeinfo.h:48:26: error: no template named 'is_pointer_v' in namespace 'std'; did you mean 'is_pointer'?
        isPointer = std::is_pointer_v<T>,
                    ~~~~~^
/Library/Developer/CommandLineTools/SDKs/MacOSX13.1.sdk/usr/include/c++/v1/type_traits:872:29: note: 'is_pointer' declared here
struct _LIBCPP_TEMPLATE_VIS is_pointer : _BoolConstant<__is_pointer(_Tp)> { };
                            ^
In file included from /Users/steven/cmake-Qt5-example/build/myApplication_autogen/mocs_compilation.cpp:2:
In file included from /Users/steven/cmake-Qt5-example/build/myApplication_autogen/2TYNM7PALD/moc_MainWindow.cpp:10:
In file included from /Users/steven/cmake-Qt5-example/build/myApplication_autogen/2TYNM7PALD/../../../src/interface/MainWindow.hpp:4:
In file included from /usr/local/opt/qt@5/lib/QtWidgets.framework/Headers/QMainWindow:1:
In file included from /usr/local/opt/qt@5/lib/QtWidgets.framework/Headers/qmainwindow.h:43:
In file included from /usr/local/include/QtWidgets/qtwidgetsglobal.h:7:
In file included from /usr/local/include/QtGui/qtguiglobal.h:7:
In file included from /usr/local/include/QtCore/qglobal.h:46:
/usr/local/include/QtCore/qtypeinfo.h:48:41: error: expected '(' for function-style cast or type construction
        isPointer = std::is_pointer_v<T>,
                    ~~~~~~~~~~~~~~~~~~~~^
/usr/local/include/QtCore/qtypeinfo.h:49:27: error: no template named 'is_integral_v' in namespace 'std'; did you mean 'is_integral'?
        isIntegral = std::is_integral_v<T>,
                     ~~~~~^
/Library/Developer/CommandLineTools/SDKs/MacOSX13.1.sdk/usr/include/c++/v1/type_traits:772:29: note: 'is_integral' declared here
struct _LIBCPP_TEMPLATE_VIS is_integral : _BoolConstant<__is_integral(_Tp)> { };
                            ^
In file included from /Users/steven/cmake-Qt5-example/build/myApplication_autogen/mocs_compilation.cpp:2:
In file included from /Users/steven/cmake-Qt5-example/build/myApplication_autogen/2TYNM7PALD/moc_MainWindow.cpp:10:
In file included from /Users/steven/cmake-Qt5-example/build/myApplication_autogen/2TYNM7PALD/../../../src/interface/MainWindow.hpp:4:
In file included from /usr/local/opt/qt@5/lib/QtWidgets.framework/Headers/QMainWindow:1:
In file included from /usr/local/opt/qt@5/lib/QtWidgets.framework/Headers/qmainwindow.h:43:
In file included from /usr/local/include/QtWidgets/qtwidgetsglobal.h:7:
In file included from /usr/local/include/QtGui/qtguiglobal.h:7:
In file included from /usr/local/include/QtCore/qglobal.h:46:
/usr/local/include/QtCore/qtypeinfo.h:49:43: error: expected '(' for function-style cast or type construction
        isIntegral = std::is_integral_v<T>,
                     ~~~~~~~~~~~~~~~~~~~~~^
/usr/local/include/QtCore/qtypeinfo.h:50:27: error: no template named 'is_trivial_v' in namespace 'std'; did you mean 'is_trivial'?
        isComplex = !std::is_trivial_v<T>,
                     ~~~~~^
/Library/Developer/CommandLineTools/SDKs/MacOSX13.1.sdk/usr/include/c++/v1/type_traits:3728:50: note: 'is_trivial' declared here
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivial
                                                 ^
In file included from /Users/steven/cmake-Qt5-example/build/myApplication_autogen/mocs_compilation.cpp:2:
In file included from /Users/steven/cmake-Qt5-example/build/myApplication_autogen/2TYNM7PALD/moc_MainWindow.cpp:10:
In file included from /Users/steven/cmake-Qt5-example/build/myApplication_autogen/2TYNM7PALD/../../../src/interface/MainWindow.hpp:4:
In file included from /usr/local/opt/qt@5/lib/QtWidgets.framework/Headers/QMainWindow:1:
In file included from /usr/local/opt/qt@5/lib/QtWidgets.framework/Headers/qmainwindow.h:43:
In file included from /usr/local/include/QtWidgets/qtwidgetsglobal.h:7:
In file included from /usr/local/include/QtGui/qtguiglobal.h:7:
In file included from /usr/local/include/QtCore/qglobal.h:46:
/usr/local/include/QtCore/qtypeinfo.h:50:42: error: expected '(' for function-style cast or type construction
        isComplex = !std::is_trivial_v<T>,
                     ~~~~~~~~~~~~~~~~~~~~^
/usr/local/include/QtCore/qtypeinfo.h:169:1: error: no template named 'is_trivial_v' in namespace 'std'; did you mean 'is_trivial'?
Q_DECLARE_TYPEINFO_BODY(QFlags<T>, Q_PRIMITIVE_TYPE);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/include/QtCore/qtypeinfo.h:154:66: note: expanded from macro 'Q_DECLARE_TYPEINFO_BODY'
        isComplex = (((FLAGS) & Q_PRIMITIVE_TYPE) == 0) && !std::is_trivial_v<TYPE>, \
                                                            ~~~~~^
/Library/Developer/CommandLineTools/SDKs/MacOSX13.1.sdk/usr/include/c++/v1/type_traits:3728:50: note: 'is_trivial' declared here
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivial
                                                 ^
In file included from /Users/steven/cmake-Qt5-example/build/myApplication_autogen/mocs_compilation.cpp:2:
In file included from /Users/steven/cmake-Qt5-example/build/myApplication_autogen/2TYNM7PALD/moc_MainWindow.cpp:10:
In file included from /Users/steven/cmake-Qt5-example/build/myApplication_autogen/2TYNM7PALD/../../../src/interface/MainWindow.hpp:4:
In file included from /usr/local/opt/qt@5/lib/QtWidgets.framework/Headers/QMainWindow:1:
In file included from /usr/local/opt/qt@5/lib/QtWidgets.framework/Headers/qmainwindow.h:43:
In file included from /usr/local/include/QtWidgets/qtwidgetsglobal.h:7:
In file included from /usr/local/include/QtGui/qtguiglobal.h:7:
In file included from /usr/local/include/QtCore/qglobal.h:46:
/usr/local/include/QtCore/qtypeinfo.h:169:1: error: expected '(' for function-style cast or type construction
Q_DECLARE_TYPEINFO_BODY(QFlags<T>, Q_PRIMITIVE_TYPE);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/include/QtCore/qtypeinfo.h:154:84: note: expanded from macro 'Q_DECLARE_TYPEINFO_BODY'
        isComplex = (((FLAGS) & Q_PRIMITIVE_TYPE) == 0) && !std::is_trivial_v<TYPE>, \
                                                            ~~~~~~~~~~~~~~~~~~~~~~~^
/usr/local/include/QtCore/qtypeinfo.h:169:1: error: no template named 'is_pointer_v' in namespace 'std'; did you mean 'is_pointer'?
Q_DECLARE_TYPEINFO_BODY(QFlags<T>, Q_PRIMITIVE_TYPE);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/include/QtCore/qtypeinfo.h:156:26: note: expanded from macro 'Q_DECLARE_TYPEINFO_BODY'
        isPointer = std::is_pointer_v< TYPE >, \
                    ~~~~~^
/Library/Developer/CommandLineTools/SDKs/MacOSX13.1.sdk/usr/include/c++/v1/type_traits:872:29: note: 'is_pointer' declared here
struct _LIBCPP_TEMPLATE_VIS is_pointer : _BoolConstant<__is_pointer(_Tp)> { };
                            ^
In file included from /Users/steven/cmake-Qt5-example/build/myApplication_autogen/mocs_compilation.cpp:2:
In file included from /Users/steven/cmake-Qt5-example/build/myApplication_autogen/2TYNM7PALD/moc_MainWindow.cpp:10:
In file included from /Users/steven/cmake-Qt5-example/build/myApplication_autogen/2TYNM7PALD/../../../src/interface/MainWindow.hpp:4:
In file included from /usr/local/opt/qt@5/lib/QtWidgets.framework/Headers/QMainWindow:1:
In file included from /usr/local/opt/qt@5/lib/QtWidgets.framework/Headers/qmainwindow.h:43:
In file included from /usr/local/include/QtWidgets/qtwidgetsglobal.h:7:
In file included from /usr/local/include/QtGui/qtguiglobal.h:7:
In file included from /usr/local/include/QtCore/qglobal.h:46:
/usr/local/include/QtCore/qtypeinfo.h:169:1: error: expected '(' for function-style cast or type construction
Q_DECLARE_TYPEINFO_BODY(QFlags<T>, Q_PRIMITIVE_TYPE);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/include/QtCore/qtypeinfo.h:156:46: note: expanded from macro 'Q_DECLARE_TYPEINFO_BODY'
        isPointer = std::is_pointer_v< TYPE >, \
                    ~~~~~~~~~~~~~~~~~~~~~~~~~^
fatal error: too many errors emitted, stopping now [-ferror-limit=]

Open3D, Python and System information

- Operating system: macOS 12.6.7 
- Open3D version: 0.17.0+59792c226
- System architecture: x86 
- Is this a remote workstation?: no
- How did you install Open3D?: build from source
- Compiler version (if built from source): AppleClang 14.0.0.14000029

Additional information

No response

crosswick commented 1 year ago

asking GPT4 about these errors, it says:

_The errors you're seeing are due to the use of C++17 features in the Qt library, but your compiler is not set to use C++17. The features in question are the std::is_trivially_copyable_v, std::is_trivially_destructible_v, std::is_scalar_v, std::is_member_object_pointer_v, std::is_pointer_v, std::is_integral_v, and std::is_trivialv type traits, which are variable templates introduced in C++17.

To fix this, you need to set your C++ standard to C++17 in your CMakeLists.txt file. You can do this by adding the following line:

set(CMAKE_CXX_STANDARD 17)

This line should be added before the project(myApplication) line in your CMakeLists.txt file. This will set the C++ standard to C++17 for all targets in your project.

Adding this, deleting the build folder and running cmake .. and make again gives these errors:

In file included from /Users/steven/cmake-Qt5-example/build/myApplication_autogen/mocs_compilation.cpp:2:
/Users/steven/cmake-Qt5-example/build/myApplication_autogen/2TYNM7PALD/moc_MainWindow.cpp:16:2: error: "This file was generated using the moc from 5.15.10. It"
#error "This file was generated using the moc from 5.15.10. It"
 ^
/Users/steven/cmake-Qt5-example/build/myApplication_autogen/2TYNM7PALD/moc_MainWindow.cpp:17:2: error: "cannot be used with the include files from this version of Qt."
#error "cannot be used with the include files from this version of Qt."
 ^
/Users/steven/cmake-Qt5-example/build/myApplication_autogen/2TYNM7PALD/moc_MainWindow.cpp:18:2: error: "(The moc has changed too much.)"
#error "(The moc has changed too much.)"
 ^
/Users/steven/cmake-Qt5-example/build/myApplication_autogen/2TYNM7PALD/moc_MainWindow.cpp:35:1: error: use of undeclared identifier 'Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET'
QT_MOC_LITERAL(0, 0, 10) // "MainWindow"
^
/Users/steven/cmake-Qt5-example/build/myApplication_autogen/2TYNM7PALD/moc_MainWindow.cpp:29:5: note: expanded from macro 'QT_MOC_LITERAL'
    Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(len, \
    ^
/Users/steven/cmake-Qt5-example/build/myApplication_autogen/2TYNM7PALD/moc_MainWindow.cpp:66:1: error: unknown type name 'QT_INIT_METAOBJECT'
QT_INIT_METAOBJECT const QMetaObject MainWindow::staticMetaObject = { {
^
/Users/steven/cmake-Qt5-example/build/myApplication_autogen/2TYNM7PALD/moc_MainWindow.cpp:66:37: error: expected ';' after top level declarator
QT_INIT_METAOBJECT const QMetaObject MainWindow::staticMetaObject = { {
                                    ^
                                    ;
6 errors generated.
crosswick commented 1 year ago

Asking GPT4 about these errors yields:

The errors you're seeing are due to a mismatch between the version of Qt used to generate the Meta-Object Compiler (moc) files and the version of Qt you're currently using to compile your project.

_The moc tool reads a C++ header file and generates additional C++ code that should be compiled and linked with the rest of the program. This generated code contains the QMetaObject code for the classes in your project that use the QOBJECT macro.

The error messages indicate that the moc files were generated using Qt version 5.15.10, but the Qt version you're currently using to compile your project is different and incompatible with these moc files.

To resolve this issue, you should:

1. Ensure that you're using the same version of Qt to generate the moc files and to compile your project. You can check your Qt version by running qmake --version in your terminal.

2. Delete the build directory and re-run CMake and make to regenerate the moc files and recompile your project. This ensures that all generated files are compatible with your current Qt version.

Here are the commands to do this:

rm -rf build
cmake .
make

Remember to replace build with your actual build directory if it's different.

crosswick commented 1 year ago

running qmake --version yields:

QMake version 3.1
Using Qt version 5.15.10 in /usr/local/Cellar/qt@5/5.15.10/lib

So that's not the issue. Please help - I have looked at the solution put forward in https://github.com/isl-org/Open3D/issues/2286 but in my Open3D CMakeLists.txt, GLIBCXX_USE_CXX11_ABI is already set to ON.

ssheorey commented 1 year ago

Hi @crosswick we recommend most users to download the prebuilt C++ binaries from GitHub releases for a consistent experience. Please follow these steps:

  1. Ensure that you can build an example Qt cmake project. [Done successfully, including here for other users.]
  2. Download Open3D binary archives for your platform and build the sample cmake project.
  3. Add Open3D to your cmake project and try to build.
  4. Develop / build your own Qt + Open3D project.

PS: GLIBCXX_USE_CXX11_ABI is only relevant for Linux.

crosswick commented 1 year ago

@ssheorey thank you for your reply - which binary should I download though?

In the list of downloads for the 0.17 release, for macosx x86_64 I can only find open3d-app-macosx-0.17_x86_64.zip, which is only the Open3D app, not the library.

Ah, it must be open3d-devel-darwin-x86_64-0.17.0.tar.xz - right? Is there also a version for arm64, Apple Silicon? I may need that in the future.

ssheorey commented 1 year ago

That's correct - these are open3d-devel packages. We don't have one for Apple Silicon since GitHub doesn't provide test machines for Apple Silicon, but we will try to add it in the future. Please open a new issue for it so that it is easier to track.

ssheorey commented 1 year ago

This will help: https://github.com/github/roadmap/issues/528

crosswick commented 1 year ago

Alright, I will open an issue requesting Apple Silicon devel support.

I would still be interested to learn how I can build from source myself in a way that the library works the same as the downloadable binary; I presume the goal is that there should be parity between the two methods, right?

ssheorey commented 1 year ago

Alright, I will open an issue requesting Apple Silicon devel support.

I would still be interested to learn how I can build from source myself in a way that the library works the same as the downloadable binary; I presume the goal is that there should be parity between the two methods, right?

Check the CI for that - it's pretty straightforward, but we sometimes have trouble due to incompatible dependency versions.

crosswick commented 1 year ago

Thanks - how do I check the CI though? The macOS CI link on the main github page seems broken.

ssheorey commented 1 year ago

https://github.com/isl-org/Open3D/actions/workflows/macos.yml

The commands to run the CI are in the file: .github/workflows/macos.yml