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

Fix for compile errors in GCC 12 #824

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,13 @@ if(Boost_FOUND)
SET(_USE_BOOST TRUE)
endif()

FIND_PACKAGE(Eigen3 REQUIRED)
if(EIGEN3_FOUND)
LIST(APPEND OpenMVS_EXTRA_INCLUDES ${EIGEN3_INCLUDE_DIR})
INCLUDE_DIRECTORIES(${EIGEN3_INCLUDE_DIR})
find_package(Eigen3 3.4 REQUIRED)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls test these chages with older linux distribution and windows and mac too

if(Eigen3_FOUND)
LIST(APPEND OpenMVS_DEFINITIONS -D_USE_EIGEN)
ADD_DEFINITIONS(${EIGEN3_DEFINITIONS})
SET(_USE_EIGEN TRUE)
MESSAGE(STATUS "Eigen ${EIGEN3_VERSION} found (include: ${EIGEN3_INCLUDE_DIR})")

message(STATUS "Found Eigen version ${Eigen3_VERSION}: ${Eigen3_DIR}")
link_libraries(Eigen3::Eigen)
endif()

FIND_PACKAGE(OpenCV REQUIRED)
Expand Down
4 changes: 3 additions & 1 deletion apps/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Add applications
ADD_SUBDIRECTORY(DensifyPointCloud)
ADD_SUBDIRECTORY(InterfaceCOLMAP)
ADD_SUBDIRECTORY(InterfaceMetashape)
ADD_SUBDIRECTORY(DensifyPointCloud)
#ADD_SUBDIRECTORY(InterfaceOpenMVG)
#ADD_SUBDIRECTORY(InterfaceVisualSFM)
ADD_SUBDIRECTORY(ReconstructMesh)
ADD_SUBDIRECTORY(RefineMesh)
ADD_SUBDIRECTORY(TextureMesh)
Expand Down
2 changes: 1 addition & 1 deletion apps/DensifyPointCloud/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ else()
endif()
FILE(GLOB LIBRARY_FILES_H "*.h" "*.inl")

cxx_executable_with_flags(DensifyPointCloud "Apps" "${cxx_default}" "MVS;${OpenMVS_EXTRA_LIBS}" ${LIBRARY_FILES_C} ${LIBRARY_FILES_H})
cxx_executable_with_flags(DensifyPointCloud "Apps" "${cxx_default}" "MVS;Common;${OpenMVS_EXTRA_LIBS}" ${LIBRARY_FILES_C} ${LIBRARY_FILES_H})
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should not be needed, Common is linked to MVS; pls find out why this is needed here and it worked fine will all linux distros till now


# Install
INSTALL(TARGETS DensifyPointCloud
Expand Down
2 changes: 1 addition & 1 deletion apps/InterfaceCOLMAP/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ else()
endif()
FILE(GLOB LIBRARY_FILES_H "*.h" "*.inl")

cxx_executable_with_flags(InterfaceCOLMAP "Apps" "${cxx_default}" "MVS;${OpenMVS_EXTRA_LIBS}" ${LIBRARY_FILES_C} ${LIBRARY_FILES_H})
cxx_executable_with_flags(InterfaceCOLMAP "Apps" "${cxx_default}" "MVS;IO;${OpenMVS_EXTRA_LIBS}" ${LIBRARY_FILES_C} ${LIBRARY_FILES_H})
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above


# Install
INSTALL(TARGETS InterfaceCOLMAP
Expand Down
2 changes: 1 addition & 1 deletion apps/InterfaceMetashape/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ else()
endif()
FILE(GLOB LIBRARY_FILES_H "*.h" "*.inl")

cxx_executable_with_flags(InterfaceMetashape "Apps" "${cxx_default}" "MVS;${OpenMVS_EXTRA_LIBS}" ${LIBRARY_FILES_C} ${LIBRARY_FILES_H})
cxx_executable_with_flags(InterfaceMetashape "Apps" "${cxx_default}" "MVS;IO;${OpenMVS_EXTRA_LIBS}" ${LIBRARY_FILES_C} ${LIBRARY_FILES_H})

# Install
INSTALL(TARGETS InterfaceMetashape
Expand Down
6 changes: 4 additions & 2 deletions apps/InterfaceOpenMVG/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
FIND_PACKAGE(OpenMVG QUIET)
IF (OPENMVG_FOUND)
find_package(Ceres REQUIRED)
INCLUDE_DIRECTORIES(${OPENMVG_INCLUDE_DIRS})

add_definitions(-D_USE_OPENMVG)
set(LIBS_DEPEND "MVS;${OPENMVG_LIBRARIES}")
set(LIBS_DEPEND "MVS;Common;OpenMVG::openMVG_sfm;OpenMVG::openMVG_camera;OpenMVG::openMVG_image")
ELSE()
set(LIBS_DEPEND "MVS")
set(LIBS_DEPEND "MVS;Common")
MESSAGE("OPENMVG_NOT FOUND : OpenMVG importer with JSON support will not be build")
ENDIF()

Expand Down
14 changes: 8 additions & 6 deletions apps/InterfaceOpenMVG/InterfaceOpenMVG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
#undef R2D
#include <openMVG/sfm/sfm_data.hpp>
#include <openMVG/sfm/sfm_data_io.hpp>
#include <openMVG/image/image.hpp>
#include <openMVG/image/image_io.hpp>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool, but the interface should be disabled anyway

#include <openMVG/cameras/cameras.hpp>

#endif


Expand Down Expand Up @@ -415,7 +417,7 @@ bool Initialize(size_t argc, LPCTSTR* argv)
Util::ensureValidPath(OPT::strInputFileName);
Util::ensureUnifySlash(OPT::strInputFileName);
Util::ensureUnifySlash(OPT::strOutputImageFolder);
Util::ensureDirectorySlash(OPT::strOutputImageFolder);
Util::ensureFolderSlash(OPT::strOutputImageFolder);
const String strInputFileNameExt(Util::getFileExt(OPT::strInputFileName).ToLower());
OPT::bOpenMVS2OpenMVG = (strInputFileNameExt == MVS_EXT);
#ifdef _USE_OPENMVG
Expand All @@ -440,10 +442,10 @@ bool Initialize(size_t argc, LPCTSTR* argv)
Util::ensureUnifySlash(OPT::strOutputFileName);
if (OPT::bOpenMVS2OpenMVG) {
if (OPT::strOutputFileName.IsEmpty())
OPT::strOutputFileName = Util::getFullFileName(OPT::strInputFileName);
OPT::strOutputFileName = Util::getFileFullName(OPT::strInputFileName);
} else {
if (OPT::strOutputFileName.IsEmpty())
OPT::strOutputFileName = Util::getFullFileName(OPT::strInputFileName) + MVS_EXT;
OPT::strOutputFileName = Util::getFileFullName(OPT::strInputFileName) + MVS_EXT;
}

// initialize global options
Expand Down Expand Up @@ -602,10 +604,10 @@ int main(int argc, LPCTSTR* argv)
image.name = view.second->s_Img_path;
Util::ensureUnifySlash(image.name);
Util::strTrim(image.name, PATH_SEPARATOR_STR);
String pathRoot(sfm_data.s_root_path); Util::ensureDirectorySlash(pathRoot);
String pathRoot(sfm_data.s_root_path); Util::ensureFolderSlash(pathRoot);
const String srcImage(MAKE_PATH_FULL(WORKING_FOLDER_FULL, pathRoot+image.name));
image.name = MAKE_PATH_FULL(WORKING_FOLDER_FULL, OPT::strOutputImageFolder+image.name);
Util::ensureDirectory(image.name);
Util::ensureFolder(image.name);
image.ID = static_cast<MVS::IIndex>(view.first);
image.platformID = map_intrinsic.at(view.second->id_intrinsic);
MVS::Platform& platform = scene.platforms[image.platformID];
Expand Down
2 changes: 1 addition & 1 deletion apps/InterfaceVisualSFM/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ else()
endif()
FILE(GLOB LIBRARY_FILES_H "*.h" "*.inl")

cxx_executable_with_flags(InterfaceVisualSFM "Apps" "${cxx_default}" "MVS;${OpenMVS_EXTRA_LIBS}" ${LIBRARY_FILES_C} ${LIBRARY_FILES_H})
cxx_executable_with_flags(InterfaceVisualSFM "Apps" "${cxx_default}" "MVS;Common;${OpenMVS_EXTRA_LIBS}" ${LIBRARY_FILES_C} ${LIBRARY_FILES_H})

# Install
INSTALL(TARGETS InterfaceVisualSFM
Expand Down
2 changes: 1 addition & 1 deletion apps/ReconstructMesh/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ else()
endif()
FILE(GLOB LIBRARY_FILES_H "*.h" "*.inl")

cxx_executable_with_flags(ReconstructMesh "Apps" "${cxx_default}" "MVS;${OpenMVS_EXTRA_LIBS}" ${LIBRARY_FILES_C} ${LIBRARY_FILES_H})
cxx_executable_with_flags(ReconstructMesh "Apps" "${cxx_default}" "MVS;Common;${OpenMVS_EXTRA_LIBS}" ${LIBRARY_FILES_C} ${LIBRARY_FILES_H})

# Install
INSTALL(TARGETS ReconstructMesh
Expand Down
2 changes: 1 addition & 1 deletion apps/RefineMesh/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ else()
endif()
FILE(GLOB LIBRARY_FILES_H "*.h" "*.inl")

cxx_executable_with_flags(RefineMesh "Apps" "${cxx_default}" "MVS;${OpenMVS_EXTRA_LIBS}" ${LIBRARY_FILES_C} ${LIBRARY_FILES_H})
cxx_executable_with_flags(RefineMesh "Apps" "${cxx_default}" "MVS;Common;${OpenMVS_EXTRA_LIBS}" ${LIBRARY_FILES_C} ${LIBRARY_FILES_H})

# Install
INSTALL(TARGETS RefineMesh
Expand Down
2 changes: 1 addition & 1 deletion apps/TextureMesh/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ else()
endif()
FILE(GLOB LIBRARY_FILES_H "*.h" "*.inl")

cxx_executable_with_flags(TextureMesh "Apps" "${cxx_default}" "MVS;${OpenMVS_EXTRA_LIBS}" ${LIBRARY_FILES_C} ${LIBRARY_FILES_H})
cxx_executable_with_flags(TextureMesh "Apps" "${cxx_default}" "MVS;Common;${OpenMVS_EXTRA_LIBS}" ${LIBRARY_FILES_C} ${LIBRARY_FILES_H})

# Install
INSTALL(TARGETS TextureMesh
Expand Down
2 changes: 1 addition & 1 deletion apps/Viewer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ else()
endif()
FILE(GLOB LIBRARY_FILES_H "*.h" "*.inl")

cxx_executable_with_flags(${VIEWER_NAME} "Apps" "${cxx_default}" "MVS;${OPENGL_LIBRARIES};${GLEW_LIBRARY};${GLFW_STATIC_LIBRARIES};GLEW::GLEW;${glfw3_LIBRARY};${GLFW3_LIBRARY};glfw;${OpenMVS_EXTRA_LIBS}" ${LIBRARY_FILES_C} ${LIBRARY_FILES_H})
cxx_executable_with_flags(${VIEWER_NAME} "Apps" "${cxx_default}" "MVS;Common;${OPENGL_LIBRARIES};${GLEW_LIBRARY};${GLFW_STATIC_LIBRARIES};GLEW::GLEW;${glfw3_LIBRARY};${GLFW3_LIBRARY};glfw;${OpenMVS_EXTRA_LIBS}" ${LIBRARY_FILES_C} ${LIBRARY_FILES_H})

# Manually set Common.h as the precompiled header
IF(CMAKE_VERSION VERSION_GREATER_EQUAL 3.16.0)
Expand Down
107 changes: 0 additions & 107 deletions build/Modules/FindEigen3.cmake

This file was deleted.

1 change: 0 additions & 1 deletion build/Utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,6 @@ macro(optimize_default_compiler_settings)
add_extra_compiler_option(-Werror=sequence-point)
add_extra_compiler_option(-Wformat)
add_extra_compiler_option(-Werror=format-security -Wformat)
add_extra_compiler_option(-Wstrict-prototypes)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls explain

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In comment below you can see that compiler is producing a warning:

cc1plus: warning: command-line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++

add_extra_compiler_option(-Winit-self)
add_extra_compiler_option(-Wsign-promo)
add_extra_compiler_option(-Wreorder)
Expand Down
1 change: 1 addition & 0 deletions libs/Common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ endif()

# Link its dependencies
TARGET_LINK_LIBRARIES(Common ${Boost_LIBRARIES} ${OpenCV_LIBS})
TARGET_COMPILE_OPTIONS(Common INTERFACE -fpermissive)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls detail, I did not understand the comment from the PR; at line 3062 all looks fine to me:

			fImage.write(cv::Mat::template ptr<const float>(--i), rowbytes);

Copy link

@bialasjaroslaw bialasjaroslaw Jun 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunatelly either new version of OpenCV has some kind of a bug or GCC12 is behaving differently and selecting non const template version of a ptr function (line 713 of mat.inl.hpp) and though const qualifier is not respected for this. I can paste exact error message if you are able to help with that. I tried to solve this myself, but I am not so smart, so I removed this code, as I am not using it anywhere (PFM image files). As I understand -fpermissive will remove such restrictions.

[ 24%] Building CXX object libs/IO/CMakeFiles/IO.dir/OBJ.cpp.o
cc1plus: warning: command-line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
In file included from /home/jbialas/openMVS/libs/Common/Types.h:2789,
   			 from /home/jbialas/openMVS/libs/Common/Common.h:176,
   			 from /home/jbialas/openMVS/libs/IO/Common.h:18,
   			 from /home/jbialas/openMVS_build/libs/IO/CMakeFiles/IO.dir/cmake_pch.hxx:5,
   			 from <command-line>:
/home/jbialas/openMVS/libs/Common/Types.inl: In instantiation of ‘bool SEACAVE::TImage<TYPE>::Save(const SEACAVE::String&) const [with TYPE = SEACAVE::TPixel<unsigned char>]’:
/home/jbialas/openMVS/libs/IO/OBJ.cpp:77:39:   required from here
/home/jbialas/openMVS/libs/Common/Types.inl:3062:72: error: passing ‘const SEACAVE::TImage<SEACAVE::TPixel<unsigned char> >’ as ‘this’ argument discards qualifiers [-fpermissive]
3062 |						 fImage.write(cv::Mat::template ptr<const float>(--i), rowbytes);
     |									  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
In file included from /usr/include/opencv4/opencv2/core/mat.hpp:3773,
   			 from /usr/include/opencv4/opencv2/core.hpp:58,
   			 from /usr/include/opencv4/opencv2/opencv.hpp:52,
   			 from /home/jbialas/openMVS/libs/Common/Types.h:143:
/usr/include/opencv4/opencv2/core/mat.inl.hpp:713:6: note:   in call to ‘_Tp* cv::Mat::ptr(int) [with _Tp = const float]’
 713 | _Tp* Mat::ptr(int y)
     |	  ^~~
make[2]: *** [libs/IO/CMakeFiles/IO.dir/build.make:237: libs/IO/CMakeFiles/IO.dir/OBJ.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:405: libs/IO/CMakeFiles/IO.dir/all] Error 2
make: *** [Makefile:136: all] Error 2
 

Copy link

@alkavan alkavan Jul 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cdcseacave I'm having the same issue on Fedora 36 and gcc 12.1.1 20220507 (Red Hat 12.1.1-1) when building the v2.0.1 tag, with boost 1.76 and and latest vcglib.

OPENMVS_VERSION="2.0.1"

# Configure CMake
cmake "../third_party/openMVS-${OPENMVS_VERSION}" \
  -DCMAKE_BUILD_TYPE=Release \
  -DBUILD_SHARED_LIBS=OFF \
  -DCMAKE_INSTALL_PREFIX=/opt/3dr \
  -DBOOST_ROOT="../third_party/boost_1_76_0/stage" \
  -DVCG_ROOT="../third_party/vcglib" \
  -DBoost_USE_STATIC_LIBS=ON

Would be happy to provide more information so we can solve this!


# Install
SET_TARGET_PROPERTIES(Common PROPERTIES
Expand Down