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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build failure due to C++ version mismatch #106206

Open
Flamefire opened this issue Jul 28, 2023 · 0 comments
Open

Build failure due to C++ version mismatch #106206

Flamefire opened this issue Jul 28, 2023 · 0 comments
Labels
module: build Build system issues triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Comments

@Flamefire
Copy link
Collaborator

Flamefire commented Jul 28, 2023

馃悰 Describe the bug

I'm building with GCC 12.2 and "system"/preinstalled protobuf.

The build fails on caffe2.pb.cc which includes protobuf which includes abseil which tries to use std::string_view.

Abseil was build without specific C++-standard flags so it uses the compilers default, which is C++17. However PyTorchs C++ standard (used to) be C++14:

set(CMAKE_CXX_STANDARD 14 CACHE STRING "The C++ standard whose features are requested to build this target.")

Both Abseil and Protobuf correctly export (via INTERFACE properties) their required C++ standard but PyTorchs doesn't consistently use the CMake target protobuf::libprotobuf

The 2 affected locations are:

  • add_library(Caffe2_PROTO OBJECT ${Caffe2_PROTO_HEADERS} ${Caffe2_PROTO_SRCS})
    which adds an (object-)library containing (generated) protobuf C++ files but that doesn't link against protobuf::libprotobuf and hence doesn't know about it's C++ standard
  • get_target_property(__tmp protobuf::libprotobuf INTERFACE_INCLUDE_DIRECTORIES)
    message(STATUS "Caffe2 protobuf include directory: " ${__tmp})
    include_directories(BEFORE SYSTEM ${__tmp})
    which hides the issue by adding the protobuf include path (read from the target) globally (which is discouraged CMake practice)

I was able to resolve this by adding target_link_libraries(Caffe2_PROTO PUBLIC protobuf::libprotobuf) and removing

get_target_property(__tmp protobuf::libprotobuf INTERFACE_INCLUDE_DIRECTORIES)
message(STATUS "Caffe2 protobuf include directory: " ${__tmp})
include_directories(BEFORE SYSTEM ${__tmp})

However I'm wondering why the object-library is necessary at all (the objects are used once to create caffe2_protos)

Although this (currently) might not be an issue anymore after 36ac095 raised the standard to C++17 I still think it is wrong to just ignore the C++ standard of (in this case) libprotobuf and any other INTERFACE options it might have set and which may be required to successfully compile it on all systems.

Versions

1.13.1 - master

cc @malfet @seemethere

@malfet malfet added module: build Build system issues triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module labels Jul 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module: build Build system issues triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants