|
[Sponsors] |
March 25, 2016, 16:49 |
C++11 in OF
|
#1 |
Member
Join Date: Aug 2015
Posts: 37
Rep Power: 11 |
I'm developing my own extensions to OpenFOAM and I'd like to user C++11 features. According to another thread [ http://www.cfd-online.com/Forums/ope...-features.html ], OF3.0 is built with native support for C++14. That kind of agrees with the release announcement:
"The release benefits from improved compatibility between the C++ compilers of GCC (4.5+, tested up to v5.2), Intel ICC (15.0.3+) and Clang (3.6+, 3.7 recommended), in line with the ISO 14882:2014(E) Programming Language C++ (C++14) Standard. Over time, we expect to introduce new features in the C++14 Standard to OpenFOAM, paying attention to compatibility of older versions of C++ compilers used in long-term supported Linux operating systems for high availability computers where possible." [ http://www.openfoam.org/version3.0.0/ ]...however, when I try to use C++11 features in my code and compile with wmake, I get warnings and errors. I've grep'd through the source code... it appears that the "-std=c++0x" flag is set under some circumstances (which my code doesn't seem to fall under), and the '-std=c++1y" flag is never set. Reading the quotation above more closely, I don't think that they actually state that the code is compiled with C++14. I know that I can make OF compile with a different C++ standard [ see http://www.sourceflux.de/blog/compil...upport-c11c0x/ , http://www.sourceflux.de/blog/enabli...cking-options/ ], but I will be running my code on other machines where I'm not able to re-compile OpenFOAM myself. Is there a trick that I'm missing - is there a way that I can use C++11 features in my own code and link to standard OF libraries? I've found that enabling C++11 for my own code without recompiling OF leads to problems at the linking stage, and I'm not able to re-compile OF on all of the machines which I will be using. |
|
March 26, 2016, 13:55 |
|
#2 |
Member
Join Date: Aug 2015
Posts: 37
Rep Power: 11 |
I've found the answer.
I was able to make my own program compile with C++11 support in OF3.0.1 as follows:
For comparison, the method described at http://www.sourceflux.de/blog/compil...upport-c11c0x/ does not work for me. |
|
March 26, 2016, 14:25 |
|
#3 |
Retired Super Moderator
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,982
Blog Entries: 45
Rep Power: 128 |
Greetings knuckles,
Many thanks for sharing! I had seen this thread of yours earlier today, but I didn't have the time to test the following myself. If you didn't need to rebuild OpenFOAM and you only had to update the respective c++ rules file, then you can simply make the following change in your application/library "Make/options" files: Code:
EXE_INC = -std=c++0x \ -I..... \ Best regards, Bruno
__________________
|
|
March 26, 2016, 17:05 |
|
#4 | |
Member
Join Date: Aug 2015
Posts: 37
Rep Power: 11 |
Quote:
|
||
July 11, 2017, 05:15 |
|
#5 |
New Member
Thien Xuan Dinh
Join Date: Jul 2014
Location: Japan
Posts: 8
Rep Power: 12 |
It is a late thank. But it is great help.
|
|
|
|