COCKOS
CONFEDERATED FORUMS
Cockos : REAPER : NINJAM : Forums
Forum Home : Register : FAQ : Members List : Search :
Old 01-30-2017, 01:19 PM   #1
br_ck1
Human being with feelings
 
Join Date: Dec 2015
Posts: 39
Default Xcode and std::stof

Hello,

I'm having a very annoying issue in Xcode7.
I use in my c++ code the std::stof() function. It works fine on Windows VisualStudio but on macOS Xcode it states that stof() is not a member function of std::

I use Clang 1.0 as a compiler.

Anyone has a hint please? I would like to continue using stof() in my code...

Thank you in advance,
br_ck1 is offline   Reply With Quote
Old 01-30-2017, 01:24 PM   #2
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
Default

Quote:
Originally Posted by br_ck1 View Post
I use Clang 1.0 as a compiler.
Wow! How old is that?!

std::stof is a C++11 standard library function which your compiler might not support at all. If it however does support C++11, you will need to enable it separately in your build settings. Newer Visual Studio versions (since VS2010) have C++11 always enabled.
__________________
I am no longer part of the REAPER community. Please don't contact me with any REAPER-related issues.
Xenakios is offline   Reply With Quote
Old 01-30-2017, 01:34 PM   #3
br_ck1
Human being with feelings
 
Join Date: Dec 2015
Posts: 39
Default

Quote:
Originally Posted by Xenakios View Post
Wow! How old is that?!

std::stof is a C++11 standard library function which your compiler might not support at all. If it however does support C++11, you will need to enable it separately in your build settings. Newer Visual Studio versions (since VS2010) have C++11 always enabled.
Thank you for your feedback, I use that compiler because it is recommended for use with WDL-OL as far as I know (Martin Finke's blog) :

COMPILER = com.apple.compilers.llvm.clang.1_0

Or maybe it is ok to use a different one ?

For example : COMPILER = com.apple.compilers.gcc.4_2

Any hint, suggestion, explanation is welcome, I'm relatively newbe to cross-platform wdl development
br_ck1 is offline   Reply With Quote
Old 01-30-2017, 01:45 PM   #4
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
Default

Quote:
Originally Posted by br_ck1 View Post
Thank you for your feedback, I use that compiler because it is recommended for use with WDL-OL as far as I know (Martin Finke's blog) :

COMPILER = com.apple.compilers.llvm.clang.1_0

Or maybe it is ok to use a different one ?

For example : COMPILER = com.apple.compilers.gcc.4_2

Any hint, suggestion, explanation is welcome, I'm relatively newbe to cross-platform wdl development
Definitely not gcc, that's no longer supported by Apple. Anyway, I suppose XCode should use the latest installed Clang/LLVM compiler anyway. (I don't remember what the Clang versions were back in XCode 7, I am using XCode 8.2 myself currently.) You will however need to separately enable C++11 if you want to use the language features or the library from that.

What macOS versions does your code need to support? The C++11 standard library can't be used for building for older versions than macOS 10.7.
__________________
I am no longer part of the REAPER community. Please don't contact me with any REAPER-related issues.
Xenakios is offline   Reply With Quote
Old 01-30-2017, 01:56 PM   #5
br_ck1
Human being with feelings
 
Join Date: Dec 2015
Posts: 39
Default

I put the target to sdk 10.5 , but I think I can change it to 10.7 if needed to enable c++11 support.

New versions of LLVM compilers come embedded with new versions of Xcode or I need to intall it separately?
br_ck1 is offline   Reply With Quote
Old 01-30-2017, 02:05 PM   #6
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
Default

Quote:
Originally Posted by br_ck1 View Post
I put the target to sdk 10.5 , but I think I can change it to 10.7 if needed to enable c++11 support.

New versions of LLVM compilers come embedded with new versions of Xcode or I need to intall it separately?
Clang/LLVM is the official compiler for XCode and comes installed with it. Note that besides changing the target sdk and OS version for deployment, you will need to change C++ language dialect and the used standard library versions too.
__________________
I am no longer part of the REAPER community. Please don't contact me with any REAPER-related issues.
Xenakios is offline   Reply With Quote
Old 01-30-2017, 02:12 PM   #7
br_ck1
Human being with feelings
 
Join Date: Dec 2015
Posts: 39
Default

Quote:
Originally Posted by Xenakios View Post
Clang/LLVM is the official compiler for XCode and comes installed with it. Note that besides changing the target sdk and OS version for deployment, you will need to change C++ language dialect and the used standard library versions too.
Ok. If I set both to 10.7 and in the same "common.xcconfig" file I enable :

CLANG_CXX_LANGUAGE_STANDARD = c++0x
CLANG_CXX_LIBRARY = libc++

Will this be sufficient to enable c++11 and consequently std::stof ?
br_ck1 is offline   Reply With Quote
Old 01-30-2017, 02:56 PM   #8
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
Default

Quote:
Originally Posted by br_ck1 View Post
Ok. If I set both to 10.7 and in the same "common.xcconfig" file I enable :

CLANG_CXX_LANGUAGE_STANDARD = c++0x
CLANG_CXX_LIBRARY = libc++

Will this be sufficient to enable c++11 and consequently std::stof ?
CLANG_CXX_LANGUAGE_STANDARD = c++0x should probably be CLANG_CXX_LANGUAGE_STANDARD = c++11 instead. c++0x used to work but might now be obsolete.
__________________
I am no longer part of the REAPER community. Please don't contact me with any REAPER-related issues.
Xenakios is offline   Reply With Quote
Old 01-30-2017, 11:41 PM   #9
br_ck1
Human being with feelings
 
Join Date: Dec 2015
Posts: 39
Default

Quote:
Originally Posted by Xenakios View Post
CLANG_CXX_LANGUAGE_STANDARD = c++0x should probably be CLANG_CXX_LANGUAGE_STANDARD = c++11 instead. c++0x used to work but might now be obsolete.
Thank you so much Xenakios for your help !

Just one thing, in addition to :
sdk = 10.7
base sdk = 10.7
CLANG_CXX_LANGUAGE_STANDARD = c++0x / c++11
CLANG_CXX_LIBRARY = libc++
...and MANTAINING : COMPILER = com.apple.compilers.llvm.clang.1_0

Are there other things to change/add ?

Changing this stuff cause some error messages during compiling?

You used the same method/workaround to enable c++11 (if you have it enabled)?

Thank you
br_ck1 is offline   Reply With Quote
Old 01-31-2017, 12:08 AM   #10
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
Default

Quote:
Originally Posted by br_ck1 View Post
Thank you so much Xenakios for your help !

Just one thing, in addition to :
sdk = 10.7
base sdk = 10.7
CLANG_CXX_LANGUAGE_STANDARD = c++0x / c++11
CLANG_CXX_LIBRARY = libc++
...and MANTAINING : COMPILER = com.apple.compilers.llvm.clang.1_0

Are there other things to change/add ?

Changing this stuff cause some error messages during compiling?

You used the same method/workaround to enable c++11 (if you have it enabled)?

Thank you
I've set the stuff in the XCode GUI, so I am not 100% sure how everything should be set up with the text files. What errors are you getting? Did you drop the compiler line? Maybe that makes it use the latest compiler...
__________________
I am no longer part of the REAPER community. Please don't contact me with any REAPER-related issues.
Xenakios is offline   Reply With Quote
Old 01-31-2017, 01:24 PM   #11
br_ck1
Human being with feelings
 
Join Date: Dec 2015
Posts: 39
Default

Quote:
Originally Posted by Xenakios View Post
I've set the stuff in the XCode GUI, so I am not 100% sure how everything should be set up with the text files. What errors are you getting? Did you drop the compiler line? Maybe that makes it use the latest compiler...
>What errors are you getting?
I didn't try that procedure yet, currently I'm away, so I was just asking if that change could cause some incompatibilities when compiling. The only error I had before was the missing std::stof function, because with sdk 10.5 c++11 is not supported...
br_ck1 is offline   Reply With Quote
Old 01-31-2017, 02:00 PM   #12
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
Default

Quote:
Originally Posted by br_ck1 View Post
>What errors are you getting?
I didn't try that procedure yet, currently I'm away, so I was just asking if that change could cause some incompatibilities when compiling. The only error I had before was the missing std::stof function, because with sdk 10.5 c++11 is not supported...
If things don't start working, as a blunt fix, you could of course just implement std::stof for non-Windows platforms yourself. (Generally it's not recommended to change/add stuff in the std:: namespace but sometimes it's an appropriate quick fix.)

edit : At least with the Visual Studio C++ standard libary, std::stof is just a wrapper with some exception throwing when errors happen for the C library function strtof.
__________________
I am no longer part of the REAPER community. Please don't contact me with any REAPER-related issues.
Xenakios is offline   Reply With Quote
Old 01-31-2017, 02:18 PM   #13
br_ck1
Human being with feelings
 
Join Date: Dec 2015
Posts: 39
Default

Quote:
Originally Posted by Xenakios View Post
If things don't start working, as a blunt fix, you could of course just implement std::stof for non-Windows platforms yourself. (Generally it's not recommended to change/add stuff in the std:: namespace but sometimes it's an appropriate quick fix.)

edit : At least with the Visual Studio C++ standard libary, std::stof is just a wrapper with some exception throwing when errors happen for the C library function strtof.
Ok, thank you again, I'll try very soon !

...as stof, strtof too seems to be c++11 only...
br_ck1 is offline   Reply With Quote
Old 01-31-2017, 04:52 PM   #14
Xenakios
Human being with feelings
 
Xenakios's Avatar
 
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
Default

Quote:
Originally Posted by br_ck1 View Post
strtof too seems to be c++11 only...
Should not be since it's not even a C++ function but just a C function.
__________________
I am no longer part of the REAPER community. Please don't contact me with any REAPER-related issues.
Xenakios is offline   Reply With Quote
Old 02-01-2017, 12:18 AM   #15
Tale
Human being with feelings
 
Tale's Avatar
 
Join Date: Jul 2008
Location: The Netherlands
Posts: 3,645
Default

Quote:
Originally Posted by Xenakios View Post
Should not be since it's not even a C++ function but just a C function.
Nevertheless it would seem that strtof() was introduced in C++11:

http://www.cplusplus.com/reference/cstdlib/strtof/
http://en.cppreference.com/w/cpp/string/byte/strtof

But strtod() is older, so OP could probably use that, or else atof().
Tale is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 01:39 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.