User forums > Using Code::Blocks

c++ lambda and <functional>

(1/1)

vurentjie:
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);

}

--- End code ---


--- 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 ===|

--- End quote ---

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();

--- End code ---

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; };

--- End code ---

vurentjie:
nevermind, this is me being silly, the error is coming from fstack protector

jarod42:
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.

Jenna:

--- Quote from: jarod42 on June 26, 2012, 04:28:00 pm ---Note that it is a linker issue, not a compiler issue.

--- End quote ---

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

Topic locked !!

Navigation

[0] Message Index

Go to full version