News:

When registered with our forums, feel free to send a "here I am" post here to differ human beings from SPAM bots.

Main Menu

Code::Blocks and clang on Debian

Started by Poenikatu, July 20, 2013, 05:32:38 AM

Previous topic - Next topic

Poenikatu

Hello. I have just started learning C++ from Bjarne's book The C++ Programming Language (4th edition). I am using it
because it teaches C++11. My system is Debian GNU/Linux x86_64 with kernel 3.2.0-4-amd64. Yesterday, I succeeded
in compiling the LLVM/Clang++ compiler from scratch (using gcc for the 1st stage). The 2nd stage involved recompilation
using Clang++ itself resulting in a binary which is 3Mb smaller. I have also compiled the new libc++ library and used it
successfully for one small program.

I intend using Code::Blocks for all my C++ work, but I notice that Code::Blocks does not yet have support for Clang++.
I' d very much like to know how to support the LLVM compiler because it implements the whole of C++11.
Poenikatu
Learning C++
Using Clang++ compiler tool kit
Debian GNU/Linux

golgepapaz

#1
Quote from: Poenikatu on July 20, 2013, 05:32:38 AM

I intend using Code::Blocks for all my C++ work, but I notice that Code::Blocks does not yet have support for Clang++.
I' d very much like to know how to support the LLVM compiler because it implements the whole of C++11.

I am sure that  C::B support clang.Have a look at Settings->Compiler. There is a entry
called llvm clang compiler. You can adjust it to point your newly compiled clang and make it
the default compiler for your projects.

Poenikatu

#2
As you said, there is an entry for LLVM Clang, but the commands issued by Code::Blocks are either overly complicated
or just plain wrong. The program is only 11 lines long. The Code::Blocks controlled build produces a binary which
fails with a Segmentation violation, whereas the command-line compilation/linking runs without errors. And, when I
try to run the target from within C::B, the loader cannot find the libc++ library (whose directory *is* in my
LD_LIBRARY_PATH).
Poenikatu
Learning C++
Using Clang++ compiler tool kit
Debian GNU/Linux

Jenna

#3
Please do not use the Welcome newcomers therad for posting other stuff than saying hello.
I created this topic for your clang/llvm disscussion.

oBFusCATed

#4
How about telling us your version of C::B? Have you tried a night build?
Also it would have been good if you've posted some build logs.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

blauzahn

#5
Please compare the commandline invoked by cb with the one you entered manually if you
have not already done. Your post does not mention it explicitly.

To see it, you can swich settings|compiler| your llvm entry | other settings | compiler logging|
 to "full command line".

Do you need full c++11 support as a beginner right from the start? Do you really need clang's libc++ now?
I use a subset of c++11 with clang with the g++4.8.1 library (must stay compatible with
MSVS 2010). So, until now there is no need for me to enter LD_LIBRARY_PATH because I have g++
installed systemwide, only clang++ ist in /usr/local. And I am fine with the recent c++11 support of g++.

If you still need the environment variable to run the binary from cb
you can set it either in the project or cb-wide.

Poenikatu

#6
My version of Code::Blocks is 12.11 svn9206 (built by Jens on 14 July 2013).
My system is Debian GNU/Linux version 7.1.
My kernel is 3.2.0-4-amd64 running on an x86_64 system.

I have created a tool which compiles my programs successfully, but, of course, C::B doesn't know that the file has been
compiled, so it insists on doing its own build as well.

I should like to know that, even though I have ticked Have clang++ follow the C++11 ISO C++ language standard, I still get my
usage of nullptr flagged as being incompatible with c++98. Why? And how does C::B know how to use the clang++ compiler anyway?
Where is it specified?
Poenikatu
Learning C++
Using Clang++ compiler tool kit
Debian GNU/Linux

BlueHazzard

Quote from: Poenikatu on July 22, 2013, 03:02:38 PM
I have created a tool which compiles my programs successfully, but, of course, C::B doesn't know that the file has been
compiled, so it insists on doing its own build as well.

So why you use the build button from c::b???

Quote from: Poenikatu on July 22, 2013, 03:02:38 PM
I should like to know that, even though I have ticked Have clang++ follow the C++11 ISO C++ language standard, I still get my
usage of nullptr flagged as being incompatible with c++98. Why?
do you use the c::b build system? Without the full build command it is hard to say... Please post the full build log as mentioned  above. But anyway where is your problem???

Quote from: Poenikatu on July 22, 2013, 03:02:38 PM
And how does C::B know how to use the clang++ compiler anyway?
Where is it specified?
From here: Settings->Compiler->Selected Compiler=LLVM Clang Compiler->Other Settings->Advanced options


Poenikatu

Ok, I saw the command-line command you mentioned. But the macro $options must be set somewhere. And the reason that I
had to use the Code::Blocks Build was because, after I had compiled the program with my custom tool, I wanted to run the
program. C::B reported that the project had not been built and proceeded to do so. It would appear that I have to run the
resulting binary at the command line in a terminal. Just so that I know :(
Poenikatu
Learning C++
Using Clang++ compiler tool kit
Debian GNU/Linux

Poenikatu

Does Code::Blocks read ~/.codeblocks/share/codeblocks before or after the files in /usr/share/codeblocks?
Poenikatu
Learning C++
Using Clang++ compiler tool kit
Debian GNU/Linux

blauzahn

You did not post your command line yet.

You should avoid to change anything within the advanced compiler options.
Just check the entries in settings| compiler | your llvm entry | Toolchain executables.

Do they point to the same ones you use from the commandline?
I have clang installed in /usr/local. So, I use:
compiler installation directory: /usr/local
c++ compiler: clang++
make program: make

To test your toolchain:
Can you create a new cb-project (command-line hello world)
select llvm/clang as compiler and build it?

To use c++11 features you have to use the compiler-flag -std=c++11
and neither -std=c++98 nor -std=c++0x

And remember to activate the compiler-flag -Wall

To see which clang++ you use, please enter on the commandline:
$ which clang++
$ clang++ -version


Poenikatu

Have done as you suggested. I cleared out the Workspace directory and started a Hello project.
C::B successfully compiled and ran the program.

Now that I understand rather more about Clang, I see that the command issued by C::B is
dwarfed by the output from Clang calling its compiler cc1, and I now understand that the ld command
is also issued by Clang itself. One caveat: I only asked for -Wall, but C::B insisted on -Weverything. How do I switch off -Weverything? I did *not* select that option when configuring the compiler.
Poenikatu
Learning C++
Using Clang++ compiler tool kit
Debian GNU/Linux

Poenikatu

Is it possible to run a console program with arguments?
Poenikatu
Learning C++
Using Clang++ compiler tool kit
Debian GNU/Linux

blauzahn

Still neither compiler output nor its version?

Look into the projects menu.

for other clang related questions:
$man clang

Poenikatu

There's no point putting compiler output 'cos I've now got Code::Blocks to compile and build successfully.
The output from "clang++ --version" is
clang version 3.4 (trunk 186654)
Target: x86_64-unknown-linux-gnu
Thread model: posix
Note my reply in which I point out that there is an enormous difference between the commands that Code::Blocks issues and the
commands issued by the Clang++ driver module to run its compiler (cc1) and the GNU linker (ld).

In a previous post, I had confused the two kinds of commands. However, I still don't understand why Code::Blocks insists on specifying
-Weverything even though I have only asked for -Wall. Can you shed light on that?

I'm using Code::Blocks 12.11 svn9224, built on July 22 2013, 10:31:52 - wx2.8.12 (Linux,unicode) - 64 bit (taken from the
Code::Blocks About window.

Poenikatu
Learning C++
Using Clang++ compiler tool kit
Debian GNU/Linux