{"id":61,"date":"2012-02-15T16:56:00","date_gmt":"2012-02-15T16:56:00","guid":{"rendered":"https:\/\/www.root42.de\/blog\/?p=61"},"modified":"2012-02-15T16:56:00","modified_gmt":"2012-02-15T16:56:00","slug":"what-about-c11-in-xcode","status":"publish","type":"post","link":"https:\/\/www.root42.de\/blog\/?p=61","title":{"rendered":"What about C++11 in Xcode?"},"content":{"rendered":"<p>This started out as a very small problem: I am using C++, Objective C++ and Objective C mixed in one project. This usually works pretty well. However, when including MapKit, the compiler choked on an Objective C++ file. It seems the MapKit.h header wants to use isinf(). This function has been introduced with ISO C 99, but it it is not included in ISO C++ 98. Hence the failure of Xcode&#8217;s gcc and clang compilers.<\/p>\n<p>To work around this problem I was thinking of trying to set the project settings to use ISO C++ 11, or C++ 0x, since Xcode&#8217;s compilers are not <i>that<\/i> up to date. This is pretty easy:<\/p>\n<div style=\"clear: both; text-align: center;\"><a href=\"http:\/\/1.bp.blogspot.com\/-pJcnbRq7N40\/Tzvi_hmMyJI\/AAAAAAAACCA\/SCLG_jaeuhA\/s1600\/Bildschirmfoto+2012-02-15+um+17.52.03.png\" style=\"margin-left: 1em; margin-right: 1em;\"><img border=\"0\" src=\"http:\/\/1.bp.blogspot.com\/-pJcnbRq7N40\/Tzvi_hmMyJI\/AAAAAAAACCA\/SCLG_jaeuhA\/s1600\/Bildschirmfoto+2012-02-15+um+17.52.03.png\" \/><\/a><\/div>\n<p>And I guess this would work for most people. However, I am also using boost in this project. And I guess it is rather up to date, concerning the new language specification. However this also means that there is a problem with clang&#8217;s support of the language. I get a ton of errors in boost when switching to C++ 0x in clang:<\/p>\n<div style=\"clear: both; text-align: center;\"><a href=\"http:\/\/2.bp.blogspot.com\/-wkQl24-OUpM\/TzvjYfU5n4I\/AAAAAAAACCI\/bhMRrnkGxEY\/s1600\/Bildschirmfoto+2012-02-15+um+17.51.44.png\" style=\"margin-left: 1em; margin-right: 1em;\"><img border=\"0\" src=\"http:\/\/2.bp.blogspot.com\/-wkQl24-OUpM\/TzvjYfU5n4I\/AAAAAAAACCI\/bhMRrnkGxEY\/s1600\/Bildschirmfoto+2012-02-15+um+17.51.44.png\" \/><\/a><\/div>\n<p>In short, I think the C++ 11 support is not quite there yet with Xcode 4.2 and clang 3.0. I will try to post updates when future Xcode releases are coming out. If, alternatively, someone has hints on how to compile boost with clang 3.0, I am also glad to try that out.<\/p>\n<p><b>Update:<\/b> There is a <a href=\"https:\/\/gitorious.org\/~mz2\/boostoniphone\/mz2-boostoniphone\">fork on gitorious<\/a> of the boost on iPhone build script, which already uses the clang compiler. I hacked the script even more to use <span style=\"font-family: 'Courier New', Courier, monospace;\">&#8211;std=c++0x<\/span> as a flag and it builds fine. Now I will try to link this new framework to an iOS project compiled with clang using C++ 0x.<\/p>\n<p><b>Update 2:<\/b> I found the root of the problem. The fantastic people over at <span style=\"font-family: 'Courier New', Courier, monospace;\">#boost <\/span>on <a href=\"http:\/\/freenode.org\/\">freenode<\/a> helped me figuring it out. In short: <a href=\"http:\/\/www.boost.org\/libs\/fusion\/\">boost::fusion<\/a> defines <span style=\"font-family: 'Courier New', Courier, monospace;\">nil<\/span>, which is an Objective C keyword. Thus we get lots of problems. Objective C defines <span style=\"font-family: 'Courier New', Courier, monospace;\">nil<\/span> and <span style=\"font-family: 'Courier New', Courier, monospace;\">Nil<\/span> in <span style=\"font-family: 'Courier New', Courier, monospace;\">objc\/objc.h<\/span>. A minimal program that compiles successfully:<\/p>\n<pre>#include &lt;boost\/phoenix\/core\/reference.hpp&gt;<br \/>#import &lt;CoreFoundation\/CoreFoundation.h&gt;<br \/><br \/>int main()<br \/>{<br \/>    return 1;<br \/>}<br \/><\/pre>\n<p>Using this command line: <\/p>\n<pre>\/Developer\/Platforms\/iPhoneOS.platform\/Developer\/usr\/bin\/clang++ <br \/>-isysroot \/Developer\/Platforms\/iPhoneOS.platform\/Developer\/SDKs\/iPhoneOS5.0.sdk <br \/>-framework Foundation -Fpath\/to\/boost\/framework --std=c++0x -arch armv7 <br \/>-stdlib=libc++ -mthumb -miphoneos-version-min=5.0 foo.mm -o foo <br \/><\/pre>\n<p>If you swap the to include \/ import statements, the program will not compile, since now the ObjC nil makes boost break. There is a <a href=\"https:\/\/svn.boost.org\/trac\/boost\/ticket\/5010\">boost ticket<\/a> tracking this issue, with a proposed patch attached, which renames the boost <span style=\"font-family: 'Courier New', Courier, monospace;\">nil<\/span> to <span style=\"font-family: 'Courier New', Courier, monospace;\">nil_<\/span>.<\/p>\n<p><b>Update 3:<\/b> The patch works fine, but now I get internal compiler errors from clang. The compile triggers a segmentation violation at some point during the compilation of my project. I guess clang 3.0 is still a bit experimental. I submitted a bug report and will revert to using the default settings of Xcode for the time being.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This started out as a very small problem: I am using C++, Objective C++ and Objective C mixed in one project. This usually works pretty well. However, when including MapKit, the compiler choked on an Objective C++ file. It seems the MapKit.h header wants to use isinf(). This function has been introduced with ISO C &hellip; <a href=\"https:\/\/www.root42.de\/blog\/?p=61\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;What about C++11 in Xcode?&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[38,7,45,24],"tags":[],"_links":{"self":[{"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/61"}],"collection":[{"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=61"}],"version-history":[{"count":0,"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/61\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=61"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=61"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.root42.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=61"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}