Experimental : g2log with Clang++

After several requests to release g2log with Clang support I finally yielded. From today g2log will have experimental support for Clang. Why the Clang support is experimental is just because I have no OSX machine to test it on. So all Clang testing was done on Linux.

Clang users on Linux and OSX are welcome to try it out:    https://bitbucket.org/KjellKod/g2log.


2013 Dec 31: Update
Edited the original post since I got Clang to work even with std::futures and std::thread.
For Linux users who would like to try out Clang you can follow this guide:  http://solarianprogrammer.com/2013/01/17/building-clang-libcpp-ubuntu-linux/
https://github.com/maidsafe/MaidSafe/wiki/Hacking-with-Clang-llvm-abi-and-llvm-libc

Following the non-striked through link should make the code below work.  

#include <iostream>
#include <future>
#include <thread>
#include <chrono>
int main()
{
std::packaged_task<std::string()> task(
[](){return "Hello from the past";});

std::future<std::string> result = task.get_future();
std::thread(std::move(task)).detach();
std::cout << "Waiting for past to catch up ...";
result.wait();
std::cout << "Done!\nThe message : '" << result.get() << "' \n";
}

On Linux/Clang you can compile the above with :
clang++ -std=c++11 -pthreads -g -stdlib=libc++  -lc++abi  future1.cpp

If the output ends with a crash then your Linux/Clang installation is faulty :
Waiting for past to catch up ...exception_ptr not yet implemented
Aborted (core dumped)

If Clang is installed correctly (don’t forget to link with  -lc++abi) then the output should be the same as if compiling on Linux/g++. For live example see: http://coliru.stacked-crooked.com/a/b5c4933f5bf86f0f

 g++-4.8 -std=c++11 -O2 -Wall -pedantic -pthread main.cpp
 ./a.out
Waiting for past to catch up …Done!
The message : ‘Hello from the past’


C++11 future and package_task 
are used by g2log. With Clang now working on Linux as well you get the full features of g2log on three platforms. Linux, Windows and OSX. It is tested and is in use by coders using system setups such as Linux (g++, Clang),  Windows(Visual 2013 and earlier,  mingw), OSX (Clang).

G2log is now truly a cross-platform logger. Thanks for all the help and feedback to make it so!

What’s next?
What about g2log with dynamic adding of sinks?  With no restriction of type of Class for the sink, inheritance or function signatures as long as it can receive a log message. The concept is neat as you can add objects of various types to a collection and do generic calls on them (i.e. “save log”) as well as sink specific log calls. I.e. SinkX rotate log file.

A beta is already up on BitBucket but it will undergo some heavy cleaning before it replaces the current g2log-dev.  It will not replace g2log since g2log will stay as the very stable logger it is known as while the new logger is more bleeding edge.

The new logger with codename G3log can be found here:  https://github.com/KjellKod/g3log. By now it seems to work great on Windows (visual studio 2013 and mingw) and Linux (g++). It is yet to prove to be ready for Clang.

Advertisements

About kjellkod

Software Engineer by trade, (former?) Martial Artist and Champion by strong will and small skill... and a Swede by nationality :)
This entry was posted in Uncategorized and tagged , , , . Bookmark the permalink.

One Response to Experimental : g2log with Clang++

  1. Pingback: G2log with Clang., Now with all the bells and whistles | Kjellkod's Blog

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