Clang CMake Settings For biicode C++11 Projects



[ADDENDUM 2/2/15]  They fixed this super fast after my post, so this post now is for educational use.


I started playing with bii tonight, and I think it’s got a lot of potential.  As part of finding my way around, I followed their well written tutorials. However, when attempting to build a C++11 project, I found an issue at least with one of their example projects (I built a non-c++11 project easily and with no errors).  In their docs for building c++ projects, they give the following CMake example for activating c++11:

IF(APPLE)
  TARGET_COMPILE_OPTIONS( ${BII_BLOCK_TARGET} INTERFACE "-std=c++11 -stdlib=libc++")
ELSEIF (WIN32 OR UNIX)
  TARGET_COMPILE_OPTIONS( ${BIT_BLOCK_TARGET} INTERFACE "-std=c++11")
ENDIF(APPLE)

The problem with the specific example project I was using: json11 specifically is that it’s a non-trivial project, with a lot of various make and cmake files including one another.  Editing the cmake file in the source directory kept being over written during compilation.  I actually had to do a deep dive into the various cmake files.  The error I kept getting was:

INFO: Processing changes...
Building: cmake --build .
[ 33%] Building CXX object lasote/json11/CMakeFiles/lasote_json11.dir/json11.cpp.o
[ 66%] Building CXX object lasote/json11/CMakeFiles/lasote_json11.dir/cmake_dummy.cpp.o
Linking CXX static library liblasote_json11.a
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: liblasote_json11.a(cmake_dummy.cpp.o) has no symbols
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib: file: liblasote_json11.a(cmake_dummy.cpp.o) has no symbols
[ 66%] Built target lasote_json11
[100%] Building CXX object examples/json11/CMakeFiles/examples_json11_test.dir/test.cpp.o
error: invalid value 'c++11 -stdlib=libc++' in '-std=c++11 -stdlib=libc++'
make[2]: *** [examples/json11/CMakeFiles/examples_json11_test.dir/test.cpp.o] Error 1
make[1]: *** [examples/json11/CMakeFiles/examples_json11_test.dir/all] Error 2
make: *** [all] Error 2
ERROR: Build failed

The offending compiler flags were: "-std=c++11 -stdlib=libc++"

What they needed to be was “-std=c++11″, or “-std=c++0x” should work equally well.

For this specific project, the files that required changing were:

/build/examples/json11/CMakeFiles/examples_json11_test.dir/flags.make
/build/lasote/json11/CMakeFiles/lasote_json11.dir/flags.make

By changing them to “-std=c++11” (or “-std=c++0x”), I received a successful build and run:

nsardo$ bii cpp:build
INFO: Processing changes...
Building: cmake --build .
[ 66%] Built target lasote_json11
[100%] Building CXX object examples/json11/CMakeFiles/examples_json11_test.dir/test.cpp.o
Linking CXX executable /Users/nsardo/Desktop/biiproj/json11/bin/examples_json11_test
[100%] Built target examples_json11_test

nsardo$ ./examples_json11_test
k1: v1
k3: ["a", 123, true, false, null]
obj: {"k1": "v1", "k2": 42, "k3": ["a", 123, true, false, null]}
[[1, 2], [10, 20], [100, 200]]

Hopefully if someone else runs into this, it will save them some time and frustration.
Happy Coding.

Advertisements

4 thoughts on “Clang CMake Settings For biicode C++11 Projects

  1. Hi Nick, thanks for the useful post.

    If you want to edit one of your dependencies, you have to “open” it. If you try to edit it while in “deps” folder it is overwritten. Try $bii open user/block, and it will move to your blocks folder and you will be able to modify it.

    The problem is partially solved now, in the last version of the cmake utils the json11 project is using http://www.biicode.com/biicode/cmake

    The problem is that json11 still depends on the first, old version of biicode/cmake. It is easy to override it, just write in your block biicode.conf:

    [requirements]
    biicode/cmake: 4

    That will override the json11 deps, and should work

      1. Right?! Still, I appreciate your showing me a better way. I had so many text windows open to track down which include was doing the overwriting (and there was actually not one, but two) I was getting dizzy!

    1. Thanks for the info, Diego! I definitely had to dig in to overcome the overwriting, lol! Now that you’ve set me straight, I’ll do it the right way.
      Really like what you’re doing with biicode.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s