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

Build on Xcode 9.3 fails: It seems to define __cplusplus to 201703L without having <optional> #201

Open
Yang8510 opened this issue May 17, 2018 · 9 comments

Comments

@Yang8510
Copy link

When I built with Xcode, it came out the error "optional" not found. When I change it to experimental/optional, the error turns to boost/shared_ptr.hpp auto_ptrs.

@juan-cardelino
Copy link

juan-cardelino commented May 21, 2018

I'm having a similar issue, but after solving the optional part, had problems with variant. It seems that for Xcode 9.3, the following ward fails:

#if (__cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L))

After forcing to disable that (using && 0) it gives me the following error:

Showing All Errors Only
/Users/juan/juanc/soft/develop/eos/include/eos/morphablemodel/MorphableModel.hpp:151:60: Call to unavailable member function 'value':

I'm using Apple LLVM version 9.1.0 (clang-902.0.39.1)
Target: x86_64-apple-darwin17.5.0

@patrikhuber
Copy link
Owner

Thank you for the report and details @juan-cardelino.
It seems that in Xcode 9.3 (Apple clang-902.0.39.1), Apple may have set __cplusplus to 201703L, without providing <optional>. This is quite a bummer, and potentially a mistake on their part.

I've added Xcode 9.3 to travis (9266d8e) so that we can track it, and indeed it fails there as well.

It's weird that after "manually" editing that check with && 0 you get that Call to unavailable member function 'value' error. Maybe you haven't changed it in all places? Have you changed it in include/eos/cpp17/optional_serialization.hpp too?
You should definitely be able to make it work by making it use the eos::cpp17 drop-in replacements, like it works for C++14 compilers.

I am afraid I won't have time to properly look at that in the next few weeks, but above should really get you going.

@patrikhuber patrikhuber changed the title Xcode issue Build on Xcode 9.3 fails: It seems to define __cplusplus to 201703L without having <optional> May 21, 2018
@juan-cardelino
Copy link

Dear Patrik,
Thanks for your quick answer. I agree that it is a mistake of XCode. About the replacement, I didn't check it thoroughly, because I had a linux box and switched to it, in which BTW worked like a charm. I'll give it another try and let you know.
Thanks again.
Best,
Juan

@juan-cardelino
Copy link

I've carefully searched all occurrences and disabled all of them. Then I got an error on auto_ptr, like @Yang8510. But I realized it was actually a boost error. I replaced my current boost (1.60) by the newest one (1.67) and worked like a charm.
Just for adding a little detail, I'm building on OSX High Sierra (10.13.4).
Thanks for the help.
Best,
Juan

@patrikhuber
Copy link
Owner

@juan-cardelino Hey cool, that's awesome! Thank you very much for reporting back.
Hehe yes I thought the boost error was something like that. And eos just uses boost for the example apps, the eos library does not require boost.

I'm glad all is working well now :-)

So I guess we just need to add something to that ifdef that for example checks for AppleClang or something like that.

@juan-cardelino
Copy link

Thank you very much for the help. Great work!

@akrymski
Copy link

I have boost 1.67 but the python module still doesn't build on High Sierra

@patrikhuber
Copy link
Owner

@akrymski What's your error? I am sure you can fix it by adjusting above #define. Xcode updated their compiler recently so it depends what version you're on, you just need to find out whether it has usable optional/variant or not and set above define accordingly, and it should work.

@MaG21
Copy link

MaG21 commented Aug 29, 2018

I managed to compile the code with xcode.

Clang doesn't fully support C++17, however the following expression resolves to true when compiling with clang __cplusplus >= 201703L, which prevents us from building the project on Xcode.

For more information refer to the following answer about Clang's C++17 support: https://stackoverflow.com/a/47794453

I created a patch, that fixes this problem when compiling with Clang (or Xcode). Save it as a .patch file and apply the patch as follows (with git):

$ git am < file.patch

From fd8bb883ef8ae92d790f4a52c2df00753fd8272c Mon Sep 17 00:00:00 2001
From: MaG <maguilamo.c@gmail.com>
Date: Wed, 29 Aug 2018 16:08:02 -0400
Subject: [PATCH] Fix compile type error when using Clang

Clang doesn't fully support C++17, however the following directive
__cplusplus >= 201703L is true when compiling with Clang.

In order to make this code  compile under clang, whe have to
prevent make clang from compiling C++17 code, to do so, I
just removed clang from any clause that requires C++17.

---
 include/eos/cpp17/optional.hpp               | 2 +-
 include/eos/cpp17/optional_serialization.hpp | 2 +-
 include/eos/cpp17/variant.hpp                | 2 +-
 include/eos/cpp17/variant_serialization.hpp  | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/include/eos/cpp17/optional.hpp b/include/eos/cpp17/optional.hpp
index ea52007..ab5943d 100644
--- a/include/eos/cpp17/optional.hpp
+++ b/include/eos/cpp17/optional.hpp
@@ -22,7 +22,7 @@
 #ifndef EOS_OPTIONAL_HPP_
 #define EOS_OPTIONAL_HPP_

-#if __cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
+#if !defined(__clang__) && (__cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L))
   #include <optional>
   namespace eos {
     namespace cpp17 {
diff --git a/include/eos/cpp17/optional_serialization.hpp b/include/eos/cpp17/optional_serialization.hpp
index caa7b05..3bf1eec 100644
--- a/include/eos/cpp17/optional_serialization.hpp
+++ b/include/eos/cpp17/optional_serialization.hpp
@@ -22,7 +22,7 @@
 #ifndef EOS_OPTIONAL_SERIALIZATION_HPP_
 #define EOS_OPTIONAL_SERIALIZATION_HPP_

-#if __cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
+#if !defined(__clang__) && (__cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L))
   #include "cereal/types/optional.hpp"
 #else
   #include "eos/cpp17/detail/akrzemi1_optional_serialization.hpp"
diff --git a/include/eos/cpp17/variant.hpp b/include/eos/cpp17/variant.hpp
index 2da8a72..c932cfd 100644
--- a/include/eos/cpp17/variant.hpp
+++ b/include/eos/cpp17/variant.hpp
@@ -22,7 +22,7 @@
 #ifndef EOS_VARIANT_HPP_
 #define EOS_VARIANT_HPP_

-#if __cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
+#if !defined(__clang__) && (__cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L))
   #include <variant>
   namespace eos {
     namespace cpp17 {
diff --git a/include/eos/cpp17/variant_serialization.hpp b/include/eos/cpp17/variant_serialization.hpp
index 5aa4798..a8166c3 100644
--- a/include/eos/cpp17/variant_serialization.hpp
+++ b/include/eos/cpp17/variant_serialization.hpp
@@ -22,7 +22,7 @@
 #ifndef EOS_VARIANT_SERIALIZATION_HPP_
 #define EOS_VARIANT_SERIALIZATION_HPP_

-#if __cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
+#if !defined(__clang__) && (__cplusplus >= 201703L || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L))
   #include "cereal/types/variant.hpp"
 #else
   #include "eos/cpp17/detail/mpark_variant_serialization.hpp"
--
2.14.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants