OS X / Clang will not use C ++ 11 headers

system information: OS X 10.10.5, Clang = Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn), cmake = 2.8.12.2

Suppose I have a simple file, main.cpp:

#include <stdio.h>

#include <vector>

#include <algorithm>

int main(void)
{
    std::vector<int> v{1, 2, 3, 4};

    int sum = std::accumulate(v.begin(), v.end(), 0);

    printf("Sum = %d\n", sum);
    return 0;
 }

When I run "clang ++ -stdlib = libC ++ -std = C ++ 11 main.cpp", I get the error:

main.cpp: 11: 20: error: no member named 'accumulate' in the namespace 'std' int sum = std :: accumulate (v.begin (), v.end (), 0);

When I look using the IDE (Qt Creator), I see that the included header is /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/algorithm

when I browse my file system, I see that / usr / include / c ++ / 4.2.1 exists with C ++ 11 compatible headers.


cmake ( ).

, CMakeLists.txt :

project(c11Test)
cmake_minimum_required(VERSION 2.8)

set(CMAKE_VERBOSE_MAKEFILE ON)

set(CMAKE_CXX_FLAGS "-stdlib=libc++ -std=gnu++11")

add_executable(${PROJECT_NAME} main.cpp)

, , ():

[100%] CXX CMakeFiles/c11Test.dir/main.cpp.o /usr/bin/ ++ -stdlib = lib++ -std = gnu ++ 11 -o CMakeFiles/c11Test.dir/main.cpp.o -c/Users/username/c11Test/main.cpp /Users/username/c 11Test/main.cpp:11:20: : "" "std"     int sum = std:: accumulate (v.begin(), v.end(), 0);                ~~~~~ ^.

( ):

, , , , , , . .

, , , OS X , , , ?

+4
1

:

( , , obv.) - <numeric> - . OSX, . , <algorithm> - , , , . .

+10

Source: https://habr.com/ru/post/1607697/


All Articles