C++11 compilation sanity check

CodeLite installation/troubleshooting forum
petah
CodeLite Expert
Posts: 231
Joined: Sat Nov 24, 2012 8:04 pm
Genuine User: Yes
IDE Question: c++
Location: Los Angeles
Contact:

C++11 compilation sanity check

Post by petah »

I apologize in advance since this is a compiler and not IDE issue (i.e. outside of CL's realm), but was wondering if anybody here was able to get any remotely advanced C++11 regex code (say std::regex_iterator) to build & link on Linux.

I tried gcc4.8 and built clang from trunk following Eran's wiki doc, but the linker barfs every time. Even http://en.cppreference.com/w/cpp/regex/ ... n_iterator doesn't work. Is it because g++ is lagging and clang uses libstd++'s headers or is there some obscure directive to link with another runtime lib? I tried LLVM's own libc++1 but can't tell if it gets linked in since it fails before any binary can be inspected with ldd.

Eran - do you by any chance have a snippet with a Clang compiler definition I could paste into ~/.codelite/config/build_settings.xml that's able to digest the smallest (non-wxWidget) regex sample?

thx again & sorry for the OT post.

-- p
main: Debian Jessie x64 + custom wxTrunk
petah
CodeLite Expert
Posts: 231
Joined: Sat Nov 24, 2012 8:04 pm
Genuine User: Yes
IDE Question: c++
Location: Los Angeles
Contact:

Re: C++11 compilation sanity check

Post by petah »

replying to my own post so I don't leave a hanging thread (this is Linux-only, everybody else "please disperse, nothing to see here").

Even though the gcc/g++ crew have claimed to be "C++11 complete" a while back, their fineprint is [*] doesn't include STL which depends on libstdc++. Practically that means you can merrily compile c++11 regexes, which may even link, but will barf at runtime. The behavior ranges from throwing an exception while evaluating the simplest regex to consistently returning empty strings no matter what you feed it.

The llvm/clang team implemented their own runtime library, called libc++, first for Mac but there are Linux ports... however I only came across very minimal examples, which work great with every c++11 feature I tested, but when trying to build real-world code (like wx's minimal sample) the resulting binary ends up linking in BOTH their new libc++ runtime and Linux's historical libstdc++, which obviously bombs at runtime. Whether there's a way to compile an app with only libc++ is up for debate; I couldn't do it but would love to be proven wrong.

Still, leaving c++11 compliance & runtimes aside, building code with Clang under Linux is IMHO very much worth it because error reporting is waaaay more useful than g++. Great news... as long as you don't get carried away by promises about c++11 features that just aren't there.

-- p
Last edited by petah on Thu Dec 26, 2013 5:14 pm, edited 1 time in total.
main: Debian Jessie x64 + custom wxTrunk
User avatar
eranif
CodeLite Plugin
Posts: 6375
Joined: Wed Feb 06, 2008 9:29 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: C++11 compilation sanity check

Post by eranif »

petah wrote:Clang under Linux is IMHO very much worth it because error reporting is waaaay more useful than g++
I upgraded to GCC 4.8.1 on Windows and to my surprise the reporting is looking similar to clang++ ...

Eran
Make sure you have read the HOW TO POST thread
petah
CodeLite Expert
Posts: 231
Joined: Sat Nov 24, 2012 8:04 pm
Genuine User: Yes
IDE Question: c++
Location: Los Angeles
Contact:

Re: C++11 compilation sanity check

Post by petah »

eranif wrote:I upgraded to GCC 4.8.1 on Windows and to my surprise the reporting is looking similar to clang++ ...
you mean with the "squiggles" (^^^^^^^error here) and all? Could it be due to CL's error detection regexes?

-- p
main: Debian Jessie x64 + custom wxTrunk
User avatar
eranif
CodeLite Plugin
Posts: 6375
Joined: Wed Feb 06, 2008 9:29 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: C++11 compilation sanity check

Post by eranif »

No, codelite has nothing to do with it ... its g++

Eran
Make sure you have read the HOW TO POST thread
petah
CodeLite Expert
Posts: 231
Joined: Sat Nov 24, 2012 8:04 pm
Genuine User: Yes
IDE Question: c++
Location: Los Angeles
Contact:

Re: C++11 compilation sanity check

Post by petah »

ok I vote for "twilight zone" then :) When I get errors under gcc, whether v4.7 or v4.8.1, it's often lots of noise... especially when templates are involved.

-- p
main: Debian Jessie x64 + custom wxTrunk
petah
CodeLite Expert
Posts: 231
Joined: Sat Nov 24, 2012 8:04 pm
Genuine User: Yes
IDE Question: c++
Location: Los Angeles
Contact:

Re: C++11 compilation sanity check

Post by petah »

* I just noticed gcc 4.8's '^' column error indicator... which I guess was a "quickie" :) Clang's error messages are still much more detailed IMHO.

On a related note, if you need to write regexes on a non-fully-C++11 runtime (like libstdc++) I found Google's open-sourced "RE2" library very nice and compact.

cheers,

-- p
main: Debian Jessie x64 + custom wxTrunk
petah
CodeLite Expert
Posts: 231
Joined: Sat Nov 24, 2012 8:04 pm
Genuine User: Yes
IDE Question: c++
Location: Los Angeles
Contact:

Re: C++11 compilation sanity check

Post by petah »

to subsantiate my earlier claim that error reporting is way better in Clang than gcc, I came across a pretty rare error when trying to convert a std::string to wxString before passing it to wxFileName.

Here's gcc's error report:
gcc_481_error.png
and Clang's:
clang_error.png
The solution is:

Code: Select all

wxFileName cfn((wxString(path)));
I probably wouldn't have figured it out without Clang...

cheers,

-- p
You do not have the required permissions to view the files attached to this post.
main: Debian Jessie x64 + custom wxTrunk
User avatar
eranif
CodeLite Plugin
Posts: 6375
Joined: Wed Feb 06, 2008 9:29 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: C++11 compilation sanity check

Post by eranif »

Indeed, a rare error (never encounter it before)
1:0 clang

Eran
Make sure you have read the HOW TO POST thread
petah
CodeLite Expert
Posts: 231
Joined: Sat Nov 24, 2012 8:04 pm
Genuine User: Yes
IDE Question: c++
Location: Los Angeles
Contact:

Re: C++11 compilation sanity check

Post by petah »

the "fixit" suggestions are really good too, I was wondering if I could write regexes to turn them into a "suggested fix" message with one-click apply button but then I found http://clang.llvm.org/docs/UsersManual. ... ble-fixits ! It'd probably cover most typos and be pretty reliable since you don't have to juggle regexes.

cheers,

-- p
main: Debian Jessie x64 + custom wxTrunk
Post Reply