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

Building with C++17 standard and Boost results in use of removed functions #2634

Closed
dgovil opened this issue Aug 31, 2023 · 9 comments
Closed

Comments

@dgovil
Copy link
Collaborator

dgovil commented Aug 31, 2023

This is more of an informational issue rather than anything dire, but I figure it's good to log it, since I know I'm not the only one trying to build USD as C++17. However, Boost is an issue because Boost has a bunch of functions that are removed from C++17 as the default pathway.

A lot of USD files use the Boost hash.hpp file that makes use of the deprecated std::unary_function call by default.
Depending on your compiler version, this will print a warning (if its deprecated but not removed), but starting with the most recent clang versions (as of macOS 14 / Xcode 15 for example), it is actually removed, resulting in this error:

boost/container_hash/hash.hpp:132:33: error: no template named 'unary_function' in namespace 'std'; did you mean '__unary_function'?
        struct hash_base : std::unary_function<T, std::size_t> {};
                           ~~~~~^

There's a couple workarounds for this, until USD is successfully de-boosted.

  1. Obviously , the easiest workaround is don't compile for C++17 and stick with C++14. But that's dull 😀
  2. Compile with Boost 1.82 per the 2024 VFX Platform, but that might not be possible for you either because of other dependencies
  3. Add add_compile_definitions(BOOST_NO_CXX98_FUNCTION_BASE) to your CMake file somewhere, or just make sure it's defined before Boost is included. That is used across various Boost functions and makes Boost be C++17 compatible.

Anyway, again, not so much something that explicitly needs solving. I'm just putting this up as an FYI for anyone else hitting it.
I assume that when USD moves to C++17, that the define will need to be set, or we'll be free of boost before then.

@sunyab
Copy link
Contributor

sunyab commented Aug 31, 2023

That's great information! We're looking to move to C++17 so we can replace some boost classes (like boost::optional) with their std equivalents as part of the de-boostification effort. It looks like we'll need to set that BOOST_NO_CXX98_FUNCTION_BASE in our CMake in the interim.

Thanks for the heads-up!

@meshula
Copy link
Member

meshula commented Aug 31, 2023

We probably need to also publish BOOST_NO_CXX98_FUNCTION_BASE to our pxrConfig.cmake files in addition to setting it in build_usd.py, because anything consuming USD is also affected. For my own usage, I have been building against boost 1.81 (1.81 was the oldest boost that worked in my regression) in order to avoid having to introduce BOOST_NO_CXX98_FUNCTION_BASE to downstream projects.

@jesschimein
Copy link
Contributor

Filed as internal issue #USD-8638

@nvmkuruc
Copy link
Collaborator

nvmkuruc commented Sep 5, 2023

It should be relatively straight forward to replace boost::hash with TfHash in imaging to avoid needing to worry about BOOST_NO_CXX98_FUNCTION_BASE.

pixar-oss pushed a commit that referenced this issue Sep 19, 2023
…a stopgap

to get us over a C++17 upgrade hurdle, and is intended to be replaced by more
thorough work by mkuruc.

Fixes #2634

(Internal change: 2294196)
pixar-oss pushed a commit that referenced this issue Sep 19, 2023
Note this adds a boost-specific #define to avoid using
deprecated STL features that have been removed on some
platforms. See #2634.

Fixes #2634

(Internal change: 2295937)
@dgovil
Copy link
Collaborator Author

dgovil commented Oct 13, 2023

@meshula and @nvmkuruc , is this issue still problematic for USD 23.11? I see that the Boost versions in the build_usd.py are still pretty old so I think we'd still hit this, but maybe all the uses of boost:hash have been removed?

If not, I think we might need to upgrade the Boost version used?

@sunyab
Copy link
Contributor

sunyab commented Oct 13, 2023

Hey @dgovil, we have not removed all uses of boost::hash but the C++17 issue should be addressed by a couple of changes:

  • 0e4d360 adds the preprocessor define that @meshula mentioned above to the USD build, so USD itself shouldn't hit this issue.
  • ae45ce8 removes the last uses of boost::hash from public headers, so client code that happens to include them shouldn't hit this issue either.

@dgovil
Copy link
Collaborator Author

dgovil commented Oct 13, 2023

Awesome. Thanks, @sunyab. I'll close this issue out since it's not blocking anymore.

@ikryukov
Copy link

ikryukov commented Nov 7, 2023

@dgovil @sunyab I'm still have this issue with 23.11 compiled with python support:

[build] In file included from /Users/ikryukov/work/USD_build_23_11/include/pxr/imaging/hd/task.h:29:
[build] In file included from /Users/ikryukov/work/USD_build_23_11/include/pxr/imaging/hd/driver.h:31:
[build] In file included from /Users/ikryukov/work/USD_build_23_11/include/pxr/base/vt/value.h:31:
[build] In file included from /Users/ikryukov/work/USD_build_23_11/include/pxr/base/tf/pyObjWrapper.h:37:
[build] In file included from /Users/ikryukov/work/USD_build_23_11/include/boost/functional/hash.hpp:6:
[build] /Users/ikryukov/work/USD_build_23_11/include/boost/container_hash/hash.hpp:132:33: error: no template named 'unary_function' in namespace 'std'; did you mean '__unary_function'?
[build]         struct hash_base : std::unary_function<T, std::size_t> {};
[build]                            ~~~~~^
[build] /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/include/c++/v1/__functional/unary_function.h:46:1: note: '__unary_function' declared here
[build] using __unary_function = __unary_function_keep_layout_base<_Arg, _Result>;
[build] ^
[build] 1 error generated.

Apple clang version 15.0.0 (clang-1500.0.40.1)
Target: arm64-apple-darwin23.1.0

I can confirm that adding add_compile_definitions(BOOST_NO_CXX98_FUNCTION_BASE) to my make project helps.

@nvmkuruc
Copy link
Collaborator

nvmkuruc commented Nov 7, 2023

The following PRs remove boost::hash from OpenUSD. They should be released in 24.02. Is cherry picking those commits an option for your 23.11 build?

#2785
#2765
#2764
#2763

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

No branches or pull requests

6 participants