Author Topic: Definition of libc++ library with Clang compiler in Code::Blocks on Ubuntu Linux  (Read 9580 times)

Offline ptolomey

  • Multiple posting newcomer
  • *
  • Posts: 12
I installed Clang and libc++ in Linux Ubuntu 12.04 using instructions from the link: http://solarianprogrammer.com/2013/01/17/building-clang-libcpp-ubuntu-linux/.
Programs published in link above pass compilation and can be run, using terminal with following compilation options: clang++ -std=c++11 -stdlib=libc++.
The problem is appeared in C::B when I tried to use STL library libc++ with Clang compiler, option -stdlib=libc++ within Compiler settings -> Other options.
Everything is passing fluently in C::B when Clang compiler is used with STL library libstdc++.
How this problem can be solved?

The source code is published in link above and the compilation errors log file attached to post.
« Last Edit: April 08, 2013, 10:13:52 pm by ptolomey »

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7588
    • My Best Post
May guess based on this link http://stackoverflow.com/questions/12939046/forcing-clang-to-link-with-c-runtime

Try adding the library "stdc++" to the link library list.

NOTE: This is only slightly related to CB; so, the topic might be locked.

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline ptolomey

  • Multiple posting newcomer
  • *
  • Posts: 12
Hi, stahta01
Thank you for reply.
The problem is does in C::B options.
I have no problems in compilation and runing the programm, when everything is done via terminal.

Offline ptolomey

  • Multiple posting newcomer
  • *
  • Posts: 12
I think I found out where the problem is.

When I use the terminal the compilation command is:
Code
clang++ -std=c++11 -stdlib=libc++ -g <filename>.cpp -o <filename>

This command make an executable file if compilation pass.

In case of C::B, first of all created objective file, and only after that executable is created.
There are two commands in C::B:
  • first for compilation and creation of objective file
  • second for linking

Code
#1 clang++ -std=c++11 -stdlib=libc++ -g -c <filename>.cpp -o obj/Debug/<filename>.o
#2 clang++ -o /bin/debug/<filename> obj/Debug/<filename>.o

The command in 2-nd line created by C::B automaticly.
Based on attached Error Log file, it can be seen that errors start to appear after command in 2-nd line.
I belive that automaticly created command in 2-nd line, should look like following:
Code
clang++ obj/Debug/<filename>.o -o /bin/debug/<filename>

Currently I have no accesses to PC with installed Clang.
Today at evening I will check this option using command line.

[attachment deleted by admin]
« Last Edit: April 09, 2013, 10:19:33 am by ptolomey »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
I belive that some compiler flags are missing in automaticly created 2-nd line command.
Please use you console to play with it and tell us which flags.
(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 jarod42

  • Multiple posting newcomer
  • *
  • Posts: 87
I would say that -stdlib=libc++ is a *linker* option.

Offline ptolomey

  • Multiple posting newcomer
  • *
  • Posts: 12
Hi jarod42,
Thank you for advice.

The flag -stdlib=libc++ is compiler's and linker's option.
The code is get compiled and runs after addition of flag -stdlib=libc++ to Compiler settings -> Other options and Linker settings -> Other linker options in C::B.

The compilation and linking options in C::B are following:
Code
Compilation: clang++ -stdlib=libc++ -std=c++11 -g -c <filename>.cpp -o obj/Debug/<filename>.o
Linking:     clang++ -stdlib=libc++ obj/Debug/<filename>.o -o /bin/debug/<filename>  

Via terminal is almost (except path) same command:
Code
Compilation: clang++ -stdlib=libc++ -std=c++11 -g -c <filename>.cpp -o <filename>.o
Linking:     clang++ -stdlib=libc++ <filename>.o -o <filename>  

Thank you for ideas.