-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Discussion about supporting C++17 #6585
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
Comments
on macOS early 10.14, we can't use C++17 with oF0.11.0 release, with both but essentially, I think it lies under extending I fixed bug about difference between and if try to use C++17 on macOS 10.14, then we need to remove I want to propose what adding what do you think? |
Hey @2bbb I think that this move to support C++17 will eventually happen so we should consider it right now how to address it. I think that it is important that these changes don't alter the way in which of is used in general, as far as this is possible and does not bloat the codebase or needs the use of hacky fixes. |
Do we still need to use boost::filesystem in C++17 (meaning C++17 and OF_USING_STD_FS=0) ? |
i will push to my repository asap. @oxillo |
boost was only used temporarily until there was filesystem support in std. The idea is not to keep it but to remove it as soon as we can and stop even shipping the boost libraries. This needs to happen gradually by first only enabling OF_USING_STD_FS for those compilers that already have full support for c++17 then after the minimum version supported by OF already supports c++17 fully remove boost completely We would need to identify what versions of the supported compilers already support c++17 fully a way to detect the version. I would say:
|
I had a bad experience last year when enabling OF_USING_STD_FS on msys2 and running the tests. It deleted my OF dir...
In ofConstants.h, I've added the c++17 detection and removed the filesystem #if
I'll try to run the tests now after a backup... |
BTW, See this post for differences between |
Yes they are not exactly the same but OF_USING_STD_FS not only includes one or the other but also ifdefs certain calls that are different for both. Exisiting code might need to be changed when directly using std::filersystem There might be some differences from std::filesystem experimental and the finall c++17 implementation. I think i only tested it with experimental when implementing it so there might be some changes that need to be made to get it to work with c++17 |
https://github.com./2bbb/openFrameworks/tree/dev/supporting_cpp17 codes in this branch is better way i think. this changes of code make another namespace i know this will break codes using but i think, this is better way. if we will not support old envs, then perhaps we can choose other way. sorry to my not better explanation. thanks. |
as a user i'd like to stimulate this issue — the real subject here is not "supporting c++17" but solving the ::filesystem ambiguity. until recently i was able to compile with c++17 (macOS and linux) but because of a compiler update the ::filesystem thing forces me to specifying down to c++14 and having adjust some things and to pepper #pragmas so the compiler does not flood the output with warnings (while still supporting the features). "transparent" c++17 usage would be very much appreciated! (and more and more 3rd party libs and example code are relying on c++17). |
As far as detecting if the compiler supports c++17 and std::filesystem this macro is defined when filesystem is available So we could probably use these across all compilers to get the right level of fallback. I could work on a PR that handles the fallback and also check to see if the final spec calls are 1:1 replacements of the experimental. see: |
@ofTheo if you are going to look into this, take into account that everything is mostly done all the differences between apis are already ifdefd and there's macros: OF_USING_STD_FS to enable one or the other. this was all working around a year ago but probably some final change in the final standard macros have broken the detection. it should be just a matter of changing a coupld of macros in ofFileUtils.h everything else should just work after that unless there's been more changes to the actual filesystem api but i doubt that's the case |
Thanks @arturoc !
That’s really helpful. Hopefully will be fairly minimal, but will try and test all the different cases.
|
Hi, How is the progress here? Is it possible now to use openFrameworks in c++17 on Mac? If I just change the compiler version and leave everything else as-is, I got a lot of the of_v0.11.0_osx_release |
Hi @2bbb With GNU++17, I get the following errors: With C++17, I get the following errors: If more details are interesting and needed, I can share the compiling log here. I noticed that there are some changes for |
@RodenLuo |
Thanks! I just changed that as well. It does not work on my project as there are errors coming from the ofxGui I used. But it does work on an empty project. Sorry that in my last post I only changed Deployment Target & C++ version in my project. |
poking this again... anything happening "behind the scenes" on this front? it is getting trickier as external libs are increasingly relying on C++17. it would be super great to be able to just have to specify -std=c++17 and have things running coherently. |
Speaking for Linux and gcc... could it actually be as easy as just doing that? Is there something wrong with this approach to use
I am currently running the testAllExamples.sh script, and it seems to all work so far. Except I don't have a webcam or speakers at the moment, so I cannot test these examples properly. But I don't really see why there would be an issue. Tested on Ubuntu 20.04 and Debian 10.9 |
Hi all, I was able to get the Visual Studio 2017 build working with c++17 with some really minimal changes off of master branch thanks to @2bbb 's recent fixes to the fs utils. I didn't realize I'd make a reference this way across forks, but the commit The only gotcha is you must add |
|
Just a note that C++17 would mean dropping macOS 10.14 from supported platforms. With macOS 12 coming out this Autumn it could be fair to drop 10.14 ( though that is still what I use ). I would be curious about whether it could be worth making OF 0.12.0 support only macOS 10.15 and up for the benefit of having C++17 on by default. yays/nays? 🙂 |
@ofTheo but why we would need to drop support for 10.14 (it is what I use too)?. Cant we support both and add some stuff to PG so it can automatically decide which version to use depending on your OS? |
Ah yes, you're right.
I think it could be done in the Project.xconf or CoreOF.xcconfig probably for Xcode and based on Availability.h Macros for makefiles.
|
Another nice possibility with OFW using C++17 |
Maybe it already deserves its own branch with changes from @2bbb and @themancalledjakob ? |
I would love to get the needed changes merged in soon for this. I'll use this issue as a reference but if anyone has working C++17 branches they are using it would be a big help if you could link to them here. Thanks! |
these work on linux for me. (tested on Debian 10/11 & Ubuntu 20.04) the commits could be cleaner though, and of course Windows & Mac are ignored. |
Thanks @themancalledjakob and everyone on this thread! For macOS I was able to get c++17 and std::filesystem working by only modifying the xcconfig of an example project and slightly tweaking the compile OF build phase. Starting with the current master or the nightly builds on the OF download page: 1. Add this to your
2. Change the first Run Script in Build Phases to:
What this does is allow the Project.xcconfig settings to overwrite the OFCore.xcconfig settings so when OF is compiled by script in the Run Script phase it uses the C++ version from Project.xcconfig @themancalledjakob I didn't end up needing to add the I will start a PR in a sec with these changes and then work on pulling the changes needed for Linux and Windows. |
Here is the branch: Compare to see the changes so far: Right now it supports cpp 17 for macOS only. Happy if people want to PR to that branch for other platforms. Once it is all working via CI I'll PR the main repo. |
Okay I can get similar functionality with the macOS makefiles. Though in order to be able to do C++17 and std::filesystem on a per project basis I use this approach. Curious what thoughts are on this. In a project or examples config.make I add this to the end:
In the config.osx.default.mk I change:
to
and then add this so we can override the std cpp version:
This results in the project and the core being built with c++17 and std::filesystem. Curious though if anyone sees anything problematic with the above? |
macOS and VS are working now in PR #6844 with a simpler approach than above. Feel free to PR this branch with other platforms: @oxillo would you be able to take a look at msys2 ? |
closed by #6844 |
🎉 |
WOWWW great work @ofTheo |
Amazing work! Thank you @ofTheo |
Very excited to have C++17 with openFrameworks. Great work @ofTheo! 👏 |
I just wanted to see if there were any ideas on how to best use C++17 (needed for one ofx that requires std::optional) but to still support mojave (10.14) by somehow changing std::filesystem for 10.14 users? I have things working now but with the minimum target of 10.15 I am getting some angry users... ;) |
@himwho I am actually working a bit more on this right now as we're not catching al the nuances with linux and C++ filesystem right now. For your situation I just tried an idea with the nightly builds ( at the bottom of the OF download page ) where we enable boost::fs and C++17, but then I get the ambiguous reference to filesystem error. If there is a way to resolve that then this is what I did:
I'm not sure if there is a way to have C++17 and declare |
@ofTheo I am a little out of the loop when it comes to the switch from Beyond that I guess I will look into how to elegantly use std namespace when 10.15+ and use boost namespace when 10.14 or below simply to handle support for I guess where i need to wrap my head is do I really want to support and package both and figure out how to test the client for which OS version they have to switch between the two? |
hmm @himwho - I am surprised you didn't get the If it did work then you could deploy that app to both 10.14 and 10.15+ systems. Was this with the 0.11.2 release or the nightly builds? Thanks! |
@ofTheo it was with latest OF on git commit , but just to make sure its clear i literally redeclared every usage of I havent tested on target devices yet but just was happy it compiled with target 10.14 and ran on my dev machine running 11.6 |
Ah okay - yeah I think that is the issue as we are defining boosts file system to If we has a different argument or namespace like
and
There is some interesting info on the detection stuff here: About to open a PR to fix the C++17 fs detection on linux and will link it here for reference. |
#7013 PR with some cpp17 filesystem fixes |
@ofTheo is there a clever way to detect which macOS version is available on runtime?
we just really need to fallback to boost if <10.14 and otherwise all the conditionals you did were good to go
|
@himwho the problem with all the preprocessor stuff like I think for your case you would simply want it to use the boost filesystem no matter what, but as mentioned above for that to work we would need to replace all the instances of eg:
This might be good practice during transitions like this but curious what others think? |
@ofTheo also I expanded the conditional to catch my case: 63119b9#diff-67461da5aefff862c534547a36c8a8bbfd65fd0985c30f9a69d21a3a0fd815a4L456
i opted for |
Let's discussion about C++17.
The text was updated successfully, but these errors were encountered: