YPZ404
YPZ404

Reputation: 93

How to change c++ compiler version in CMake when building OpenPose on MacOS?

I have cloned the latest version of OpenPose and try to build it on MacOS 13.5 (22G74). After I run make -j sysctl -n hw.logicalcpu it generates a bunch of errors saying that I used an outdated c++ version:

/usr/local/include/google/protobuf/port_def.inc:205:1: error: static_assert failed due to requirement '201103L >= 201402L' "Protobuf only supports C++14 and newer."
static_assert(PROTOBUF_CPLUSPLUS_MIN(201402L), "Protobuf only supports C++14 and newer.");
^             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/usr/local/include/absl/base/policy_checks.h:79:2: error: "C++ versions less than C++14 are not supported."
#error "C++ versions less than C++14 are not supported."

So I searched through the CMakeLists.txt and added these lines on the top of the file:

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

also changed part of the c++ flags section to std=c++14:

elseif (UNIX)
  # Turn on C++14
  add_definitions(-std=c++14)
  set(CMAKE_CXX_FLAGS_RELEASE "-O3")
elseif (APPLE)
  # Turn on C++14
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
  set(CMAKE_CXX_FLAGS_RELEASE "-O3")
endif (WIN32)

# C++ additional flags
if (CMAKE_COMPILER_IS_GNUCXX)
  message(STATUS "GCC detected, adding compile flags")
  # set(OP_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp -Wpedantic -Wall -Wextra -Wfatal-errors")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
  set(OP_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wpedantic -Wall -Wextra -Wfatal-errors")
  # set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -Wpedantic -Wall -Wextra -Wfatal-errors")
endif (CMAKE_COMPILER_IS_GNUCXX)

then remove the build folder and do the steps all over again, but still got the same errors. I check the CMake Configuration Summery in the Terminal, found out the flag is still set to version 11 for c++:

-- ******************* Caffe Configuration Summary *******************
-- General:
--   Version           :   1.0.0
--   Git               :   1.0-149-g1807aada
--   System            :   Darwin
--   C++ compiler      :   /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
--   Release CXX flags :   -O3 -DNDEBUG -fPIC -Wall -std=c++11 -Wno-sign-compare -Wno-uninitialized
--   Debug CXX flags   :   -g -fPIC -Wall -std=c++11 -Wno-sign-compare -Wno-uninitialized
--   Build type        :   Release

Right now I have no idea how to change the flags and compiler version. I also can't find how to change this in cmake-gui, the gui looks like this: enter image description here Any solution is welcome!

Upvotes: 0

Views: 1781

Answers (2)

YPZ404
YPZ404

Reputation: 93

Turns out I was modifying the wrong CMakeLists.txt file. The correct one should be under the path:openpose/3rdparty/caffe/CMakeLists.txt.

Then change the flag here to other versions:

# ---[ Flags
if(UNIX OR APPLE)
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wall -std=c++17")
endif()

This should do the work.

Upvotes: 3

felixkellenbenz
felixkellenbenz

Reputation: 43

The CMAKE_CXX_STANDARD variable was introduced in CMake 3.1 so make sure to use cmake_minimum_required(VERSION 3.1). If this does not help, I found this (How do I activate C++ 11 in CMake?) post on Stack Overflow which could provide you with a more in depth answer.

Upvotes: 0

Related Questions