c++ - std::async([](){ std::cout<< "Hello "; }) build error -


cppcon 2015: detlef vollmann “executors c++ - long story ..." starts off example:

std::async([](){ std::cout << "hello "; }); std::async([](){ std::cout << "world!\n"; }); 

c++ reference shows std::async in <future> , std::cout in <iostream>. missing make build work?

$ cat >hw.cpp <<eof > #include <iostream> > int main(){ >     std::cout << "hello world!\n"; > } > eof $ clang++ -std=c++14 hw.cpp $ ./a.out hello world! $ cat >cppcon15.cpp <<eof > #include <future> > #include <iostream> > int main(){ >     std::async([](){ std::cout << "hello "; }); >     std::async([](){ std::cout << "world!\n"; }); > } > eof $ clang++ -std=c++14 cppcon15.cpp /tmp/cppcon15-4f0a58.o: in function `std::thread::thread<std::__future_base::_async_state_impl<std::_bind_simple<main::$_1 ()>, void>::_async_state_impl(std::_bind_simple<main::$_1 ()>&&)::{lambda()#1}>(std::__future_base::_async_state_impl<std::_bind_simple<main::$_1 ()>, void>::_async_state_impl(std::_bind_simple<main::$_1 ()>&&)::{lambda()#1}&&)': cppcon15.cpp:(.text+0x2cf6): undefined reference `pthread_create' /tmp/cppcon15-4f0a58.o: in function `std::thread::thread<std::__future_base::_async_state_impl<std::_bind_simple<main::$_0 ()>, void>::_async_state_impl(std::_bind_simple<main::$_0 ()>&&)::{lambda()#1}>(std::__future_base::_async_state_impl<std::_bind_simple<main::$_0 ()>, void>::_async_state_impl(std::_bind_simple<main::$_0 ()>&&)::{lambda()#1}&&)': cppcon15.cpp:(.text+0x6bb6): undefined reference `pthread_create' clang: error: linker command failed exit code 1 (use -v see invocation) 

you need compile -pthread linker lets make use of async/future/thread functionality.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -