2015-04-03 25 views
2

使用Travis-CI我試圖建立一個使用std::make_unique的C++項目。但是我得到生成錯誤:如何在叮3.4中使用make_unique?

no member named 'make_unique' in namespace 'std' 
      mFiles.emplace_back(std::make_unique<File>(*this, rec)); 

我已經包括memory,這個代碼編譯在VS2013和gcc 4.8與-std=c++14。如果我使用鐺3.4這個標誌我得到一個錯誤:

error: invalid value 'c++14' in '-std=c++14' 

根據鐺文檔:

http://clang.llvm.org/cxx_status.html

,我應該使用-std=c++1y但仍yeilds相同no member named 'make_unique' in namespace 'std'。那麼我如何才能使它工作?

+0

嘗試使用-std = C++ 1y改爲-std = C++ 14 – senfen 2015-04-03 12:17:46

+0

閱讀我的最後一句,這會產生相同的錯誤 – paulm 2015-04-03 12:18:46

+0

您確定這是一個C++ 14功能嗎?我認爲它也存在於C++ 11中。試過''-std = C++ 11 -stdlib = libC++''? – BitTickler 2015-04-03 12:22:56

回答

2

這不依賴於編譯器,而是依賴於標準庫實現。 std::make_unique不是核心語言功能,而是庫函數。

檢查Travis使用的版本libstdc++


the GCC 4.9 changelogstd::make_unique引入libstdc++各地GCC 4.9的發佈時間。

如果Travis正在使用4.9版之前的GCC版本,很可能它的libstdc++版本還沒有std::make_unique

+0

我升級了gcc到travis上的4.9,拉到了新的libstdC++,現在make_unique在-ngd = -C++ 1y中工作 – paulm 2015-04-05 12:49:21