How to upload to biicode. Example 1: JSON11 by Dropbox

A few days ago, we came across this fantastic library from the Dropbox team, to encode and decode JSON using C++11. Syntax is very clean and attractive which makes the library very easy to use.
Also, this library is an ideal example to show how to upload to biicode your library like I did.

Why would you want to upload to biicode your library ?

Once it’s uploaded to biicode, everyone (including yourself) can reuse it easily and without any complex configuration.
This is key: If you make a good job configuring and uploading the library to biicode, nobody will EVER do this job again. The library will work for anyone just by typing #include “lasote/json11/json11.hpp”.

Upload to biicode


Ok, it sounds convincing, show me how to do it!

1. Install biicode in your computer.

2. Fork original repository (OPTIONAL)

If the library is available on Github or another public git repository, it’s a good practice to fork the repository so in case the author  updates we can merge them to our “biicode compatible” library easily. For this step, go to original repository and click on fork:
JSON11 fork ready to upload to biicode

3. Init a new biicode project and create a new block

Easy-peasy, just like this:

If you already have a biicode user you can replace “lasote” with your username so you can publish your code when you finish this tutorial.
Now copy the source code into blocks/lasote/json folder or execute git clone into it (if you forked the original repository):

4. Check if biicode has found the relationships between your source code

It’s important that biicode locates all the #includes in your source code and the files that these includes point to.
Command “bii deps” give us all the information we need to know about the “dependency scanning” of biicode in our project:

manage your dependencies with biicode

If biicode doesn’t find an #include it is shown under the “unresolved” section. As you can see in this case, everything is OK!
In future posts we will explain how to proceed in case of unresolved files.

5. Build our library

Wow! It fails a lot! What happened?

If we analyze the trace of the compilation we see this:

It’s asking us to activate c++11. Expected… the original library needs c++11.

How can we activate C++11?

Biicode uses CMake for C/C++ project compilation. It creates a CMakeList.txt file where we can specify compilation flags etc.
If we edit the file we can see a lot of commented code with sample cases. In there, you can find how to activate C++11.

In this case, we want our library to be multi-platform and reusable so I will include these lines after ADD_BIICODE_TARGETS()

Hereinafter, when someone #include (s)  our library, he doesn’t need to activate C++11. Its ready!

NOTE: Maybe it seems too difficult, don’t you think? We are working on a feature to share or include CMakes recipes like this. Meanwhile you can just copy and paste this code to enable C++11 in your project.

UPDATE: With biicode you can reuse CMake recipes, so to activate C++11 you can include “biicode/cmake” block to search for ‘tools.cmake’ where this code is already implemented. Open CMakelists.txt in your project, include ‘tools‘ and activate C++11 like this:

If we run build again:

It fails again, why? Let’s check the trace.

It seems it cannot find memcmp, we #include “string.h” in test.cpp and if we build again:

Now the library has been compiled! Go to “bin” folder and execute the main example:

6. Upload to biicode: Publish the library

Congrats! Now your library is on biicode’s cloud! :D

NOTE: Don’t forget to commit and push the changes to github if you forked the repository!

7. Check if anybody can reuse the library

After you upload to biicode the first version, its a good practice to create another biicode project and reuse from (include) the library to check if everything is working fine. This way we’ll simulate a third person reusing our code.

Exit previous biicode project folder and create another one:

Write an example in a file “main.cpp” in blocks/lasote/example directory that #include our lasote/json11 library:

Build the example and run the example!


We need your feedback! What do you think? Is it easy enough to upload to biicode? Do you think that we should share CMake recipes? What would you like?
If you want to upload to biicode your library  we will be pleased to help if you need. Write us in the biicode forum and we will give you support!

Stay tuned

Related Posts