[llvm-dev] Clang++: No member name 'make_unique' in namespace 'std'

1,985 views
Skip to first unread message

users users via llvm-dev

unread,
Feb 11, 2021, 5:21:03 PM2/11/21
to llvm...@lists.llvm.org
Dear LLVM Developers:

1.   Recently I built llvm/12.0 on IBM power8 using gcc/8.2.0. When I run clang++ with an example from https://en.cppreference.com/w/cpp/memory/unique_ptr/make_unique:

 #include <iostream>
#include <iomanip>
#include <memory>
 
struct Vec3
{
    int x, y, z;
 
    // following constructor is no longer needed since C++20
    Vec3(int x = 0, int y = 0, int z = 0) noexcept : x(x), y(y), z(z) { }
 
    friend std::ostream& operator<<(std::ostream& os, const Vec3& v) {
        return os << "{ x=" << v.x << ", y=" << v.y << ", z=" << v.z << " }";
    }
};
 
int main()
{
    // Use the default constructor.
    std::unique_ptr<Vec3> v1 = std::make_unique<Vec3>();
    // Use the constructor that matches these arguments
    std::unique_ptr<Vec3> v2 = std::make_unique<Vec3>(0,1,2);
    // Create a unique_ptr to an array of 5 elements
    std::unique_ptr<Vec3[]> v3 = std::make_unique<Vec3[]>(5);
 
    std::cout << "make_unique<Vec3>():      " << *v1 << '\n'
              << "make_unique<Vec3>(0,1,2): " << *v2 << '\n'
              << "make_unique<Vec3[]>(5):   ";
    for (int i = 0; i < 5; i++) {
        std::cout << std::setw(i ? 30 : 0) << v3[i] << '\n';
    }
}

It failed with the following errors:
    Error: no member named 'make_unique' in namespace 'std'
       std::unique_ptr<Vec3> v1 = std::make_unique<Vec3>();
    ... ...

Any idea and suggestion about what is going on? or have I missed something? The command I used to compile the code above:
     $ clang++ a.cpp

2.  Comparing this llvm with my current gcc/8.2.0 on a project (openmp code running 1 thread), it showed that llvm is almost twice as slow as gcc (both compile with -O3) on my IBM power8 machine. Is it suppose to be with such slower performance than gcc? 

Thank you very much for any advice!

Best Regards,
Shelton 






 



David Blaikie via llvm-dev

unread,
Feb 11, 2021, 5:26:09 PM2/11/21
to users users, llvm...@lists.llvm.org
1) clang++ -v will show you which standard library headers it's using,
it might be using an older standard library on your system that
doesn't have std::make_unique.
2) Did you build the compiler in release mode, or in debug mode? (with
or without assertions enabled)

> _______________________________________________
> LLVM Developers mailing list
> llvm...@lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
_______________________________________________
LLVM Developers mailing list
llvm...@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev

Mehdi AMINI via llvm-dev

unread,
Feb 11, 2021, 5:27:34 PM2/11/21
to users users, llvm-dev
On Thu, Feb 11, 2021 at 2:21 PM users users via llvm-dev <llvm...@lists.llvm.org> wrote:
Maybe `clang++ -std=c++11 a.cpp` ?
 

2.  Comparing this llvm with my current gcc/8.2.0 on a project (openmp code running 1 thread), it showed that llvm is almost twice as slow as gcc (both compile with -O3) on my IBM power8 machine. Is it suppose to be with such slower performance than gcc? 

It is very sensitive to how you built it, by default it'll be built in debug mode. For best performance you would ideally you enable Release mode, and bootstrap with LTO/PGO.

-- 
Mehdi

 

Thank you very much for any advice!

Best Regards,
Shelton 






 



Nevin Liber via llvm-dev

unread,
Feb 11, 2021, 5:41:15 PM2/11/21
to llvm-dev
On Thu, Feb 11, 2021 at 4:27 PM Mehdi AMINI via llvm-dev <llvm...@lists.llvm.org> wrote:
Maybe `clang++ -std=c++11 a.cpp` ?

Note:  make_unique was added in C++14.
--
 Nevin ":-)" Liber  <mailto:ne...@cplusplusguy.com+1-847-691-1404

users users via llvm-dev

unread,
Feb 11, 2021, 5:53:53 PM2/11/21
to David Blaikie, llvm...@lists.llvm.org
Hi David,

Thank you so much for your quick response!
I am very inexperienced with llvm. Please bear with me if my questions look stupid:

1. Here is the output from the command ss"clang++ -v":  


$ clang++ -v

clang version 12.0.0 (... .../llvm/llvm-project_git/clang 36263a7cccc0d98afc36dea55e7a004d08455811)

Target: powerpc64le-unknown-linux-gnu

Thread model: posix

InstalledDir: ... .../llvm/llvm-project_git/build_12.0.0_36263a7_010421/bin

Found candidate GCC installation: /usr/lib/gcc/ppc64le-redhat-linux/4.8.2

Found candidate GCC installation: /usr/lib/gcc/ppc64le-redhat-linux/4.8.5

Selected GCC installation: /usr/lib/gcc/ppc64le-redhat-linux/4.8.5

Candidate multilib: .;@m64

Selected multilib: .;@m64


Before using clang++, I removed gcc modules, because I thought clang++ should not be dependent of any host compiler once it was built successfully. Or does it need to make my host compiler (such as gcc/8.2.0) available to it so that to compile my project? 
     
2.  Here are the options I used to build llvm:
 -DLLVM_ENABLE_PROJECTS="clang;libcxx;libcxxabi;openmp;parallel-libs" -DCMAKE_BUILD_TYPE="Release" -DLLVM_TARGETS_TO_BUILD=PowerPC -DLLVM_ENABLE_LIBPFM=OFF -DRUN_HAVE_GNU_POSIX_REGEX=0 -DRUN_HAVE_THREAD_SAFETY_ATTRIBUTES=0 -Wno-dev ../llvm
Are these correct options to use?

Please advise. Thank you so much David!

Best,
Shelton

users users via llvm-dev

unread,
Feb 11, 2021, 6:04:44 PM2/11/21
to Mehdi AMINI, llvm-dev
Dear Mehdi,

Thank you so much for answering my questions - so quick!
1.  " clang++ a.cpp -std=c++11" seems does not work either. But when I add a gcc modulel "module load gcc/7.3.0", it is compiled successfully without error - event llvm is built with gcc/8.2.0.

2. I used the options to build llvm  
 -DLLVM_ENABLE_PROJECTS="clang;libcxx;libcxxabi;openmp;parallel-libs" -DCMAKE_BUILD_TYPE="Release" -DLLVM_TARGETS_TO_BUILD=PowerPC -DLLVM_ENABLE_LIBPFM=OFF -DRUN_HAVE_GNU_POSIX_REGEX=0 -DRUN_HAVE_THREAD_SAFETY_ATTRIBUTES=0 -Wno-dev ../llvm
are they correct options?

Thanks!
Shelton.

David Blaikie via llvm-dev

unread,
Feb 11, 2021, 6:08:30 PM2/11/21
to users users, llvm...@lists.llvm.org
On Thu, Feb 11, 2021 at 2:53 PM users users <usertest...@gmail.com> wrote:
>
> Hi David,
>
> Thank you so much for your quick response!
> I am very inexperienced with llvm. Please bear with me if my questions look stupid:
>
> 1. Here is the output from the command ss"clang++ -v":
>
>
> $ clang++ -v
>
> clang version 12.0.0 (... .../llvm/llvm-project_git/clang 36263a7cccc0d98afc36dea55e7a004d08455811)
>
> Target: powerpc64le-unknown-linux-gnu
>
> Thread model: posix
>
> InstalledDir: ... .../llvm/llvm-project_git/build_12.0.0_36263a7_010421/bin
>
> Found candidate GCC installation: /usr/lib/gcc/ppc64le-redhat-linux/4.8.2
>
> Found candidate GCC installation: /usr/lib/gcc/ppc64le-redhat-linux/4.8.5
>
> Selected GCC installation: /usr/lib/gcc/ppc64le-redhat-linux/4.8.5
>
> Candidate multilib: .;@m64
>
> Selected multilib: .;@m64
>
>
> Before using clang++, I removed gcc modules, because I thought clang++ should not be dependent of any host compiler once it was built successfully. Or does it need to make my host compiler (such as gcc/8.2.0) available to it so that to compile my project?

I think you may need to pass -stdlib=libc++ to use the libc++ you
built/installed, rather than the system libstdc++ which looks a bit
out of date (& so doesn't have std::make_unique).

>
> 2. Here are the options I used to build llvm:
> -DLLVM_ENABLE_PROJECTS="clang;libcxx;libcxxabi;openmp;parallel-libs" -DCMAKE_BUILD_TYPE="Release" -DLLVM_TARGETS_TO_BUILD=PowerPC -DLLVM_ENABLE_LIBPFM=OFF -DRUN_HAVE_GNU_POSIX_REGEX=0 -DRUN_HAVE_THREAD_SAFETY_ATTRIBUTES=0 -Wno-dev ../llvm
> Are these correct options to use?

Mostly right except you probably want/need
-DLLVM_ENABLE_ASSERTIONS=Off if you want a production-speed compiler.

Mehdi AMINI via llvm-dev

unread,
Feb 11, 2021, 6:19:24 PM2/11/21
to David Blaikie, llvm...@lists.llvm.org, users users
This is implied by `-DCMAKE_BUILD_TYPE="Release"`: https://github.com/llvm/llvm-project/blob/main/llvm/CMakeLists.txt#L412-L416

David Blaikie via llvm-dev

unread,
Feb 11, 2021, 6:22:45 PM2/11/21
to Mehdi AMINI, llvm...@lists.llvm.org, users users

Ah, huh. Then I'm not sure what else would account for the slow runtime.

Andrzej Warzynski via llvm-dev

unread,
Feb 17, 2021, 9:47:23 AM2/17/21
to llvm...@lists.llvm.org
Shelton,

Please try adding this when compiling a.cpp (earlier mentioned by David):
-stdlib=libc++

AFAIK, even when you _do_ build LLVM's libc++, clang++ will use
libstdc++ by default anyway. In your case, that's your rather old system
libstdc++. When you run "module load gcc/7.3.0" you are most likely
loading libstdc++ that corresponds to gcc-7.3.0 (and which is C++14
compatible). So the compilation works.

I hope that this helps!

Andrzej

On 11/02/2021 23:04, users users via llvm-dev wrote:
> Dear Mehdi,
>
> Thank you so much for answering my questions - so quick!
> 1.  " clang++ a.cpp -std=c++11" seems does not work either. But when I
> add a gcc modulel "module load gcc/7.3.0", it is compiled successfully

> without error - event llvm is built with gcc/8.2.0. <http://8.2.0.>


>
> 2. I used the options to build llvm
>  -DLLVM_ENABLE_PROJECTS="clang;libcxx;libcxxabi;openmp;parallel-libs"
> -DCMAKE_BUILD_TYPE="Release" -DLLVM_TARGETS_TO_BUILD=PowerPC
> -DLLVM_ENABLE_LIBPFM=OFF -DRUN_HAVE_GNU_POSIX_REGEX=0
> -DRUN_HAVE_THREAD_SAFETY_ATTRIBUTES=0 -Wno-dev ../llvm
> are they correct options?
>
> Thanks!
> Shelton.
>
>
> On Thu, Feb 11, 2021 at 4:27 PM Mehdi AMINI <joke...@gmail.com
> <mailto:joke...@gmail.com>> wrote:
>
>
>
> On Thu, Feb 11, 2021 at 2:21 PM users users via llvm-dev
> <llvm...@lists.llvm.org <mailto:llvm...@lists.llvm.org>> wrote:
>
> Dear LLVM Developers:
>
> 1.   Recently I built llvm/12.0 on IBM power8 using gcc/8.2.0.

> <http://8.2.0.> When I run clang++ with an example from


> https://en.cppreference.com/w/cpp/memory/unique_ptr/make_unique
> <https://en.cppreference.com/w/cpp/memory/unique_ptr/make_unique>:
>
> #include <iostream>
>
> #include <iomanip>
> #include <memory>
>
> struct Vec3
> {
> int x, y, z;
>
> // following constructor is no longer needed since C++20

> Vec3(int x= 0,int y= 0,int z= 0) noexcept : x(x), y(y), z(z) { }
>
> friend std::ostream <http://en.cppreference.com/w/cpp/io/basic_ostream>& operator<<(std::ostream <http://en.cppreference.com/w/cpp/io/basic_ostream>& os,const Vec3& v) {


> return os<< "{ x=" << v.x << ", y=" << v.y << ", z=" << v.z << " }";
> }
> };
>
> int main()
> {
> // Use the default constructor.

> std::unique_ptr <http://en.cppreference.com/w/cpp/memory/unique_ptr><Vec3 > v1= std::make_unique<Vec3 >();


> // Use the constructor that matches these arguments

> std::unique_ptr <http://en.cppreference.com/w/cpp/memory/unique_ptr><Vec3 > v2= std::make_unique<Vec3 >(0,1,2);


> // Create a unique_ptr to an array of 5 elements

> std::unique_ptr <http://en.cppreference.com/w/cpp/memory/unique_ptr><Vec3[]> v3= std::make_unique<Vec3[]>(5);
>
> std::cout <http://en.cppreference.com/w/cpp/io/cout> << "make_unique<Vec3>(): " << *v1<< '\n'


> << "make_unique<Vec3>(0,1,2): " << *v2<< '\n'
> << "make_unique<Vec3[]>(5): ";

> for (int i= 0; i< 5; i++) {
> std::cout <http://en.cppreference.com/w/cpp/io/cout> << std::setw <http://en.cppreference.com/w/cpp/io/manip/setw>(i? 30 : 0) << v3[i] << '\n';


> }
> }
>
>
> It failed with the following errors:
>     Error: no member named 'make_unique' in namespace 'std'
>        std::unique_ptr<Vec3> v1 = std::make_unique<Vec3>();
>     ... ...
>
> Any idea and suggestion about what is going on? or have I missed
> something? The command I used to compile the code above:
>      $ clang++ a.cpp
>
>
> Maybe `clang++ -std=c++11 a.cpp` ?
>
>
> 2.  Comparing this llvm with my current gcc/8.2.0 on a project
> (openmp code running 1 thread), it showed that llvm is almost
> twice as slow as gcc (both compile with -O3) on my IBM power8
> machine. Is it suppose to be with such slower performance than gcc?
>
>
> It is very sensitive to how you built it, by default it'll be built
> in debug mode. For best performance you would ideally you enable
> Release mode, and bootstrap with LTO/PGO.
>
> --
> Mehdi
>
>
> Thank you very much for any advice!
>
> Best Regards,
> Shelton
>
>
>
>
>
>
>
>
>
> _______________________________________________
> LLVM Developers mailing list

> llvm...@lists.llvm.org <mailto:llvm...@lists.llvm.org>
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
> <https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev>

Reply all
Reply to author
Forward
0 new messages