2

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(); });
Lawrence Aiello
4,6885 gold badges23 silver badges39 bronze badges
asked Nov 6, 2014 at 16:43
7
  • What's the line preceding this one? Commented Nov 6, 2014 at 16:45
  • 3
    Your certain your toolchain is (a) compiling with c++11 compliance and (b) supports lamdas ? Commented Nov 6, 2014 at 16:47
  • @DavidO void die(string s) { s = regex_replace(s, regex("\\$!"), *(smatch s) { return strerrno(); }); throw runtime_error(s); } Commented Nov 6, 2014 at 16:48
  • @WhozCraig my server is running on Debian with gcc (Debian 4.4.5-8) 4.4.5 Commented Nov 6, 2014 at 16:51
  • 1
    I suspected so. Lambda expression support was not added to g++ until 4.5. Read this, or this. Commented Nov 6, 2014 at 16:53

2 Answers 2

3

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++.

answered Nov 6, 2014 at 16:53
Sign up to request clarification or add additional context in comments.

3 Comments

Don't work, falls with # 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.
If you're still experiencing the error after upgrading g++ to 4.7, then you're not using the -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.
For example, create the simplest C++11 program you can, that uses some simple C++11 feature. Compile it with g++ -std=c++11 mytest.cpp -o mytest, and you can confirm for yourself in a simpler environment that the compiler flag works.
0

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.

answered Nov 6, 2014 at 16:45

10 Comments

now its falls with # 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.
Is using *(smatch s){ return strerrno(); } a new way to specify lambdas in C++?
I am not sure, I have never used C++11
There you go; 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.
I'll add that in my answer
|

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.