C++11 support #1683

Closed
springmeyer opened this Issue Jan 9, 2013 · 12 comments

Comments

Projects
None yet
2 participants
Owner

springmeyer commented Jan 9, 2013

Ticket to track moving to using c++11 features for better performance and future compatibility with boost, clang++, libc++, and other advanced cxx libs.

Owner

springmeyer commented Jan 9, 2013

Boost 1.53 is making big progress on c++11 (http://www.boost.org/users/history/version_1_53_0.html), variant stuff in particular looks interesting:

Owner

springmeyer commented Jan 11, 2013

@artemp - I got linking working: https://gist.github.com/4e89a4b24c35dcd1dcd8. Basically we need to fix the hardcoded install name. My only gocha after than was due to forgetting to symlink libc++.dylib to libc++.1.dylib.

Owner

artemp commented Jan 11, 2013

@springmeyer - excellent! Here is how I'm configuring/compiling deps and Mapnik :

ICU 50.1.1

./configure --prefix=/opt/mapnik_deps CXX=clang++ CXXFLAGS="-std=c++11 -stdlib=libc++ -I/Users/artem/Projects/libcxx/include"

boost 1_52_0

./bootstrap.sh
echo 'using clang : : /opt/llvm/bin/clang++ : <compileflags>"-std=c++11 -stdlib=libc++ -nostdinc++ -I/Users/artem/Projects/libcxx/include" <linkflags>"-nostdlib -L/Users/artem/Projects/libcxx/lib -lc++ -lSystem" ;' >> tools/build/v2/user-config.jam
./b2 toolset=clang --prefix=/opt/boost -sICU_PATH=/opt/mapnik_deps install

check:

find /opt/boost/lib/ -name '*.dylib' -exec otool -L {} + | grep c++

emacs /opt/boost/include/boost/gil/channel_algorithm.hpp
// replace -1 with 0xffffffff in (hack!)

template <typename UnsignedIntegralChannel>
struct unsigned_integral_max_value : public mpl::integral_c<UnsignedIntegralChannel,-1> {};

postgresql

./configure --prefix=/opt/postgresql

geos

./configure --prefix=/opt/mapnik_deps CXX=clang++ CXXFLAGS="-std=c++11 -stdlib=libc++ -nostdinc++ -nostdlib -I/Users/artem/Projects/libcxx/include" LDFLAGS="-nostdlib -L/Users/artem/Projects/libcxx/lib" LIBS="-lc++ -lSystem" --enable-python

postgis

./configure --with-geosconfig=/opt/mapnik_deps/bin/geos-config --with-projdir=/opt/mapnik_deps --with-pgconfig=/opt/postgresql/bin/pg_config --with-gdalconfig=/opt/mapnik_deps/bin/gdal-config --prefix=/opt/postgresql/

libxml 2.8.0

CC=gcc CFLAGS="-std=c99 -I/opt/mapnik_deps/include" LDFLAGS="-L/opt/mapnik_deps/lib" ./configure --prefix=/opt/mapnik_deps --with-icu=yes --without-iconv --with-threads=yes

GDAL 1.9.2

./configure CXX=clang++ CC=clang LD=clang CFLAGS="-std=c99" CXXFLAGS="-std=c++11 -stdlib=libc++ -Wno-c++11-narrowing -I/Users/artem/Projects/libcxx/include" LDFLAGS="-nostdlib -L/Users/artem/projects/libcxx/lib -lSystem -lc++" --with-pg=/opt/postgresql/bin/pg_config --prefix=/opt/mapnik_deps --with-libtiff=/opt/mapnik_deps

mapnik

./scons/scons.py CXX=/opt/llvm/bin/clang++ CUSTOM_CXXFLAGS="-std=c++11 -stdlib=libc++ -I/Users/artem/Projects/libcxx/include" CUSTOM_LDFLAGS="-nostdlib -L/Users/artem/Projects/libcxx/lib -lc++ -lSystem" BOOST_INCLUDES=/opt/boost/include BOOST_LIBS=/opt/boost/lib configure
Owner

springmeyer commented Jan 11, 2013

cool, what about ICU?

Owner

artemp commented Jan 11, 2013

@springmeyer - sure ^^

Owner

springmeyer commented Jan 15, 2013

fix for libc++: 96857ca

Owner

artemp commented Jan 23, 2013

google protobuf

latest libtool

git clone git://git.savannah.gnu.org/libtool.git
./bootstrap
./configure --prefix=/opt/mapnik_deps
make -j8 && make install

protobuf (c++11/libc++)

svn checkout http://protobuf.googlecode.com/svn/trunk/ protobuf-trunk
cd protobug-trunk
Index: src/google/protobuf/message.cc
===================================================================
--- src/google/protobuf/message.cc  (revision 473)
+++ src/google/protobuf/message.cc  (working copy)
@@ -31,7 +31,7 @@
 // Author: kenton@google.com (Kenton Varda)
 //  Based on original Protocol Buffers design by
 //  Sanjay Ghemawat, Jeff Dean, and others.
-
+#include <iostream>
 #include <stack>
 #include <google/protobuf/stubs/hash.h>
./autogen.sh
CC=clang++ CXX=clang++ CXXFLAGS="-std=c++11 -nostdlib -stdlib=libc++ -nostdinc++ -I/Users/artem/Projects/libcxx/include -mmacosx-version-min=10.8"  LDFLAGS="-nostdlib -stdlib=libc++ -L/Users/artem/Projects/libcxx/lib" LIBS="-lSystem -lc++" ./configure --prefix=/opt/mapnik_deps --enable-static=no
make -j8
make install
Owner

springmeyer commented May 10, 2013

std fail state oddities with libc++: https://gist.github.com/artemp/45d5d82ed5696978e7c4

@springmeyer springmeyer pushed a commit that referenced this issue Jul 27, 2013

Dane Springmeyer support optionally compiling with -std=c++11 on OSX / clang / apple l…
…ibc++ / boost 1.53 - refs #1683
76f111c
Owner

springmeyer commented Jul 30, 2013

okay, I've recently tested all the tweaks needed for building against libc++ in c++11 mode when using Apple's libc++ and clang++ with the latest XCode. It is easier when using apple libc++ rather than source build libc++, so I think we should be sticking with that route primarily.

$ clang++ -v
Apple LLVM version 4.2 (clang-425.0.28) (based on LLVM 3.2svn)
Target: x86_64-apple-darwin12.4.0
Thread model: posix
$ xcodebuild -version
Xcode 4.6.3
Build version 4H1503
$ otool -L /usr/lib/libc++.dylib 
/usr/lib/libc++.dylib:
    /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 65.1.0)
    /usr/lib/libc++abi.dylib (compatibility version 1.0.0, current version 24.2.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0)
$ otool -L /usr/lib/libc++abi.dylib 
/usr/lib/libc++abi.dylib:
    /usr/lib/libc++abi.dylib (compatibility version 1.0.0, current version 26.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0)

Mapnik master (soon to be v2.3.0) now builds cleanly against libc++ and all tests pass as of 79d1e6e.

Building all Mapnik C++ dependencies can be done using apple libc++ with:

export CXXFLAGS="-std=c++11 -stdlib=libc++"
export LDFLAGS="-stdlib=libc++"

Except for GDAL since it uses libtool which for some reason still causes linking to libstdc++ even when -stdlib=libc++ is in the CXXFLAGS. The workaround for libtool/GDAL (which also seems to work for other deps) is to instead put the -std=c++11 -stdlib=libc++ into CXX like:

export CXX="clang++ -std=c++11 -stdlib=libc++"

Then Mapnik needs -DBOOST_SPIRIT_USE_PHOENIX_V3=1 which is automatically added at https://github.com/mapnik/mapnik/blob/19a7e9ad194528ab47ca3de8b385c9f537516b32/SConstruct#L1672-L1680

Owner

springmeyer commented Jul 30, 2013

I will note that I've tested the above workflow using the mapnik-packaging scripts.The versions I am using can be seen at https://github.com/mapnik/mapnik-packaging/blob/96eafb948280aae45251314f91bb47e92f447a39/osx/settings.sh#L114-L161. I hit compile problems with boost 1.54 that I've yet to debug so for now I am sticking with 1.53.

Owner

springmeyer commented Jul 30, 2013

closing, next actions captured at #1972

Owner

springmeyer commented Jul 30, 2013

correcting statement above "The workaround for libtool/GDAL (which also seems to work for other deps) ". This was incorrect. Only setting export CXX="clang++ -std=c++11 -stdlib=libc++" breaks both boost and mapnik build, so something about the compiler/linker appears to require -std=c++11 -stdlib=libc++ to come later (in CXXFLAGS).

kmuehlbauer referenced this issue in conda-forge/gdal-feedstock Jun 30, 2016

Closed

build problem with libtool #81

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment