To help us debug your issue please explain:
Hello,
First off, I would like to say thank you to everyone involved in this awesome project.
I have read the how-to article about managing the C++ standard, where it is stated that "By default Conan will detect the default standard of your compiler to not generate different binary packages."
My conan package uses a custom build system for which I need to manually parse and pass the CXX flags.
I caught the error when I tried to pass a flag for the standard with the following code:
if "gnu" in self.settings.cppstd:
cxx_flags.append("-std=gnu++%s" % str(self.settings.cppstd).replace("gnu", ""))
else:
cxx_flags.append("-std=c++%s" % str(self.settings.cppstd))
```python
cxx_flags.append("-std=c++%s" % str(self.settings.cppstd))
TypeError: __str__ returned non-string (type NoneType)
Upon further debugging I spotted the following custom warning being outputted:
```python
if not self.settings.cppstd:
self.output.warn("cppstd empty")
My recipe specified cppstd in the settings and I did not pass a command line argument and the settings.cppstd was None instead of a detected default value.
I ended up with the following temporary workaround in my configure method:
if not self.settings.cppstd:
self.output.warn("cppstd empty, setting default")
from conans.client.build.cppstd_flags import cppstd_default
self.settings.cppstd = cppstd_default(self.settings.get_safe("compiler"),
self.settings.get_safe("compiler.version"))
I would assume that the default value should be set for the user as well as internally when no cppstd command line argument is given but it is specified in the recipe.
For the record, not having the cppstd specified in the recipe, (properly) throws an exception on the following line:
if not self.settings.cppstd:
ConanException: 'settings.cppstd' doesn't exist
Software information:
I'm currently using Conan version 1.2.0 on
ProductName: Mac OS X
ProductVersion: 10.13.3
BuildVersion: 17D102
with
Xcode 9.2
Build version 9C40b
and Python 3.6.4 installed from brew
Hi! I'm glad you like the project, many thanks.
About the cppstd, following the Conan model or correct way to do the things, you should declare the cppstd in your profile (or default profile). In general, forcing a setting in the configure method is not a good idea. This way, you can control the different packages generated by changing the profile.
In your build method, if not self.settings.cppstd you can omit the flag -std, and the compiler will use the default. Otherwise, adjust it.
So, the sentence: By default Conan will detect the default standard of your compiler to not generate different binary packages. means that you can generate packages without specifying any cppstd setting value (so no -std flag will be used in your compilation), but if later, you specify a cppstd value, if this value is the default of your compiler, the package id will be the same as the previous generated package.
About from conans.client.build.cppstd_flags import cppstd_default, it is ok, but please, take into account that we could break any function not documented in the reference: build helpers, tools module, conanfile methods and vars and so on.
Hope it makes sense for you!
Hi @lasote,
Thank you very much for the quick reply.
Also thank you for the tip about removing the -std flag.
I understand that the cppstd_default function might change at any time and that was just a quick fix I made after examining conan's source code.
Still, I do think that IF the author specified cppstd in the conanfile, that would make it mandatory for that recipe and an error should be properly thrown if it is not supplied.
Similarly how, for example, if I intentionally remove the arch from my conan profile and try a build, conan reports the following error message:
ERROR: Conanfile: 'settings.arch' value not defined
The cppstd is a special case, it has to have a default None value because the None means: "The compiler default".
Also, the None settings do not require to be set explicitly, its value is None by default. This allows a smoother introduction of such new settings (cppstd was introduced very recently)
Hi @lasote, @memsharded,
Following your last two comments, I have adjusted my code not to use the cppstd_default function and I have adjusted the appending of the flag to the following:
if self.settings.get_safe('cppstd'):
if "gnu" in self.settings.cppstd:
cxx_flags.append("-std=gnu++%s" % str(self.settings.cppstd).replace("gnu", ""))
else:
cxx_flags.append("-std=c++%s" % str(self.settings.cppstd))
else:
self.output.info("cppstd not explicitly defined, using default")
My question was answered and the issue can be closed as it is in fact the intended behavior. However I would suggest adding to the documentation that the cppstd has a default value of None.
Hi @T1T4N!
Yes, there is already an issue opened in the docs repo to document this: conan-io/docs#474
Awesome! Once again, a big thank you to everyone who is involved with the development of this project.
Great!
You might also try the generic conan function:
cppstd_flag = cppstd_flag(conanfile.settings.get_safe("compiler"),
conanfile.settings.get_safe("compiler.version"),
conanfile.settings.get_safe("cppstd"))
Most helpful comment
Awesome! Once again, a big thank you to everyone who is involved with the development of this project.