Boost C++ Libraries: Ticket #7671: Error including boost/thread.hpp header on iOS https://svn.boost.org/trac10/ticket/7671 <p> <strong>System configuration:</strong> 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 <a class="ext-link" href="http://gitorious.org/~galbraithjoseph/boostoniphone/galbraithjosephs-boostoniphone"><span class="icon">​</span>http://gitorious.org/~galbraithjoseph/boostoniphone/galbraithjosephs-boostoniphone</a> All latest patches and updates installed. </p> <p> <strong>Setup:</strong> 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 <code>&lt;boost.thread.hpp&gt;</code>. </p> <p> <strong>Expected behavior:</strong> The test target is compiled and run on the device. </p> <p> <strong>Observed behavior:</strong> 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: </p> <pre class="wiki">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 </pre><p> <strong>Comment:</strong> This applies only to the <code>thread.hpp</code> header. In the test case object I have also included the <code>&lt;boost.regex.hpp&gt;</code> and the <code>&lt;boost/lambda/lambda.hpp&gt;</code> headers. These two are correctly included and the corresponding test cases work as expected. Only the <code>thread.hpp</code> header shows the issue described above. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/7671 Trac 1.4.3 viboes Fri, 09 Nov 2012 14:15:07 GMT <link>https://svn.boost.org/trac10/ticket/7671#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7671#comment:1</guid> <description> <p> Could you show the exact command and the compiler error and the source file? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Fri, 09 Nov 2012 14:20:14 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7671#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7671#comment:2</guid> <description> <p> I guess that you should link with libc++ which is C++11 aware. </p> </description> <category>Ticket</category> </item> <item> <author>Wolfram Schroers <Dr.Schroers@…></author> <pubDate>Fri, 09 Nov 2012 15:47:29 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7671#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7671#comment:3</guid> <description> <p> I could not access the specific command the Xcode IDE issues (I will try it with <code>xcodebuild</code> on the command line later), but the error message in the header <code>boost/chrono/duration.hpp</code> says "Non-constexpr function 'max' cannot be used in constant expression". </p> <p> I just noticed that the issue goes away if I remove <code>BOOST_CHRONO_LIB_CONSTEXPR</code> in lines 353, 361 and 369 in the file <code>boost/chrono/duration.hpp</code> and the project compiles fine. </p> </description> <category>Ticket</category> </item> <item> <author>Wolfram Schroers <Dr.Schroers@…></author> <pubDate>Fri, 09 Nov 2012 15:54:38 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7671#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7671#comment:4</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/7671#comment:2" title="Comment 2">viboes</a>: The project uses C++11 and the compiler supports the <code>constexpr</code> statement. The issue seems to be that the boost-header assumes that <code>std::numeric_limits&lt;float&gt;::max</code> is a compile-time constant which is not the case on the given platform. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Fri, 09 Nov 2012 17:06:35 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7671#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7671#comment:5</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/7671#comment:4" title="Comment 4">Wolfram Schroers &lt;Dr.Schroers@…&gt;</a>: </p> <blockquote class="citation"> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/7671#comment:2" title="Comment 2">viboes</a>: The project uses C++11 and the compiler supports the <code>constexpr</code> statement. The issue seems to be that the boost-header assumes that <code>std::numeric_limits&lt;float&gt;::max</code> is a compile-time constant which is not the case on the given platform. </p> </blockquote> <p> As said before you need to use a std lib compatible with C++11. libc++ is free and works well with clang. </p> </description> <category>Ticket</category> </item> <item> <author>Wolfram Schroers <Dr.Schroers@…></author> <pubDate>Sat, 10 Nov 2012 19:25:19 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7671#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7671#comment:6</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/7671#comment:5" title="Comment 5">viboes</a>: [...] </p> <blockquote class="citation"> <p> As said before you need to use a std lib compatible with C++11. libc++ is free and works well with clang. </p> </blockquote> <p> In the default answer of <a class="ext-link" href="http://stackoverflow.com/questions/12865226/in-xcode-4-5-what-is-compiler-default-for-c-standard-library-and-c-lan?rq=1"><span class="icon">​</span>http://stackoverflow.com/questions/12865226/in-xcode-4-5-what-is-compiler-default-for-c-standard-library-and-c-lan?rq=1</a> this post there is specific code to test for stdlib++ vs. lib++. The output for me is: </p> <pre class="wiki">Using libc++ Language mode = gnu++11 </pre><p> I am not sure how to proceed in this case, because it looks like I am already using <code>libc++</code>. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sat, 10 Nov 2012 20:49:01 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7671#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7671#comment:7</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/7671#comment:6" title="Comment 6">Wolfram Schroers &lt;Dr.Schroers@…&gt;</a>: </p> <blockquote class="citation"> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/7671#comment:5" title="Comment 5">viboes</a>: [...] </p> <blockquote class="citation"> <p> As said before you need to use a std lib compatible with C++11. libc++ is free and works well with clang. </p> </blockquote> <p> In the default answer of <a class="ext-link" href="http://stackoverflow.com/questions/12865226/in-xcode-4-5-what-is-compiler-default-for-c-standard-library-and-c-lan?rq=1"><span class="icon">​</span>http://stackoverflow.com/questions/12865226/in-xcode-4-5-what-is-compiler-default-for-c-standard-library-and-c-lan?rq=1</a> this post there is specific code to test for stdlib++ vs. lib++. The output for me is: </p> <pre class="wiki">Using libc++ Language mode = gnu++11 </pre><p> I am not sure how to proceed in this case, because it looks like I am already using <code>libc++</code>. </p> </blockquote> <p> Hrrr. I'm using MacOS 10.7.5 and when I compile for C++11 and use libc++ I don't get any error. </p> <p> Which version of libc++ are you using? Which version of the compiler? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Sat, 10 Nov 2012 23:01:29 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7671#comment:8 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7671#comment:8</guid> <description> <p> The source of libc++ &lt;limits&lt; contains the following </p> <pre class="wiki">template &lt;class _Tp&gt; class _LIBCPP_VISIBLE numeric_limits : private __libcpp_numeric_limits&lt;typename remove_cv&lt;_Tp&gt;::type&gt; { typedef __libcpp_numeric_limits&lt;typename remove_cv&lt;_Tp&gt;::type&gt; __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();} </pre><p> with specializations for float, double and long double </p> <pre class="wiki">template &lt;&gt; class __libcpp_numeric_limits&lt;float, true&gt; { 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__;} </pre><p> I don't see why then the error occurs. Please could you verify the code inside &lt;limits&gt; on your configuration? </p> </description> <category>Ticket</category> </item> <item> <author>Wolfram Schroers <Dr.Schroers@…></author> <pubDate>Sun, 11 Nov 2012 07:13:56 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7671#comment:9 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7671#comment:9</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/7671#comment:8" title="Comment 8">viboes</a>: </p> <p> In my case the file contains: </p> <pre class="wiki"> template &lt;class _Tp&gt; class _LIBCPP_VISIBLE numeric_limits : private __libcpp_numeric_limits&lt;typename remove_cv&lt;_Tp&gt;::type&gt; { typedef __libcpp_numeric_limits&lt;typename remove_cv&lt;_Tp&gt;::type&gt; __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();} </pre><p> 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 ... </p> </description> <category>Ticket</category> </item> <item> <author>Wolfram Schroers <Dr.Schroers@…></author> <pubDate>Sun, 11 Nov 2012 07:14:43 GMT</pubDate> <title>attachment set https://svn.boost.org/trac10/ticket/7671 https://svn.boost.org/trac10/ticket/7671 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">BoostTest.tgz</span> </li> </ul> <p> Sample project that demonstrates the error </p> Ticket rkb Tue, 13 Nov 2012 01:23:00 GMT <link>https://svn.boost.org/trac10/ticket/7671#comment:10 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7671#comment:10</guid> <description> <p> Hello -- came across this thread during search for issue. </p> <p> From my xcode experiment to build basic thread program, ran into same issue. </p> <p> On my end - I switched to C++ Standard Library libstdc++ and was able to compile my program. Earlier errors were the same as above. </p> </description> <category>Ticket</category> </item> <item> <author>Wolfram Schroers <Dr.Schroers@…></author> <pubDate>Tue, 13 Nov 2012 09:45:02 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7671#comment:11 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7671#comment:11</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/7671#comment:10" title="Comment 10">rkb</a>: [...] </p> <blockquote class="citation"> <p> On my end - I switched to C++ Standard Library libstdc++ and was able to compile my program. Earlier errors were the same as above. </p> </blockquote> <p> I have just explicitly added <code>libstdc++.dylib</code> to the "Link Binary With Libraries" section of the "Build Phases" tab. The result is unchanged, however. As far as I can see, the <code>.dylib</code> library does not come with a separate header file and the issue is in the header <code>limits</code>. </p> <p> Could you be a little more explicit in describing how you switched the library? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>rkb</dc:creator> <pubDate>Tue, 13 Nov 2012 12:46:09 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7671#comment:12 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7671#comment:12</guid> <description> <p> Hello. My apologies. To detail a bit more: </p> <p> 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). </p> <p> It was after this change that I was able to successfully compile. Please let me know if this is helpful. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>tuhertz</dc:creator> <pubDate>Tue, 13 Nov 2012 14:23:45 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7671#comment:13 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7671#comment:13</guid> <description> <p> libc++ in Xcode is outdated , so <code>constexpr</code> keyword missing in <code>limits</code> 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. </p> </description> <category>Ticket</category> </item> <item> <author>Wolfram Schroers <Dr.Schroers@…></author> <pubDate>Tue, 13 Nov 2012 15:35:49 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7671#comment:14 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7671#comment:14</guid> <description> <p> Changing the <code>libc++</code> to <code>libstdc++</code> in the "C++ Standard Library" row in the "Build Settings" yields 50+ linker errors. This does not appear to work. </p> <p> 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 ... </p> <p> The only practical solution I have found so far is to edit the boost header <code>&lt;boost/thread.hpp&gt;</code> and remove the <code>BOOST_CHRONO_LIB_CONSTEXPR</code> keyword. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>tuhertz</dc:creator> <pubDate>Tue, 13 Nov 2012 16:42:49 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7671#comment:15 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7671#comment:15</guid> <description> <p> 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 <code>constexpr</code>, but both <code>libc++</code> and <code>libstdc++</code> don't implement it in <code>limits</code> header. Changing language dialect to C++98 is easiest fix if you don't have to build Boost with C++11. </p> <p> I think building with custom <code>limits</code> header won't make any trouble, because <code>limits</code> 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. </p> <p> libc++ has been updated in Xcode 4.6 developer preview and i confirm <code>limit</code> header is updated also, so this problem will be gone in next Xcode release. </p> </description> <category>Ticket</category> </item> <item> <author>Hyeon-bin Jeong <tuhertz@…></author> <pubDate>Tue, 13 Nov 2012 18:17:28 GMT</pubDate> <title>attachment set https://svn.boost.org/trac10/ticket/7671 https://svn.boost.org/trac10/ticket/7671 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">libcpp_c11_numeric_limits.patch</span> </li> </ul> <p> Set BOOST_NO_CXX11_NUMERIC_LIMITS for Xcode 4.5 to fix compilation error. </p> Ticket viboes Sat, 17 Nov 2012 08:47:51 GMT owner, component changed; cc set https://svn.boost.org/trac10/ticket/7671#comment:16 https://svn.boost.org/trac10/ticket/7671#comment:16 <ul> <li><strong>cc</strong> <span class="trac-author">viboes</span> added </li> <li><strong>owner</strong> changed from <span class="trac-author">Anthony Williams</span> to <span class="trac-author">John Maddock</span> </li> <li><strong>component</strong> <span class="trac-field-old">thread</span> → <span class="trac-field-new">config</span> </li> </ul> Ticket Dr. Wolfram Schroers <Dr.Schroers@…> Wed, 28 Nov 2012 14:49:07 GMT <link>https://svn.boost.org/trac10/ticket/7671#comment:17 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7671#comment:17</guid> <description> <p> 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. </p> </description> <category>Ticket</category> </item> <item> <author>me@…</author> <pubDate>Mon, 17 Dec 2012 17:18:53 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7671#comment:18 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7671#comment:18</guid> <description> <p> You can also add #define BOOST_THREAD_DONT_USE_CHRONO before including the Boost headers for this error to go away. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>viboes</dc:creator> <pubDate>Wed, 16 Jan 2013 22:50:43 GMT</pubDate> <title>owner, status, component changed https://svn.boost.org/trac10/ticket/7671#comment:19 https://svn.boost.org/trac10/ticket/7671#comment:19 <ul> <li><strong>owner</strong> changed from <span class="trac-author">John Maddock</span> to <span class="trac-author">viboes</span> </li> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> <li><strong>component</strong> <span class="trac-field-old">config</span> → <span class="trac-field-new">thread</span> </li> </ul> <p> <a class="changeset" href="https://svn.boost.org/trac10/changeset/82391" title="Chrono: Don't use constexpr with libc++ &lt; 1002">[82391]</a> Should have fixed this issue. </p> Ticket viboes Thu, 17 Jan 2013 18:17:41 GMT status, milestone changed; resolution set https://svn.boost.org/trac10/ticket/7671#comment:20 https://svn.boost.org/trac10/ticket/7671#comment:20 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> <li><strong>milestone</strong> <span class="trac-field-old">To Be Determined</span> → <span class="trac-field-new">Boost 1.53.0</span> </li> </ul> Ticket