Modify

Ticket #7671 (closed Bugs: fixed)

Opened 17 months ago

Last modified 15 months ago

Error including boost/thread.hpp header on iOS

Reported by: Dr.Schroers@… Owned by: viboes
Milestone: Boost 1.53.0 Component: thread
Version: Boost 1.52.0 Severity: Problem
Keywords: Cc: viboes

Description

System configuration: MacOS X 10.8.2, Xcode 4.5.2, iOS SDK 6.0, iOS 6.0.1 installed on device, boost v1.52.0 compiled via the script at  http://gitorious.org/~galbraithjoseph/boostoniphone/galbraithjosephs-boostoniphone All latest patches and updates installed.

Setup: I have successfully built the boost.framework using the above script and included it into an iOS project with a test target. One test case class includes the file <boost.thread.hpp>.

Expected behavior: The test target is compiled and run on the device.

Observed behavior: Compilation fails with three times the error message "Semantic issue - Constexpr function never produces a constant expression". In all three cases the issue appears to be due to the same piece of code included in the following hierarchy:

boost/thread.hpp line 13:
boost/thread/thread.hpp line 17:
boost/thread/pthread/thread_data.hpp line 11:
boost/thread/locks.hpp line 11:
boost/chrono/time_point.hpp line 18:
boost/chrono/duration.hpp line 33:
boost/chrono/duration.hpp lines 355/363/371:
limits line 443

Comment: This applies only to the thread.hpp header. In the test case object I have also included the <boost.regex.hpp> and the <boost/lambda/lambda.hpp> headers. These two are correctly included and the corresponding test cases work as expected. Only the thread.hpp header shows the issue described above.

Attachments

BoostTest.tgz Download (8.0 KB) - added by Wolfram Schroers <Dr.Schroers@…> 17 months ago.
Sample project that demonstrates the error
libcpp_c11_numeric_limits.patch Download (401 bytes) - added by Hyeon-bin Jeong <tuhertz@…> 17 months ago.
Set BOOST_NO_CXX11_NUMERIC_LIMITS for Xcode 4.5 to fix compilation error.

Change History

comment:1 Changed 17 months ago by viboes

Could you show the exact command and the compiler error and the source file?

comment:2 follow-up: ↓ 4 Changed 17 months ago by viboes

I guess that you should link with libc++ which is C++11 aware.

comment:3 Changed 17 months ago by Wolfram Schroers <Dr.Schroers@…>

I could not access the specific command the Xcode IDE issues (I will try it with xcodebuild on the command line later), but the error message in the header boost/chrono/duration.hpp says "Non-constexpr function 'max' cannot be used in constant expression".

I just noticed that the issue goes away if I remove BOOST_CHRONO_LIB_CONSTEXPR in lines 353, 361 and 369 in the file boost/chrono/duration.hpp and the project compiles fine.

comment:4 in reply to: ↑ 2 ; follow-up: ↓ 5 Changed 17 months ago by Wolfram Schroers <Dr.Schroers@…>

Replying to viboes: The project uses C++11 and the compiler supports the constexpr statement. The issue seems to be that the boost-header assumes that std::numeric_limits<float>::max is a compile-time constant which is not the case on the given platform.

comment:5 in reply to: ↑ 4 ; follow-up: ↓ 6 Changed 17 months ago by viboes

Replying to Wolfram Schroers <Dr.Schroers@…>:

Replying to viboes: The project uses C++11 and the compiler supports the constexpr statement. The issue seems to be that the boost-header assumes that std::numeric_limits<float>::max is a compile-time constant which is not the case on the given platform.

As said before you need to use a std lib compatible with C++11. libc++ is free and works well with clang.

comment:6 in reply to: ↑ 5 ; follow-up: ↓ 7 Changed 17 months ago by Wolfram Schroers <Dr.Schroers@…>

Replying to viboes: [...]

As said before you need to use a std lib compatible with C++11. libc++ is free and works well with clang.

In the default answer of  http://stackoverflow.com/questions/12865226/in-xcode-4-5-what-is-compiler-default-for-c-standard-library-and-c-lan?rq=1 this post there is specific code to test for stdlib++ vs. lib++. The output for me is:

Using libc++
Language mode = gnu++11

I am not sure how to proceed in this case, because it looks like I am already using libc++.

comment:7 in reply to: ↑ 6 Changed 17 months ago by viboes

Replying to Wolfram Schroers <Dr.Schroers@…>:

Replying to viboes: [...]

As said before you need to use a std lib compatible with C++11. libc++ is free and works well with clang.

In the default answer of  http://stackoverflow.com/questions/12865226/in-xcode-4-5-what-is-compiler-default-for-c-standard-library-and-c-lan?rq=1 this post there is specific code to test for stdlib++ vs. lib++. The output for me is:

Using libc++
Language mode = gnu++11

I am not sure how to proceed in this case, because it looks like I am already using libc++.

Hrrr. I'm using MacOS 10.7.5 and when I compile for C++11 and use libc++ I don't get any error.

Which version of libc++ are you using? Which version of the compiler?

comment:8 follow-up: ↓ 9 Changed 17 months ago by viboes

The source of libc++ <limits< contains the following

template <class _Tp>
class _LIBCPP_VISIBLE numeric_limits
    : private __libcpp_numeric_limits<typename remove_cv<_Tp>::type>
{
    typedef __libcpp_numeric_limits<typename remove_cv<_Tp>::type> __base;
    typedef typename __base::type type;
public:
    static _LIBCPP_CONSTEXPR const bool is_specialized = __base::is_specialized;
    _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type min() _NOEXCEPT {return __base::min();}
    _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type max() _NOEXCEPT {return __base::max();}

with specializations for float, double and long double

template <>
class __libcpp_numeric_limits<float, true>
{
protected:
...
    _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type min() _NOEXCEPT {return __FLT_MIN__;}
    _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type max() _NOEXCEPT {return __FLT_MAX__;}

I don't see why then the error occurs. Please could you verify the code inside <limits> on your configuration?

comment:9 in reply to: ↑ 8 Changed 17 months ago by Wolfram Schroers <Dr.Schroers@…>

Replying to viboes:

In my case the file contains:

template <class _Tp>
class _LIBCPP_VISIBLE numeric_limits
    : private __libcpp_numeric_limits<typename remove_cv<_Tp>::type>
{
    typedef __libcpp_numeric_limits<typename remove_cv<_Tp>::type> __base;
    typedef typename __base::type type;
public:
    static const bool is_specialized = __base::is_specialized;
    _LIBCPP_INLINE_VISIBILITY static type min() _NOEXCEPT {return __base::min();}
    _LIBCPP_INLINE_VISIBILITY static type max() _NOEXCEPT {return __base::max();}
    _LIBCPP_INLINE_VISIBILITY static type lowest() _NOEXCEPT {return __base::lowest();}

I have created a minimal Xcode project file that shows the error when compiling and attached the file to this report. The version numbers are stated in the original report. Hope that helps ...

Changed 17 months ago by Wolfram Schroers <Dr.Schroers@…>

Sample project that demonstrates the error

comment:10 follow-up: ↓ 11 Changed 17 months ago by rkb

Hello -- came across this thread during search for issue.

From my xcode experiment to build basic thread program, ran into same issue.

On my end - I switched to C++ Standard Library libstdc++ and was able to compile my program. Earlier errors were the same as above.

comment:11 in reply to: ↑ 10 Changed 17 months ago by Wolfram Schroers <Dr.Schroers@…>

Replying to rkb: [...]

On my end - I switched to C++ Standard Library libstdc++ and was able to compile my program. Earlier errors were the same as above.

I have just explicitly added libstdc++.dylib to the "Link Binary With Libraries" section of the "Build Phases" tab. The result is unchanged, however. As far as I can see, the .dylib library does not come with a separate header file and the issue is in the header limits.

Could you be a little more explicit in describing how you switched the library?

comment:12 Changed 17 months ago by rkb

Hello. My apologies. To detail a bit more:

Under project build settings in xcode, try searching for "lib" via the search field. Under Apple LLVM compiler 4.1, a field called C++ Standard Library appears. Just click this to toggle to libstdc++ (GNU C++ standard library).

It was after this change that I was able to successfully compile. Please let me know if this is helpful.

comment:13 Changed 17 months ago by tuhertz

libc++ in Xcode is outdated , so constexpr keyword missing in limits header. It should work fine if you change C++ language dialect to C++98 or GNU++98. If you want to compile Boost with C++11 dialect, you need to get latest headers from libc++ trunk.

comment:14 Changed 17 months ago by Wolfram Schroers <Dr.Schroers@…>

Changing the libc++ to libstdc++ in the "C++ Standard Library" row in the "Build Settings" yields 50+ linker errors. This does not appear to work.

I also do not feel comfortable installing custom headers for what feels like a basic system library. There may be potential side effects, including the danger that some modification under the hood could endanger app store approval or something ...

The only practical solution I have found so far is to edit the boost header <boost/thread.hpp> and remove the BOOST_CHRONO_LIB_CONSTEXPR keyword.

comment:15 Changed 17 months ago by tuhertz

If you don't change C++ Language Dialect in Build Setting, you will get errors no matter which library you choose. Because Boost knows your compiler supports C+11 constexpr, but both libc++ and libstdc++ don't implement it in limits header. Changing language dialect to C++98 is easiest fix if you don't have to build Boost with C++11.

I think building with custom limits header won't make any trouble, because limits is header only library and all classes are empty classes. All members are static or inline methods, so it will just replace with constants in Boost library in compilation time. You don't need to replacing system header, just adding it's location to Header Search Path in build settings, it takes precedence over system header.

libc++ has been updated in Xcode 4.6 developer preview and i confirm limit header is updated also, so this problem will be gone in next Xcode release.

Changed 17 months ago by Hyeon-bin Jeong <tuhertz@…>

Set BOOST_NO_CXX11_NUMERIC_LIMITS for Xcode 4.5 to fix compilation error.

comment:16 Changed 17 months ago by viboes

  • Cc viboes added
  • Owner changed from anthonyw to johnmaddock
  • Component changed from thread to config

comment:17 Changed 17 months ago by Dr. Wolfram Schroers <Dr.Schroers@…>

Thanks for your responses. In my situation switching to Xcode 4.6 is the best choice at the moment. The alternative patch file is also a good alternative, but I'll go with switching to the developer preview for now.

comment:18 Changed 16 months ago by me@…

You can also add #define BOOST_THREAD_DONT_USE_CHRONO before including the Boost headers for this error to go away.

comment:19 Changed 15 months ago by viboes

  • Owner changed from johnmaddock to viboes
  • Status changed from new to assigned
  • Component changed from config to thread

[82391] Should have fixed this issue.

comment:20 Changed 15 months ago by viboes

  • Status changed from assigned to closed
  • Resolution set to fixed
  • Milestone changed from To Be Determined to Boost 1.53.0
View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.