C++11 compilation sanity check
-
- 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
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
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
-
- 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
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
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
- 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
I upgraded to GCC 4.8.1 on Windows and to my surprise the reporting is looking similar to clang++ ...petah wrote:Clang under Linux is IMHO very much worth it because error reporting is waaaay more useful than g++
Eran
Make sure you have read the HOW TO POST thread
-
- 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
you mean with the "squiggles" (^^^^^^^error here) and all? Could it be due to CL's error detection regexes?eranif wrote:I upgraded to GCC 4.8.1 on Windows and to my surprise the reporting is looking similar to clang++ ...
-- p
main: Debian Jessie x64 + custom wxTrunk
- 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
No, codelite has nothing to do with it ... its g++
Eran
Eran
Make sure you have read the HOW TO POST thread
-
- 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
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
-- p
main: Debian Jessie x64 + custom wxTrunk
-
- 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
* 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
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
-
- 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
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:
and Clang's:
The solution is:
I probably wouldn't have figured it out without Clang...
cheers,
-- p
Here's gcc's error report:
and Clang's:
The solution is:
Code: Select all
wxFileName cfn((wxString(path)));
cheers,
-- p
You do not have the required permissions to view the files attached to this post.
main: Debian Jessie x64 + custom wxTrunk
- 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
Indeed, a rare error (never encounter it before)
1:0 clang
Eran
1:0 clang
Eran
Make sure you have read the HOW TO POST thread
-
- 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
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
cheers,
-- p
main: Debian Jessie x64 + custom wxTrunk