Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: Poenikatu on July 20, 2013, 05:32:38 am

Title: Code::Blocks and clang on Debian
Post by: Poenikatu 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.
Title: Code::Blocks and clang on Debian
Post by: golgepapaz 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.
Title: Code::Blocks and clang on Debian
Post by: Poenikatu 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).
Title: Re: Code::Blocks and clang on Debian
Post by: Jenna 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.
Title: Re: Code::Blocks and clang on Debian
Post by: oBFusCATed 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.
Title: Re: Code::Blocks and clang on Debian
Post by: blauzahn 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.
Title: Re: Code::Blocks and clang on Debian
Post by: Poenikatu 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?
Title: Re: Code::Blocks and clang on Debian
Post by: BlueHazzard 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

Title: Re: Code::Blocks and clang on Debian
Post by: Poenikatu 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 :(
Title: Re: Code::Blocks and clang on Debian
Post by: Poenikatu on July 22, 2013, 04:44:18 pm
Does Code::Blocks read ~/.codeblocks/share/codeblocks before or after the files in /usr/share/codeblocks?
Title: Re: Code::Blocks and clang on Debian
Post by: blauzahn 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

Title: Re: Code::Blocks and clang on Debian
Post by: Poenikatu 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.
Title: Re: Code::Blocks and clang on Debian
Post by: Poenikatu on July 22, 2013, 08:46:23 pm
Is it possible to run a console program with arguments?
Title: Re: Code::Blocks and clang on Debian
Post by: blauzahn 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
Title: Re: Code::Blocks and clang on Debian
Post by: Poenikatu 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.

Title: Re: Code::Blocks and clang on Debian
Post by: Poenikatu on July 22, 2013, 10:56:50 pm
When I start a new project, after pressing Finish on the last configuration page, I get the following message:

 This wizard doesn't know how to
 setup exception flags for this
 compiler.

Can anybody explain this message and what I can do about it?
~~~~
Title: Re: Code::Blocks and clang on Debian
Post by: Alpha on July 22, 2013, 11:14:37 pm
Can anybody explain this message and what I can do about it?
Bug in the wizard; fixed in trunk.

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?
The command -Weverything was most likely specified at project (not target) level.
Title: Re: Code::Blocks and clang on Debian
Post by: stahta01 on July 22, 2013, 11:14:55 pm
When I start a new project, after pressing Finish on the last configuration page, I get the following message:

 This wizard doesn't know how to
 setup exception flags for this
 compiler.

Can anybody explain this message and what I can do about it?
~~~~



You need to check all the Compiler/Linker setting the Wizard said it does not know what to do.
This means it likely did NOT set the correct settings.


Tim S.
Title: Re: Code::Blocks and clang on Debian
Post by: oBFusCATed on July 22, 2013, 11:18:42 pm
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?
If it is in the build log then you've set it somewhere.

Possible locations:
1. settings -> compiler -> your compiler -> compiler settings -> compiler flags or other options
2. project -> build options -> project ->  compiler settings -> compiler flags or other options
3. project -> build options -> your active target -> compiler settings -> compiler flags or other options

Good luck... :P

p.s. there is no point to start topics where you're not willing to help the people trying to help you.  ::)
Title: Re: Code::Blocks and clang on Debian
Post by: blauzahn on July 23, 2013, 06:28:54 am
Quote
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?
It is probably acivated project-wide (see  See project -> build options -> select your project name (top left)).
Often, the project and target options are concatenated but you can limit that to target only if you want.
See project -> build options -> your llvm target -> policy: use target options only. This can be set individually for compile- link-flags etc.
Quite comfortable. Play with it.

If the unwanted option is still there, than it is configured systemwide. See reply by oBFusCATed to find its location.

If you want to use the wizard without updating your cb: You can start a project with gcc and later on switch the selected compiler to llvm/clang.
or even create your personal compiler-settings by copying and adapting one of the existing ones (see settings -> compiler) and use that.
Title: Re: Code::Blocks and clang on Debian
Post by: Poenikatu on July 23, 2013, 01:34:08 pm
Thank you for your kindness. I am now actively translating all Code::Blocks messages into Esperanto, so
I shall not be able to take your advice for a few days.  >:(