simonfuhrmann / mve

Multi-View Environment
http://www.gcc.tu-darmstadt.de/home/proj/mve/
Other
977 stars 419 forks source link

Compilation issue in MacOS Silicon: This header is only meant to be used on x86 and x64 architecture #572

Closed l-4-l closed 1 month ago

l-4-l commented 1 month ago

I am trying to compile the MVE in MacOS (Sonoma 14.4.1), with CPU M1 Max.

  1. I installed libraries with brew command:

    arch -arm64 brew install libjpeg libtiff
  2. Because it was still complaining about missing headers, I modified libs/mve/Makefile as following:

    diff --git a/libs/mve/Makefile b/libs/mve/Makefile
    index 6240dda..853ecc4 100644
    --- a/libs/mve/Makefile
    +++ b/libs/mve/Makefile
    @@ -3,8 +3,8 @@ TARGET := libmve.a
    include ${MVE_ROOT}/Makefile.inc
    
    # Position independent code (-fPIC) is required for the UMVE plugin system.
    -CXXFLAGS += -fPIC -I${MVE_ROOT}/libs
    -LDLIBS += -lpng -ltiff -ljpeg
    +CXXFLAGS += -fPIC -I${MVE_ROOT}/libs -I/opt/homebrew/include
    +LDLIBS += -lpng -ltiff -ljpeg -L/opt/homebrew/lib
  3. I executed make -j8. Now I have at least 20 compilation errors "This header is only meant to be used on x86 and x64 architecture", first lines with error:

    /Applications/Xcode.app/Contents/Developer/usr/bin/make -C sfm
    c++ -Wall -Wextra -Wundef -pedantic -march=native -funsafe-math-optimizations -fno-math-errno -std=c++11 -g -O3 -pthread -I../../libs   -c -MM ba_linear_solver.cc bundle_adjustment.cc bundler_common.cc bundler_features.cc bundler_incremental.cc bundler_init_pair.cc bundler_intrinsics.cc bundler_matching.cc bundler_tracks.cc camera_database.cc cascade_hashing.cc exhaustive_matching.cc extract_focal_length.cc feature_set.cc fundamental.cc homography.cc matching.cc nearest_neighbor.cc pose_p3p.cc ransac.cc ransac_fundamental.cc ransac_homography.cc ransac_pose_p3p.cc sift.cc surf.cc triangulate.cc visualizer.cc >Makefile.dep
    In file included from nearest_neighbor.cc:42:
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/15.0.0/include/emmintrin.h:14:2: error: "This header is only meant to be used on x86 and x64 architecture"
    #error "This header is only meant to be used on x86 and x64 architecture"
    ^
    In file included from nearest_neighbor.cc:42:
    In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/15.0.0/include/emmintrin.h:17:
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/15.0.0/include/xmmintrin.h:14:2: error: "This header is only meant to be used on x86 and x64 architecture"
    #error "This header is only meant to be used on x86 and x64 architecture"
    ^
    In file included from nearest_neighbor.cc:42:
    In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/15.0.0/include/emmintrin.h:17:
    In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/15.0.0/include/xmmintrin.h:17:
  4. I tried to compile with Docker, command line docker buildx -t mve build ., result is that it cannot find emmintrin.h. I suppose it is also because of Apple Silicon architecture but this time in Docker image. Start of the docker build log:

#0 0.049 fetch http://dl-cdn.alpinelinux.org/alpine/v3.10/main/aarch64/APKINDEX.tar.gz
#0 0.428 fetch http://dl-cdn.alpinelinux.org/alpine/v3.10/community/aarch64/APKINDEX.tar.gz
#0 0.570 (1/65) Installing libgcc (8.3.0-r0)

End of the docker build log (first error message):

#0 16.64 make[2]: Entering directory '/mve/libs/sfm'
#0 16.64 g++ -Wall -Wextra -Wundef -pedantic -march=native -funsafe-math-optimizations -fno-math-errno -std=c++11 -g -O3 -pthread -I../../libs -fopenmp  -c -o ransac_homography.o ransac_homography.cc
#0 17.16 g++ -Wall -Wextra -Wundef -pedantic -march=native -funsafe-math-optimizations -fno-math-errno -std=c++11 -g -O3 -pthread -I../../libs -fopenmp  -c -o visualizer.o visualizer.cc
#0 18.13 g++ -Wall -Wextra -Wundef -pedantic -march=native -funsafe-math-optimizations -fno-math-errno -std=c++11 -g -O3 -pthread -I../../libs -fopenmp  -c -o triangulate.o triangulate.cc
#0 20.09 g++ -Wall -Wextra -Wundef -pedantic -march=native -funsafe-math-optimizations -fno-math-errno -std=c++11 -g -O3 -pthread -I../../libs -fopenmp  -c -o nearest_neighbor.o nearest_neighbor.cc
#0 20.12 nearest_neighbor.cc:42:10: fatal error: emmintrin.h: No such file or directory
#0 20.12  #include <emmintrin.h> // SSE2
#0 20.12           ^~~~~~~~~~~~~
#0 20.12 compilation terminated.

Did anybody tried to compile for MacOS Silicon?

andre-schulz commented 1 month ago

It's probably because the inclusion of the SSE2/SSE3 intrinsics headers is unguarded. Can you try the following?

diff --git a/libs/sfm/nearest_neighbor.cc b/libs/sfm/nearest_neighbor.cc
index 14825f6bc4e0..0924175beae4 100644
--- a/libs/sfm/nearest_neighbor.cc
+++ b/libs/sfm/nearest_neighbor.cc
@@ -39,8 +39,12 @@

 #include <algorithm>
 #include <iostream>
-#include <emmintrin.h> // SSE2
-#include <pmmintrin.h> // SSE3
+#if defined(__SSE2__)
+#   include <emmintrin.h> // SSE2
+#endif
+#if defined(__SSE3__)
+#   include <pmmintrin.h> // SSE3
+#endif

 #include "sfm/nearest_neighbor.h"
l-4-l commented 1 month ago

@andre-schulz thank you, it works. Now it fails on linking stage:

/Applications/Xcode.app/Contents/Developer/usr/bin/make -C apps
/Applications/Xcode.app/Contents/Developer/usr/bin/make -C bundle2pset
c++  bundle2pset.o ../../libs/mve/libmve.a ../../libs/util/libmve_util.a -lpng -ltiff -ljpeg  -L/opt/homebrew/lib -o bundle2pset
Undefined symbols for architecture arm64:
  "mve::geom::save_ply_mesh(std::__1::shared_ptr<mve::TriangleMesh const>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, mve::geom::SavePLYOptions const&)", referenced from:
      _main in bundle2pset.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [bundle2pset] Error 1
make[1]: *** [all] Error 2
make: *** [all] Error 2
andre-schulz commented 1 month ago

Hm that's weird. Can you post the command-line how bundle2pset.o was compiled and the output of objdump -a bundle2pset.o?

l-4-l commented 1 month ago

@andre-schulz

The original full output (make -j8):

% make -j8
/Applications/Xcode.app/Contents/Developer/usr/bin/make -C libs
/Applications/Xcode.app/Contents/Developer/usr/bin/make -C math
#ar rcs libmve_math.a
/Applications/Xcode.app/Contents/Developer/usr/bin/make -C util
make[2]: `libmve_util.a' is up to date.
/Applications/Xcode.app/Contents/Developer/usr/bin/make -C mve
make[2]: `libmve.a' is up to date.
/Applications/Xcode.app/Contents/Developer/usr/bin/make -C sfm
make[2]: `libmve_sfm.a' is up to date.
/Applications/Xcode.app/Contents/Developer/usr/bin/make -C dmrecon
make[2]: `libmve_dmrecon.a' is up to date.
/Applications/Xcode.app/Contents/Developer/usr/bin/make -C fssr
make[2]: `libmve_fssr.a' is up to date.
/Applications/Xcode.app/Contents/Developer/usr/bin/make -C ogl
make[2]: `libmve_ogl.a' is up to date.
/Applications/Xcode.app/Contents/Developer/usr/bin/make -C apps
/Applications/Xcode.app/Contents/Developer/usr/bin/make -C bundle2pset
c++  bundle2pset.o ../../libs/mve/libmve.a ../../libs/util/libmve_util.a -lpng -ltiff -ljpeg  -L/opt/homebrew/lib -o bundle2pset
Undefined symbols for architecture arm64:
  "mve::geom::save_ply_mesh(std::__1::shared_ptr<mve::TriangleMesh const>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, mve::geom::SavePLYOptions const&)", referenced from:
      _main in bundle2pset.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [bundle2pset] Error 1
make[1]: *** [all] Error 2
make: *** [all] Error 2

Then I repeated the problematic command with -v in the problematic folder:

% c++ -v bundle2pset.o ../../libs/mve/libmve.a ../../libs/util/libmve_util.a -lpng -ltiff -ljpeg  -L/opt/homebrew/lib -o bundle2pset
Apple clang version 15.0.0 (clang-1500.3.9.4)
Target: arm64-apple-darwin23.4.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -lto_library /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libLTO.dylib -dynamic -arch arm64 -platform_version macos 14.0.0 14.4 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -o bundle2pset -L/opt/homebrew/lib -L/usr/local/lib bundle2pset.o ../../libs/mve/libmve.a ../../libs/util/libmve_util.a -lpng -ltiff -ljpeg -lc++ -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/15.0.0/lib/darwin/libclang_rt.osx.a
Undefined symbols for architecture arm64:
  "mve::geom::save_ply_mesh(std::__1::shared_ptr<mve::TriangleMesh const>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, mve::geom::SavePLYOptions const&)", referenced from:
      _main in bundle2pset.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

ObjDump shows that bundle2pset.o is arm64:

% objdump -a bundle2pset.o
bundle2pset.o:  file format mach-o arm64
l-4-l commented 1 month ago

it looks like make cleanup magically helped the situation, it is built successfully on MacOS M1, all problems are solved by adding -I/opt/homebrew/include and -L/opt/homebrew/lib to each Makefile which mentions -lpng.

@andre-schulz Thank you for your support!

andre-schulz commented 1 month ago

That's great to hear! Have fun with MVE! :slightly_smiling_face: :+1:

l-4-l commented 1 month ago

another small problem with compiling of UMVE (QT): in new QT5.6+ (https://www.qtcentre.org/threads/65744-include-quot-QDialog-quot-etc-not-found-after-upgrade-from-5-4-to-5-6) a module "widgets" must be added to the umve.pro, if it's not there, the make cannot find QApplication header. Diff:

diff --git a/apps/umve/umve.pro b/apps/umve/umve.pro
index a6c4227..f1cddf4 100644
--- a/apps/umve/umve.pro
+++ b/apps/umve/umve.pro
@@ -1,7 +1,7 @@
 MVE_ROOT = ../..

 CONFIG += qt release c++11
-QT += concurrent opengl
+QT += concurrent opengl widgets