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

Mac Compiling issue #1727

Closed
AndersonChang opened this issue Apr 28, 2020 · 23 comments
Closed

Mac Compiling issue #1727

AndersonChang opened this issue Apr 28, 2020 · 23 comments

Comments

@AndersonChang
Copy link

Hi all,

I tried to follow the steps :

  1. git clone --recursive https://github.com/openMVG/openMVG.git
  2. mkdir openMVG_Build
  3. cd openMVG_Build
  4. cmake -DCMAKE_BUILD_TYPE=RELEASE . ../openMVG/src/
  5. make install

and then I got the following message:

[ 0%] Building HTML documentation with Sphinx
Running Sphinx v2.4.0
WARNING: html_static_path entry '_static' does not exist
loading pickled environment... done
building [mo]: targets for 0 po files that are out of date
building [html]: targets for 0 source files that are out of date
updating environment: 0 added, 0 changed, 0 removed
looking for now-outdated files... none found
no targets are out of date.
build succeeded, 1 warning.

The HTML pages are in htmlDoc.
[ 0%] Built target doc
[ 14%] Built target lib_CoinUtils
[ 17%] Built target lib_Osi
[ 30%] Built target lib_clp
[ 31%] Built target lib_OsiClpSolver
[ 32%] Built target openMVG_stlplus
[ 34%] Built target openMVG_lemon
[ 34%] Built target main_svgSample
[ 35%] Built target openMVG_easyexif
[ 37%] Built target openMVG_fast
[ 37%] Built target openMVG_exif
[ 39%] Built target openMVG_features
[ 40%] Built target openMVG_numeric
[ 41%] Built target openMVG_image
[ 42%] Built target openMVG_linearProgramming
[ 48%] Built target openMVG_multiview
[ 49%] Built target openMVG_lInftyComputerVision
[ 51%] Built target openMVG_geometry
[ 52%] Built target openMVG_matching
[ 53%] Built target openMVG_kvld
[ 54%] Built target openMVG_matching_image_collection
[ 54%] Built target openMVG_multiview_test_data
[ 54%] Built target openMVG_robust_estimation
[ 54%] Built target openMVG_system
[ 60%] Built target openMVG_sfm
[ 60%] Linking CXX executable ../../Darwin-x86_64-RELEASE/openMVG_sample_cameras_undistoBrown
ld: library not found for -lgomp
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [Darwin-x86_64-RELEASE/openMVG_sample_cameras_undistoBrown] Error 1
make[1]: *** [openMVG_Samples/cameras_undisto_Brown/CMakeFiles/openMVG_sample_cameras_undistoBrown.dir/all] Error 2
make: *** [all] Error 2

It seems the linker cannot find the target, could anyone instruct me how to modify the CmakeList.txt to solve this problem?

Thanks.

@pmoulon
Copy link
Member

pmoulon commented Apr 28, 2020

Temporary solution:

  • deactivate OpenMP by adding -DOpenMVG_USE_OPENMP=OFF to your make command line

Long term solution:

Recent CMake seems to have new ways to handle OpenMP but it was not stable on all the machine I tried.

@AndersonChang
Copy link
Author

Thanks pmoulon, I tried to recompile with the following command,

cmake -DCMAKE_BUILD_TYPE=RELEASE -DOpenMVG_USE_OPENMP=OFF -DOpenMVG_BUILD_TESTS=ON -DOpenMVG_BUILD_EXAMPLES=ON . ../openMVG/src/

which disabled OpenMP, and run make install :

Scanning dependencies of target openMVG_test_progress
[0~80%]
[ 80%] Linking CXX executable ../../Darwin-x86_64-RELEASE/openMVG_sample_image_matching
[ 80%] Built target openMVG_sample_image_matching
Scanning dependencies of target openMVG_sample_image_matching_gmsfilter
[ 80%] Building CXX object openMVG_Samples/features_image_matching_gmsfilter/CMakeFiles/openMVG_sample_image_matching_gmsfilter.dir/describe_and_match_gmsfilter.cpp.o
[ 80%] Linking CXX executable ../../Darwin-x86_64-RELEASE/openMVG_sample_image_matching_gmsfilter
[ 80%] Built target openMVG_sample_image_matching_gmsfilter
Scanning dependencies of target openMVG_sample_describe_and_match_GUI_autogen
[ 80%] Automatic MOC for target openMVG_sample_describe_and_match_GUI
[ 80%] Built target openMVG_sample_describe_and_match_GUI_autogen
Scanning dependencies of target openMVG_sample_describe_and_match_GUI
[ 80%] Building CXX object openMVG_Samples/describe_and_match_GUI/CMakeFiles/openMVG_sample_describe_and_match_GUI.dir/openMVG_sample_describe_and_match_GUI_autogen/mocs_compilation.cpp.o
[ 80%] Building CXX object openMVG_Samples/describe_and_match_GUI/CMakeFiles/openMVG_sample_describe_and_match_GUI.dir/main.cpp.o
[ 80%] Building CXX object openMVG_Samples/describe_and_match_GUI/CMakeFiles/openMVG_sample_describe_and_match_GUI.dir/ImageView.cpp.o
[ 81%] Building CXX object openMVG_Samples/describe_and_match_GUI/CMakeFiles/openMVG_sample_describe_and_match_GUI.dir/MainWindow.cpp.o
[ 81%] Linking CXX executable ../../Darwin-x86_64-RELEASE/openMVG_sample_describe_and_match_GUI.app/Contents/MacOS/openMVG_sample_describe_and_match_GUI
[ 81%] Built target openMVG_sample_describe_and_match_GUI
Scanning dependencies of target openMVG_sample_geodesy_show_exif_gps_position
[ 81%] Building CXX object openMVG_Samples/geodesy_show_exif_gps_position/CMakeFiles/openMVG_sample_geodesy_show_exif_gps_position.dir/show_exif_gps_position_demo.cpp.o
[ 81%] Linking CXX executable ../../Darwin-x86_64-RELEASE/openMVG_sample_geodesy_show_exif_gps_position
[ 81%] Built target openMVG_sample_geodesy_show_exif_gps_position
Scanning dependencies of target openMVG_sample_pano_converter
[ 81%] Building CXX object openMVG_Samples/image_spherical_to_pinholes/CMakeFiles/openMVG_sample_pano_converter.dir/main_pano_converter.cpp.o
[ 81%] Linking CXX executable ../../Darwin-x86_64-RELEASE/openMVG_sample_pano_converter
[ 81%] Built target openMVG_sample_pano_converter
Scanning dependencies of target openMVG_sample_image_undistort_autogen
[ 81%] Automatic MOC for target openMVG_sample_image_undistort
[ 81%] Built target openMVG_sample_image_undistort_autogen
Scanning dependencies of target openMVG_sample_image_undistort
[ 81%] Building CXX object openMVG_Samples/image_undistort_gui/CMakeFiles/openMVG_sample_image_undistort.dir/openMVG_sample_image_undistort_autogen/mocs_compilation.cpp.o
[ 81%] Building CXX object openMVG_Samples/image_undistort_gui/CMakeFiles/openMVG_sample_image_undistort.dir/main.cc.o
[ 81%] Building CXX object openMVG_Samples/image_undistort_gui/CMakeFiles/openMVG_sample_image_undistort.dir/MainWindow.cc.o
[ 82%] Building CXX object openMVG_Samples/image_undistort_gui/CMakeFiles/openMVG_sample_image_undistort.dir/QImageInterface.cc.o
[ 82%] Linking CXX executable ../../Darwin-x86_64-RELEASE/openMVG_sample_image_undistort
Undefined symbols for architecture x86_64:
"image_undistort_gui::MainWindow::staticMetaObject", referenced from:
image_undistort_gui::MainWindow::onOpenImage() in MainWindow.cc.o
image_undistort_gui::MainWindow::onExportImage() in MainWindow.cc.o
"vtable for image_undistort_gui::MainWindow", referenced from:
_main in main.cc.o
image_undistort_gui::MainWindow::MainWindow(QWidget*) in MainWindow.cc.o
NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [Darwin-x86_64-RELEASE/openMVG_sample_image_undistort] Error 1
make[1]: *** [openMVG_Samples/image_undistort_gui/CMakeFiles/openMVG_sample_image_undistort.dir/all] Error 2
make: *** [all] Error 2

Somehow it keeps stuck in openMVG_sample_image_undistort linker error, it seems to me
that some linker setting in CmakeList cannot find the path correctly.

Let me know if you have any suggestion.

Thanks.

@pmoulon
Copy link
Member

pmoulon commented Apr 29, 2020

For this issue, you can see here for the putative fix #1720

@AndersonChang
Copy link
Author

I see , after I add "-DOpenMVG_BUILD_GUI_SOFTWARES=OFF" to disable the gui, it works for compiling src code. Thanks a lot ! : )

@pmoulon
Copy link
Member

pmoulon commented Apr 29, 2020

Without OpenMP OpenMVG will be a bit slow, I would advise you to use OpenMVG in a docker to use OpenMVG at its full speed on your Mac

@rperrot
Copy link
Contributor

rperrot commented Apr 29, 2020

An alternative to build with openMP is to install a clang compiler with openMP enabled. That's possible using macports (maybe homebrew) and it works fine with openMVG.

@virtualritz
Copy link

virtualritz commented May 15, 2020

The Apple Clang compiler does support OpenMP. I have a similar issue on macOS 10.15.4. This is IMHO related to header files not being found; not to OpenMP support in the compiler:

[ 37%] Building CXX object openMVG/features/CMakeFiles/openMVG_features.dir/akaze/AKAZE.cpp.o
In file included from /Users/moritz/code/openMVG/src/openMVG/features/akaze/AKAZE.cpp:9:
In file included from /Users/moritz/code/openMVG/src/openMVG/features/akaze/AKAZE.hpp:39:
In file included from /Users/moritz/code/openMVG/src/openMVG/image/image_container.hpp:12:
In file included from /usr/local/include/eigen3/Eigen/Dense:1:
/usr/local/include/eigen3/Eigen/Core:266:10: fatal error: 'omp.h' file not found
#include <omp.h>

@pmoulon
Copy link
Member

pmoulon commented May 15, 2020

@virtualritz You should access this line only if EIGEN_HAS_OPENMP is defined...
This preprocessor should not be defined by default from my understanding...

#if (defined _OPENMP) && (!defined EIGEN_DONT_PARALLELIZE)
  #define EIGEN_HAS_OPENMP
#endif

So you could fix your build by using -DEIGEN_DONT_PARALLELIZE=1 in the cmake command line of OpenMVG

@virtualritz
Copy link

I tried:

> cmake -DCMAKE_BUILD_TYPE=RELEASE -DEIGEN_DONT_PARALLELIZE=1 ../src
...
-- Generating done
CMake Warning:
  Manually-specified variables were not used by the project:

    EIGEN_DONT_PARALLELIZE


-- Build files have been written to: /Users/moritz/code/openMVG/build
> make -j4
...
[ 36%] Building CXX object openMVG/numeric/CMakeFiles/openMVG_numeric.dir/numeric.cpp.o
In file included from /Users/moritz/code/openMVG/src/openMVG/numeric/nullspace.cpp:9:
In file included from /Users/moritz/code/openMVG/src/openMVG/numeric/nullspace.hpp:12:
In file included from /Users/moritz/code/openMVG/src/openMVG/numeric/eigen_alias_definition.hpp:17:
In file included from /usr/local/include/eigen3/Eigen/Dense:1:
/usr/local/include/eigen3/Eigen/Core:266:10: fatal error: 'omp.h' file not found
#include <omp.h>
         ^~~~~~~

@virtualritz
Copy link

I also tried out commenting our the #define EIGEN_HAS_OPENMP. No luck. Eigen keeps looking for the omp.h.

@pmoulon
Copy link
Member

pmoulon commented May 21, 2020

My bad, to forwards the preprocessor to the compiler you need to use https://cmake.org/cmake/help/v3.0/command/add_definitions.html.

@virtualritz
Copy link

virtualritz commented May 21, 2020

The bottom line is that the macOS build of OpenMVG is broken for users of Apple Clang. Using OpenMVG w/o OpenMP is too slow to be feasible.

I'm building darktable with Apple Clang with OpenMP support w/o issues on my machine. Aka: this is not a compiler issue.

@virtualritz
Copy link

virtualritz commented May 21, 2020

My bad, to forwards the preprocessor to the compiler you need to use https://cmake.org/cmake/help/v3.0/command/add_definitions.html.

Well, as I said: I commented out that line with the #define and it was still looking for that header. So this doesn't work. The only thing that does is to specify -DOpenMVG_USE_OPENMP=OFF but that makes OpenMVG unusably slow on my box.

@rperrot
Copy link
Contributor

rperrot commented May 21, 2020

The bottom line is that the macOS build of OpenMVG is broken for users of Apple Clang. Using OpenMVG w/o OpenMP is too slow to be feasible.

Aka: this is not a compiler issue.

There are many issues :

  1. Apple clang doesn't come with OpenMP support (maybe il will never support it) ;
  2. Macports (and maybe homebrew) clang includes openMP support and it is fully supported on macOS build of openMVG.
  3. No it's not a compiler issue, it's detection of openMP on a dependency of openMVG (Eigen) that cause this issue.
  4. We rely on openMP for man parts of the parallelization inside openMVG. So if you want to have maximum perfomance, you must have a compiler that support openMP.

The only thing that does is to specify -DOpenMVG_USE_OPENMP=OFF but that makes OpenMVG unusably slow on my box.

There is no alternative of using a different compiler (aka macports clang) if you want openMP support. If you want to keep apple clang you must agree with it's drawback.

@pmoulon
Copy link
Member

pmoulon commented May 21, 2020

Sidenote: You can use OpenMVG in a Docker and so still using all the core of your machine to run OpenMVG

@virtualritz
Copy link

virtualritz commented May 21, 2020

There is no alternative of using a different compiler (aka macports clang) if you want openMP support. If you want to keep apple clang you must agree with it's drawback.

You are mistaken. As I wrote above – I am building darktable (which needs OpenMP) on the same system using Apple Clang. See e.g. here for how to do this. Again. This is not a compiler issue.

TLDR; Try this using Apple Clang:

clang -Xpreprocessor -fopenmp foo.c -lomp

@rperrot
Copy link
Contributor

rperrot commented May 22, 2020

Thanks for your suggestion, but it's actually building openMP (using llvm version) to bring support to apple clang. That's exactly the same as macports/homebrew clang version did in a more cleaner way.

Since you compile an openMP version that is not exactly the same version as the LLVM backend you may encounter performance degradation (because of some LTO that may not be possible). Strong/deep integration of openMP is always preferable.

Even it works, i strongly suggest that you use a clean install of llvm/clang/libomp from the same source/version for maximum performance and compatibility.

@virtualritz
Copy link

virtualritz commented May 22, 2020

The issue is that there are tons of issues with building stuff when you have the Homebrew (or MacPorts) clang installed next to Apple clang.

I've been fighting with them over two years and I do not want to go back there. I'm usually avoiding building stuff with OpenMP on macOS and just switch to Linux but at the moment I'm far from home and stuck with an old MBP that doesn't have the space to install even a VM.

@rperrot
Copy link
Contributor

rperrot commented May 22, 2020

I'm usually avoiding building stuff with OpenMP

I agree. We try our best to avoid openMP in openMVG (using std::thread for ex), but it' a tedious task.

@cogitas3d
Copy link

Im with this problem on Mac OS X Catalina.

I'm using develop branch:
git clone --recursive https://github.com/openMVG/openMVG.git -b develop

I use the flags:
cmake -DCMAKE_BUILD_TYPE=RELEASE -DOpenMVG_BUILD_GUI_SOFTWARES=OFF -DOpenMVG_USE_OPENMP=OFF ../src

But I had this error:

[ 80%] Built target openMVG_sample_pano_spherical_to_cubic
[ 81%] Building CXX object software/SfM/CMakeFiles/openMVG_main_SplitMatchFileIntoMatchFiles.dir/main_SplitMatchFileIntoMatchFiles.cpp.o
[ 81%] Linking CXX executable ../../Darwin-x86_64-RELEASE/openMVG_main_SplitMatchFileIntoMatchFiles
[ 81%] Built target openMVG_main_SplitMatchFileIntoMatchFiles
[ 82%] Building CXX object software/SfM/CMakeFiles/openMVG_main_ComputeStructureFromKnownPoses.dir/main_ComputeStructureFromKnownPoses.cpp.o
/Users/ciceromoraes/Programs/openMVG/src/software/SfM/main_ComputeStructureFromKnownPoses.cpp:33:10: fatal error:
'ceres/types.h' file not found
#include <ceres/types.h>
^~~~~~~~~~~~~~~

This is the first time in years, that I have problem with openMVG compilation.

@cogitas3d
Copy link

[SOLVED]

How I need only some of the coomand, i solved the problem ignoring the make errors:

make -i

Thank you all to show how to solve the other problems!

@pmoulon
Copy link
Member

pmoulon commented Mar 25, 2021

@cogitas3d Normally the problem should be solved with this https://github.com/openMVG/openMVG/blob/develop/src/software/SfM/CMakeLists.txt#L154

Can you add message(${CERES_INCLUDE_DIRS}) in the cmakelist and see if it is having a value?

@pmoulon pmoulon closed this as completed Feb 3, 2022
rfabbri added a commit to rfabbri/openMVG that referenced this issue Mar 29, 2022
Compiles and links in develop branch using Xcode 13.3 under
macOS Monterey 12.2.1 (march/2022).
Likely also builds with XCode 12.5.1 under Big Sur.
The problem was that cmake would proceed OK,
but there were build errors such as 'omp.h' not found.
See Issue openMVG#1727.

See also this commit in an unmerged PR for additional fixes that may be needed in other
branches:
openMVG@b775118
@rfabbri
Copy link
Contributor

rfabbri commented Mar 29, 2022

@virtualritz please see PR #1908 for a fix on the develop branch for the include problem 'omp.h' file not found
The develop branch with this fix builds without compile or link problems on Mac OS using Xcode 13.3 under
macOS Monterey 12.2.1 (march/2022).

pmoulon pushed a commit that referenced this issue Apr 16, 2022
Fixes #2008
- Compiles and links in develop branch using Xcode 13.3 under macOS Monterey 12.2.1 (march/2022).
Likely also builds with XCode 12.5.1 under Big Sur.
The problem was that cmake would proceed OK, but there were build errors such as 'omp.h' not found.
See Issue #1727.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants