在我们的测试环境中编译时遇到了以下问题:
尽管已经运行的窗口,我们的构建在Freebsd 9上失败,并显示以下错误消息:
error: no member named 'all_of' in namespace 'std'
鉴于我将-std = c ++ 11添加到我们的Cmake标志中,我想知道为什么这不起作用。
clang version 3.4 (tags/RELEASE_34/final)
Target: i386-portbld-freebsd9.1
Thread model: posix
继承人的职能
#include <algorithm>
...
inline bool is_positive_number(const std::string & str)
{
if (str.empty())
return false;
return std::all_of(str.begin(), str.end(), ::isdigit);
}
安装程序记录来自pkg install clang34
Installing libexecinfo: 1.1_3
Installing llvm34: 3.4_1
Installing clang34: 3.4_2
帮助赞赏我认为这个功能是在很久以前实现的,但显然我使用它错了或者我完全误解了一些东西,这对于clang来说是非常新的。
编辑:流程的详细信息。
Selected GCC installation:
"/usr/local/llvm34/bin/clang" -cc1 -triple i386-portbld-freebsd9.1 -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name main.cpp -mrelocation-model static -mdisable-fp-elim -masm-verbose -mconstructor-aliases -target-cpu i486 -target-linker-version 2.17.50 -v -v -g -coverage-file /home/source/release/server/game/CMakeFiles/game_r4708M_32.dir/src/main.cpp.o -resource-dir /usr/local/llvm34/bin/../lib/clang/3.4 -D "__SVN_VERSION__=\"\"" -I /home/source/release/server/game/../../extern/include/boost -I /home/source/release/server/game/../../extern/include -I /home/source/release/server/game/../libmysql/mysql-connector-c-6.1.5-src/output/freebsd/include -I /home/source/release/server/game/../liblua/include -I /home/source/release/server/game/../libdevil -internal-isystem /usr/include/c++/4.2 -internal-isystem /usr/include/c++/4.2/backward -Wno-invalid-source-encoding -W -Wno-invalid-source-encoding -W -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /home/source/release/server/game -ferror-limit 19 -fmessage-length 237 -mstackrealign -fobjc-runtime=gnustep -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -vectorize-slp -o CMakeFiles/game_r4708M_32.dir/src/main.cpp.o -x c++ /home/source/release/server/game/src/main.cpp
clang -cc1 version 3.4 based upon LLVM 3.4 default target i386-portbld-freebsd9.1
ignoring duplicate directory "/usr/include/c++/4.2"
ignoring duplicate directory "/usr/include/c++/4.2"
ignoring duplicate directory "/usr/include/c++/4.2/backward"
#include "..." search starts here:
#include <...> search starts here:
/home/source/release/server/game/../../extern/include/boost
/home/source/release/server/game/../../extern/include
/home/source/release/server/game/../libmysql/mysql-connector-c-6.1.5-src/output/freebsd/include
/home/source/release/server/game/../liblua/include
/home/source/release/server/game/../libdevil
/usr/include/c++/4.2
/usr/include/c++/4.2/backward
/usr/local/llvm34/bin/../lib/clang/3.4/include
按照Steve Wills的建议切换到“-stdlib = libc ++”后,我认为它选择了正确的包含路径(v1),但仍未找到或发生冲突。
clang version 3.4 (tags/RELEASE_34/final)
Target: i386-portbld-freebsd9.1
Thread model: posix
Selected GCC installation:
"/usr/local/llvm34/bin/clang" -cc1 -triple i386-portbld-freebsd9.1 -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name main.cpp -mrelocation-model static -mdisable-fp-elim -masm-verbose -mconstructor-aliases -target-cpu i486 -target-linker-version 2.17.50 -v -v -g -coverage-file /home/source/release/server/game/CMakeFiles/game_r4708M_32.dir/src/main.cpp.o -resource-dir /usr/local/llvm34/bin/../lib/clang/3.4 -D "__SVN_VERSION__=\"\"" -I /home/source/release/server/game/../../extern/include/boost -I /home/source/release/server/game/../../extern/include -I /home/source/release/server/game/../libmysql/mysql-connector-c-6.1.5-src/output/freebsd/include -I /home/source/release/server/game/../liblua/include -I /home/source/release/server/game/../libdevil -internal-isystem /usr/include/c++/v1 -Wno-invalid-source-encoding -W -Wno-invalid-source-encoding -W -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /home/source/release/server/game -ferror-limit 19 -fmessage-length 237 -mstackrealign -fobjc-runtime=gnustep -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -vectorize-slp -o CMakeFiles/game_r4708M_32.dir/src/main.cpp.o -x c++ /home/source/release/server/game/src/main.cpp
clang -cc1 version 3.4 based upon LLVM 3.4 default target i386-portbld-freebsd9.1
ignoring duplicate directory "/usr/include/c++/4.2"
#include "..." search starts here:
#include <...> search starts here:
/home/source/release/server/game/../../extern/include/boost
/home/source/release/server/game/../../extern/include
/home/source/release/server/game/../libmysql/mysql-connector-c-6.1.5-src/output/freebsd/include
/home/source/release/server/game/../liblua/include
/home/source/release/server/game/../libdevil
/usr/include/c++/v1
/usr/include/c++/4.2
/usr/include/c++/4.2/backward
/usr/local/llvm34/bin/../lib/clang/3.4/include
/usr/include
End of search list.
In file included from /home/source/release/server/game/src/main.cpp:1:
In file included from /home/source/release/server/game/src/stdafx.h:12:
/home/source/release/server/game/src/../../common/utils.h:120:14: error: no member named 'all_of' in namespace 'std'
亲切的问候 马丁B.
答案 0 :(得分:0)
看来你的Cmake设置中有一些东西。 或许Cmake不太擅长识别Clang?
以下最小例子;
#include <algorithm>
#include <string>
bool is_positive_number(const std::string & str);
int main(int argc, char *argv[]) {
is_positive_number("12");
}
bool is_positive_number(const std::string & str)
{
if (str.empty())
return false;
return std::all_of(str.begin(), str.end(), ::isdigit);
}
在没有任何特殊指令的情况下使用c++
或clang++
进行无警告编译;
c++ -Wall foo.cpp
供参考(为方便起见,重新格式化):
c++ -### foo.cpp
FreeBSD clang version 3.4 (tags/RELEASE_34/final 197956) 20140216
Target: x86_64-unknown-freebsd10.0
Thread model: posix
"/usr/bin/c++" "-cc1" "-triple" "x86_64-unknown-freebsd10.0"
"-emit-obj" "-mrelax-all" "-disable-free" "-disable-llvm-verifier"
"-main-file-name" "foo.cpp" "-mrelocation-model" "static"
"-mdisable-fp-elim"
"-masm-verbose" "-mconstructor-aliases" "-munwind-tables"
"-target-cpu" "x86-64" "-resource-dir" "/usr/bin/../lib/clang/3.4"
"-internal-isystem" "/usr/include/c++/v1" "-fdeprecated-macro"
"-fdebug-compilation-dir" "/home/rsmith/tmp" "-ferror-limit" "19"
"-fmessage-length" "105" "-mstackrealign" "-fobjc-runtime=gnustep"
"-fcxx-exceptions" "-fexceptions" "-fdiagnostics-show-option"
"-fcolor-diagnostics" "-vectorize-slp" "-o" "/tmp/foo-206692.o"
"-x" "c++" "foo.cpp"
"/usr/bin/ld" "--eh-frame-hdr" "-dynamic-linker"
"/libexec /ld-elf.so.1" "--hash-style=both" "--enable-new-dtags"
"-o" "a.out" "/usr/lib/crt1.o" "/usr/lib/crti.o"
"/usr/lib/crtbegin.o" "-L/usr/lib" "/tmp/foo-206692.o"
"-lc++" "-lm" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed"
"-lc" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed"
"/usr/lib/crtend.o" "/usr/lib/crtn.o"
注意这只使用"-internal-isystem" "/usr/include/c++/v1"
,而你的调用也使用/usr/include/c++/4.2"
(来自旧的GCC c ++版本4.2)。
答案 1 :(得分:0)
此错误可能是由于缺失造成的:
set( CMAKE_CXX_STANDARD 11 )
答案 2 :(得分:0)
要运行all_of函数,您需要c ++ 11编译器
如果您在代码块中运行程序,请转到
setting --> compliers --> c++11 ISO c++ language standard [-std=c++11]
它肯定会工作
谢谢你好运