while compiling in our test environment i encountered the following problem:
Despite the already working windows our build failed on Freebsd 9 with the following error message:
error: no member named 'all_of' in namespace 'std'
Given that i added -std=c++11 to our Cmake flags i wonder why this is not working.
clang version 3.4 (tags/RELEASE_34/final)
Target: i386-portbld-freebsd9.1
Thread model: posix
Heres the function
#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);
}
Installer Log from pkg install clang34
Installing libexecinfo: 1.1_3
Installing llvm34: 3.4_1
Installing clang34: 3.4_2
Help appreciated i thought this function was implemented some ages ago but apparently im using it wrong or maybe i totally misunderstood something both is possible im quite new to clang.
Edit: Details of the process.
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
After switching to "-stdlib=libc++" as suggested by Steve Wills, I assume its selecting the right include path (v1) but its still not found or conflicted.
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'
此错误可能是由于缺少以下内容造成的:
set( CMAKE_CXX_STANDARD 11 )
It would appear that there is something in your Cmake setup. Or maybe that Cmake isn't very good at recognizing Clang?
The following minimal example;
#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);
}
compiles without warnings using c++
or clang++
without any special directives;
c++ -Wall foo.cpp
For reference (reformatted for convenience):
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"
Notice how this only uses "-internal-isystem" "/usr/include/c++/v1"
, while your invocation also uses /usr/include/c++/4.2"
(which is from the old GCC c++ version 4.2).
要运行 all_of 函数,如果您在代码块中运行程序,则需要 c++11 编译器,然后转到setting --> compliers --> c++11 ISO c++ language standard [-std=c++11]
它肯定会工作谢谢祝你好运
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.