Bug 1415512

Summary: Using clang with libc++ does not work
Product: [Fedora] Fedora Reporter: imbacen
Component: libcxxAssignee: Tom "spot" Callaway <tcallawa>
Status: CLOSED CURRENTRELEASE QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 25CC: fweimer, nieric, tcallawa
Target Milestone: ---   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2017-03-01 21:05:18 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description imbacen 2017-01-22 23:16:59 UTC
Description of problem:
Trying to compile a hello world cpp on Fedora 25 with clang++ and libc++ (libcxx).

sudo dnf install clang libcxx-devel

#include <iostream>
#include <string>

int main()
{
    std::string a = "abc";
    std::cout << a;
}

clang++ -stdlib=libc++ hello.cpp

This results in a bunch of linker errors.

Version-Release number of selected component (if applicable):
libcxx-devel-3.8.1-1.fc25.x86_64

How reproducible:
Always

Steps to Reproduce:
1. Install clang and libcxx
2. Try to compile a hello world program

Actual results:
Compile fails

Expected results:
Compile succeeds

Additional info:
I am not a C++ expert but to my understanding libc++ needs to be linked against libc++abi to work and this is not the case with current package. libc++-abi is also not packaged yet (https://bugzilla.redhat.com/show_bug.cgi?id=1332306 ?) so as far as I can understand it is not currently possible to effectively use libc++ on Fedora, unless someone can correct me on this.
What I can't really understand is why libcxx was even included in this state as a package.

Comment 1 Tom "spot" Callaway 2017-01-23 14:40:18 UTC
Upstream separates them. I am waiting on a review for 1332306 in order to get libcxxabi in to Fedora. I did not think it would take this long for that to happen.

Comment 2 E.N. 2017-03-01 17:37:48 UTC
There is now a libcxxabi package (https://admin.fedoraproject.org/pkgdb/package/rpms/libcxxabi/), but still the code in comment #1 can't compile maybe because issues raised by GCC developers here: https://lists.fedoraproject.org/archives/list/devel@lists.fedoraproject.org/thread/UHWAP45O7DOWQ6QA5KL36T5D5YHTLE5K/

Comment 3 E.N. 2017-03-01 17:45:31 UTC
(In reply to E.N. from comment #2)
> the code in comment #1
comment #0, I meant.

Comment 4 Tom "spot" Callaway 2017-03-01 18:25:38 UTC
It seems to work if you append -lc++abi.

Comment 5 E.N. 2017-03-01 20:26:24 UTC
$ cat hello-world.cpp 
#include <iostream>
#include <string>

int main()
{
    std::string a = "abc";
    std::cout << a << std::endl;
}


$ clang++ -stdlib=libc++ -lc++abi -o bar hello-world.cpp
hello-world.cpp:3:10: fatal error: 'iostream' file not found
#include <iostream>
         ^
1 error generated.


$ cat /etc/os-release 
NAME=Fedora
VERSION="26 (Rawhide)"
…


$ rpm --query llvm llvm-devel clang clang-devel libcxx libcxxabi
llvm-3.9.0-7.fc26.x86_64
llvm-devel-3.9.0-7.fc26.x86_64
clang-3.9.0-4.fc26.x86_64
clang-devel-3.9.0-4.fc26.x86_64
libcxx-3.9.0-2.fc26.x86_64
libcxxabi-3.9.0-1.fc26.x86_64


Am I missing something? Is it related to versions' mismatches?

Comment 6 Tom "spot" Callaway 2017-03-01 20:30:34 UTC
Try it with libcxx-3.9.0-3, which is built against libcxxabi.

https://koji.fedoraproject.org/koji/buildinfo?buildID=863381

[spot@localhost ~]$ cat hello-world.cpp 
#include <iostream>
#include <string>

int main()
{
    std::string a = "abc";
    std::cout << a << std::endl;
}
[spot@localhost ~]$ clang++ -stdlib=libc++ -lc++abi -o bar hello-world.cpp 
[spot@localhost ~]$ cat /etc/os-release
NAME=Fedora
VERSION="26 (Workstation Edition)"
…

[spot@localhost ~]$ rpm --query llvm llvm-devel clang clang-devel libcxx libcxxabi
llvm-3.9.0-7.fc26.x86_64
llvm-devel-3.9.0-7.fc26.x86_64
clang-3.9.0-4.fc26.x86_64
package clang-devel is not installed
libcxx-3.9.0-3.fc26.x86_64
libcxxabi-3.9.0-1.fc26.x86_64

Comment 7 E.N. 2017-03-01 20:59:55 UTC
My error, my bad. After running

koji download-build --arch=x86_64 libcxx-3.9.0-3.fc26

and installing the downloaded RPMs, I saw libcxxabi-devel being pulled as a dependency because it was not yet installed. The code compile well after downgrading libcxx and libcxx-devel to 3.9.0.2 while having libcxxabi-devel onto the box.

For the record:
$ rpm --query llvm llvm-devel clang clang-devel libcxx libcxx-devel libcxxabi libcxxabi-devel
llvm-3.9.0-7.fc26.x86_64
llvm-devel-3.9.0-7.fc26.x86_64
clang-3.9.0-4.fc26.x86_64
clang-devel-3.9.0-4.fc26.x86_64
libcxx-3.9.0-2.fc26.x86_64
libcxx-devel-3.9.0-2.fc26.x86_64
libcxxabi-3.9.0-1.fc26.x86_64
libcxxabi-devel-3.9.0-1.fc26.x86_64
$ clang++ -stdlib=libc++ -lc++ -lc++abi -o bar hello-world.cpp
$ ./bar 
abc

Thanks for your time and all the packages you maintain, it's really amazing to realize the great stuff you do for the distro.

My impression is this bug should now be closed.

Comment 8 Tom "spot" Callaway 2017-03-01 21:05:18 UTC
Thanks for the kind words (and your patience).