Author Topic: Code::Blocks and clang on Debian  (Read 14877 times)

Offline Poenikatu

  • Multiple posting newcomer
  • *
  • Posts: 10
    • My personal web site
Code::Blocks and clang on Debian
« on: July 20, 2013, 05:32:38 am »
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.
« Last Edit: July 22, 2013, 03:13:12 pm by jens »
Poenikatu
Learning C++
Using Clang++ compiler tool kit
Debian GNU/Linux

Offline golgepapaz

  • Multiple posting newcomer
  • *
  • Posts: 44
Code::Blocks and clang on Debian
« Reply #1 on: July 20, 2013, 06:11:24 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.
« Last Edit: July 22, 2013, 03:13:25 pm by jens »

Offline Poenikatu

  • Multiple posting newcomer
  • *
  • Posts: 10
    • My personal web site
Code::Blocks and clang on Debian
« Reply #2 on: July 20, 2013, 02:57:31 pm »
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).
« Last Edit: July 22, 2013, 03:13:37 pm by jens »
Poenikatu
Learning C++
Using Clang++ compiler tool kit
Debian GNU/Linux

Offline jens

  • Administrator
  • Lives here!
  • *****
  • Posts: 7265
    • Jens' unofficial debian-repository for the Code::Blocks - IDE
Re: Code::Blocks and clang on Debian
« Reply #3 on: July 20, 2013, 03:44:18 pm »
Please do not use the Welcome newcomers therad for posting other stuff than saying hello.
I created this topic for your clang/llvm disscussion.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 12129
    • Travis build status
Re: Code::Blocks and clang on Debian
« Reply #4 on: July 20, 2013, 03:47:21 pm »
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.
« Last Edit: July 22, 2013, 03:13:58 pm by jens »
(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!]

Offline blauzahn

  • Multiple posting newcomer
  • *
  • Posts: 101
Re: Code::Blocks and clang on Debian
« Reply #5 on: July 21, 2013, 05:41:44 pm »
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.
« Last Edit: July 22, 2013, 03:14:08 pm by jens »

Offline Poenikatu

  • Multiple posting newcomer
  • *
  • Posts: 10
    • My personal web site
Re: Code::Blocks and clang on Debian
« Reply #6 on: July 22, 2013, 03:02:38 pm »
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?
« Last Edit: July 22, 2013, 03:14:23 pm by jens »
Poenikatu
Learning C++
Using Clang++ compiler tool kit
Debian GNU/Linux

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 2569
Re: Code::Blocks and clang on Debian
« Reply #7 on: July 22, 2013, 03:34:46 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???

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???

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


Offline Poenikatu

  • Multiple posting newcomer
  • *
  • Posts: 10
    • My personal web site
Re: Code::Blocks and clang on Debian
« Reply #8 on: July 22, 2013, 04:33:17 pm »
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

Offline Poenikatu

  • Multiple posting newcomer
  • *
  • Posts: 10
    • My personal web site
Re: Code::Blocks and clang on Debian
« Reply #9 on: July 22, 2013, 04:44:18 pm »
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

Offline blauzahn

  • Multiple posting newcomer
  • *
  • Posts: 101
Re: Code::Blocks and clang on Debian
« Reply #10 on: July 22, 2013, 07:38:24 pm »
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


Offline Poenikatu

  • Multiple posting newcomer
  • *
  • Posts: 10
    • My personal web site
Re: Code::Blocks and clang on Debian
« Reply #11 on: July 22, 2013, 08:36:43 pm »
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

Offline Poenikatu

  • Multiple posting newcomer
  • *
  • Posts: 10
    • My personal web site
Re: Code::Blocks and clang on Debian
« Reply #12 on: July 22, 2013, 08:46:23 pm »
Is it possible to run a console program with arguments?
Poenikatu
Learning C++
Using Clang++ compiler tool kit
Debian GNU/Linux

Offline blauzahn

  • Multiple posting newcomer
  • *
  • Posts: 101
Re: Code::Blocks and clang on Debian
« Reply #13 on: July 22, 2013, 10:09:02 pm »
Still neither compiler output nor its version?

Look into the projects menu.

for other clang related questions:
$man clang

Offline Poenikatu

  • Multiple posting newcomer
  • *
  • Posts: 10
    • My personal web site
Re: Code::Blocks and clang on Debian
« Reply #14 on: July 22, 2013, 10:49:39 pm »
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