Now I'm trying to install RealPlexor by dklab, but it's falls with errors:
# bash ./Make.sh
In file included from dklab_realplexor.cpp:68:
utils/misc.h: In function ‘void die(std::string)’:
utils/misc.h:105: error: expected primary-expression before ‘[’ token
compilation terminated due to -Wfatal-errors.
Here is that line
s = regex_replace(s, regex("\\$!"), [](smatch s) { return strerrno(); });
-
What's the line preceding this one?DavidO– DavidO2014年11月06日 16:45:14 +00:00Commented Nov 6, 2014 at 16:45
-
3Your certain your toolchain is (a) compiling with c++11 compliance and (b) supports lamdas ?WhozCraig– WhozCraig2014年11月06日 16:47:03 +00:00Commented Nov 6, 2014 at 16:47
-
@DavidO void die(string s) { s = regex_replace(s, regex("\\$!"), *(smatch s) { return strerrno(); }); throw runtime_error(s); }Kirill Danshin– Kirill Danshin2014年11月06日 16:48:34 +00:00Commented Nov 6, 2014 at 16:48
-
@WhozCraig my server is running on Debian with gcc (Debian 4.4.5-8) 4.4.5Kirill Danshin– Kirill Danshin2014年11月06日 16:51:25 +00:00Commented Nov 6, 2014 at 16:51
-
1I suspected so. Lambda expression support was not added to g++ until 4.5. Read this, or this.WhozCraig– WhozCraig2014年11月06日 16:53:53 +00:00Commented Nov 6, 2014 at 16:53
2 Answers 2
Make sure that you are passing the following flag to your compiler (as described in the the g++ documentation):
-std=c++11
This tells the gcc compiler (g++) to compile your code with C++11 semantics.
The lambda expression syntax you are using (the part starting with []) is a C++11 feature, and will cause compilers great confusion if it appears in code that they aren't expecting to be C++11.
However, as has been pointed out in another comment here (and is confirmed by this table, the version of gcc you are running (4.4.5, per a comment) doesn't have lambda expression support. May have to use a function object instead, or upgrade to a newer version of gcc/g++.
3 Comments
# bash ./Make.sh In file included from dklab_realplexor.cpp:68:0: utils/misc.h: In function ‘void die(std::string)’: utils/misc.h:105:50: error: expected primary-expression before ‘s’ compilation terminated due to -Wfatal-errors. -std=c++11 flag as documented in gcc.gnu.org/onlinedocs/gcc/Standards.html , and judging from some of your other comments, I would say you probably need to set Make.sh to generate the appropriate flags in the project's makefile.g++ -std=c++11 mytest.cpp -o mytest, and you can confirm for yourself in a simpler environment that the compiler flag works.Just say
s = regex_replace(s, regex("\\$!"), *(smatch s) { return strerrno(); });
The [] operator is usually used to index something (like a character array), so C++ expects something in front of it
Also try this suggestion from @DavidO:
You're using a lambda expression which is a C++11 syntax, but probably haven't set your compiler to recognize C++11. If you're using g++, you would use the -std=c++11 flag.
10 Comments
# bash ./Make.sh In file included from dklab_realplexor.cpp:68: utils/misc.h: In function ‘void die(std::string)’: utils/misc.h:105: error: expected primary-expression before ‘s’ compilation terminated due to -Wfatal-errors. *(smatch s){ return strerrno(); } a new way to specify lambdas in C++?-std=c++11 flag.