Author Topic: c++ lambda and <functional>  (Read 7484 times)

Offline vurentjie

  • Multiple posting newcomer
  • *
  • Posts: 13
c++ lambda and <functional>
« on: June 26, 2012, 03:52:35 pm »
not sure how to get this too compile, i have tried an updated mingw, but still get the same error

Code
#include <functional>
void foo() { }

int main() {
    std::function<void()> f(foo);

}

Quote
obj\Debug\main.o||In function `main':|
C:\Users\vurentjie-64\My Code\CPP\test_functional\main.cpp|4|undefined reference to `___stack_chk_guard'|
C:\Users\vurentjie-64\My Code\CPP\test_functional\main.cpp|7|undefined reference to `___stack_chk_guard'|
C:\Users\vurentjie-64\My Code\CPP\test_functional\main.cpp|7|undefined reference to `___stack_chk_fail'|
||=== Build finished: 3 errors, 0 warnings ===|

trying to use std::function seems to be the cause of this, for instance i can get something simple like this working

Code
auto func = [](){ std::cout << "Hello" << std::endl; };
func();

i don't actually think this is cb specific but perhaps someone else has dealt with this before.

i stumbled on this while trying to pass lambda's as arguments.

the following also errors the same

Code
std::function<void ()> fn=[](){ std::cout << "Hello" << std::endl; };


Offline vurentjie

  • Multiple posting newcomer
  • *
  • Posts: 13
Re: c++ lambda and <functional>
« Reply #1 on: June 26, 2012, 04:20:40 pm »
nevermind, this is me being silly, the error is coming from fstack protector

Offline jarod42

  • Multiple posting newcomer
  • *
  • Posts: 87
Re: c++ lambda and <functional>
« Reply #2 on: June 26, 2012, 04:28:00 pm »
It works for me with the providing code.

Note that it is a linker issue, not a compiler issue.

I succeeded to reproduce the bug by adding -fstack-protector -fstack-protector-all options.

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: c++ lambda and <functional>
« Reply #3 on: June 26, 2012, 05:47:40 pm »
Note that it is a linker issue, not a compiler issue.

Note that this question is not related to C::B and therefore violates our forum rules.

Topic locked !!