[cfe-users] Part/complete compilation with clang++

David Blaikie dblaikie at gmail.com
Sat Jul 20 09:44:23 PDT 2013


Nothing obviously wrong with that - yes, jumping in with a debugger
might be an option, but the code looks simple enough that I'd wonder
if it's an issue with linking or the standard library.

On Sat, Jul 20, 2013 at 9:30 AM, Sian Mountbatten
<poenikatu at fastmail.co.uk> wrote:
> On 2013-07-20 17:25, David Blaikie wrote:
>
> On Sat, Jul 20, 2013 at 6:46 AM, Sian Mountbatten
> <poenikatu at fastmail.co.uk> wrote:
>
> Dear List
>
> I have a small program which contains the code shown on page 1058 of
> Stroustrup's TC++PL (4th ed.) just above the 37.2.1 section. I omitted
> the line which initialises (and declares) pat1.
>
> Not everyone has a copy of TC++PL on hand, perhaps you could provide
> the code you are compiling?
>
> If I compile the file main.cpp to regex using this command:
>    clang++ -g -std=c++11 -stdlib=libc++ -o regex main.cpp
> I get no warnings, no errors, in fact no console output from clang++.
> When the program is run, it produces "\w+\d*" on the console.
>
> If you avoid initializing a variable you may get undefined behavior,
> which isn't going to be reliable.
>
> Now, if I compile with this command:
>   clang++ -g -std=c++11 -o main.o -c main.cpp
> and then link with this command:
>   clang++ -g -stdlib=libc++ -o regex main.o
> again, I get no output from clang++. Unfortunately, when the output
> program is run, it fails with "Segmentation violation".
>
> Again, I'm assuming you've invoked UB & the two different standard
> libraries are just failing in different ways. Once we see the code,
> that might change.
>
> Does this mean that when I start writing programs which are made up
> of many source files, I shall be unable to compile the individual files?
>
> I don't understand this question, well maybe - no, there shouldn't
> really be any difference between compiling and then linking and
> compiling+linking in one go. But UB is UB (though I'd still be
> surprised if that actually behaves differently)
>
> I am trying to use Code::Blocks as the IDE for clang++. The commands it
> issues are peculiar and, especially, the linker is, I reckon, just plain
> wrong. The point is that the Code::Blocks binary also fails with a
> Segmentation violation.
>
> So what's going wrong? Can clang++ act, not only as a compiler, but also a
> linker?
>
> Both GCC and Clang (& many other compilers) can act as wrappers around
> assemblers and linkers. They just invoke the assembler (well,
> Clang/LLVM has an integrated assembler too, so it doesn't invoke
> another process to assemble) or linker with the relevant arguments
> (such as figuring out the right libraries to link for the standard
> library, etc)
>
> And is it possible to use a debugger from the LLVM stable rather
> than
> GNU gdb?
>
> There is a debugger under the LLVM project, called LLDB - it's not
> very mature & even less so on Linux. Clang's debug info should operate
> perfectly well with GDB, if it doesn't, please file bugs.
>
> Looking forward to progessing on these points.
>
> --
> Sian Mountbatten <www.poenikatu.co.uk>
> Learning C++!!!
> I'm an FSF member (no. 10888)
> Help us support software freedom! http://www.fsf.org/jf?referrer=10888
>
>
>
> _______________________________________________
> cfe-users mailing list
> cfe-users at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-users
>
> http://paste.debian.net/17301
>
> --
> Sian Mountbatten
> Learning C++!!!
> I'm an FSF member
> Help us support software freedom! http://www.fsf.org/jf?referrer=10888



More information about the cfe-users mailing list