错误1:
/tmp/ccEeAok8.o: In function `main':
follypromise.cpp:(.text+0x1c6): undefined reference to `folly::Future
follypromise.cpp:(.text+0x245): undefined reference to `folly::Future
follypromise.cpp:(.text+0x264): undefined reference to `folly::Future
/tmp/ccEeAok8.o: In function `folly::demangle(std::type_info const&)':
follypromise.cpp:(.text._ZN5folly8demangleERKSt9type_info[_ZN5folly8demangleERKSt9type_info]+0x2a): undefined reference to `folly::demangle(char const*)'
/tmp/ccEeAok8.o: In function `folly::MicroSpinLock::lock()':
follypromise.cpp:(.text._ZN5folly13MicroSpinLock4lockEv[_ZN5folly13MicroSpinLock4lockEv]+0xd1): undefined reference to `google::LogMessageFatal::LogMessageFatal(char const*, int)'
follypromise.cpp:(.text._ZN5folly13MicroSpinLock4lockEv[_ZN5folly13MicroSpinLock4lockEv]+0xe2): undefined reference to `google::LogMessage::stream()'
follypromise.cpp:(.text._ZN5folly13MicroSpinLock4lockEv[_ZN5folly13MicroSpinLock4lockEv]+0x127): undefined reference to `google::LogMessageFatal::~LogMessageFatal()'
follypromise.cpp:(.text._ZN5folly13MicroSpinLock4lockEv[_ZN5folly13MicroSpinLock4lockEv]+0x13b): undefined reference to `google::LogMessageFatal::~LogMessageFatal()'
/tmp/ccEeAok8.o: In function `folly::MicroSpinLock::unlock()':
follypromise.cpp:(.text._ZN5folly13MicroSpinLock6unlockEv[_ZN5folly13MicroSpinLock6unlockEv]+0x6b): undefined reference to `google::LogMessageFatal::LogMessageFatal(charconst*, int)'
follypromise.cpp:(.text._ZN5folly13MicroSpinLock6unlockEv[_ZN5folly13MicroSpinLock6unlockEv]+0x7c): undefined reference to `google::LogMessage::stream()'
follypromise.cpp:(.text._ZN5folly13MicroSpinLock6unlockEv[_ZN5folly13MicroSpinLock6unlockEv]+0xc1): undefined reference to `google::LogMessageFatal::~LogMessageFatal()'
follypromise.cpp:(.text._ZN5folly13MicroSpinLock6unlockEv[_ZN5folly13MicroSpinLock6unlockEv]+0x112): undefined reference to `google::LogMessageFatal::~LogMessageFatal()'
/tmp/ccEeAok8.o: In function `folly::RequestContext::saveContext()':
follypromise.cpp:(.text._ZN5folly14RequestContext11saveContextEv[_ZN5folly14RequestContext11saveContextEv]+0xd): undefined reference to `folly::RequestContext::getStaticContext()'
/tmp/ccEeAok8.o: In function `folly::RequestContextScopeGuard::RequestContextScopeGuard(std::shared_ptr
follypromise.cpp:(.text._ZN5folly24RequestContextScopeGuardC2ESt10shared_ptrINS_14RequestContextEE[_ZN5folly24RequestContextScopeGuardC5ESt10shared_ptrINS_14RequestContextEE]+0x3e): undefined reference to `folly::RequestContext::setContext(std::shared_ptr
/tmp/ccEeAok8.o: In function `folly::RequestContextScopeGuard::~RequestContextScopeGuard()':
follypromise.cpp:(.text._ZN5folly24RequestContextScopeGuardD2Ev[_ZN5folly24RequestContextScopeGuardD5Ev]+0x39): undefined reference to `folly::RequestContext::setContext(std::shared_ptr
/tmp/ccEeAok8.o: In function `folly::Promise
follypromise.cpp:(.text._ZN5folly7PromiseIiE9getFutureEv[_ZN5folly7PromiseIiE9getFutureEv]+0x36): undefined reference to `folly::Future
/tmp/ccEeAok8.o: In function `_ZN5folly6FutureIiE18thenImplementationIPFviENS_6detail14callableResultIiS4_EELb0EJOiEEENSt9enable_ifIXntsrNT0_13ReturnsFutureE5valueENSA_6ReturnEE4typeEOT_NS5_9argResultIXT1_ESF_JDpT2_EEE':
follypromise.cpp:(.text._ZN5folly6FutureIiE18thenImplementationIPFviENS_6detail14callableResultIiS4_EELb0EIOiEEENSt9enable_ifIXntsrNT0_13ReturnsFutureE5valueENSA_6ReturnEE4typeEOT_NS5_9argResultIXT1_ESF_IDpT2_EEE[_ZN5folly6FutureIiE18thenImplementationIPFviENS_6detail14callableResultIiS4_EELb0EIOiEEENSt9enable_ifIXntsrNT0_13ReturnsFutureE5valueENSA_6ReturnEE4typeEOT_NS5_9argResultIXT1_ESF_IDpT2_EEE]+0x1d): undefined reference to `folly::Future
follypromise.cpp:(.text._ZN5folly6FutureIiE18thenImplementationIPFviENS_6detail14callableResultIiS4_EELb0EIOiEEENSt9enable_ifIXntsrNT0_13ReturnsFutureE5valueENSA_6ReturnEE4typeEOT_NS5_9argResultIXT1_ESF_IDpT2_EEE[_ZN5folly6FutureIiE18thenImplementationIPFviENS_6detail14callableResultIiS4_EELb0EIOiEEENSt9enable_ifIXntsrNT0_13ReturnsFutureE5valueENSA_6ReturnEE4typeEOT_NS5_9argResultIXT1_ESF_IDpT2_EEE]+0x7d): undefined reference to `folly::Future
follypromise.cpp:(.text._ZN5folly6FutureIiE18thenImplementationIPFviENS_6detail14callableResultIiS4_EELb0EIOiEEENSt9enable_ifIXntsrNT0_13ReturnsFutureE5valueENSA_6ReturnEE4typeEOT_NS5_9argResultIXT1_ESF_IDpT2_EEE[_ZN5folly6FutureIiE18thenImplementationIPFviENS_6detail14callableResultIiS4_EELb0EIOiEEENSt9enable_ifIXntsrNT0_13ReturnsFutureE5valueENSA_6ReturnEE4typeEOT_NS5_9argResultIXT1_ESF_IDpT2_EEE]+0x12b): undefined reference to `folly::Future
/tmp/ccEeAok8.o: In function `folly::Promise
follypromise.cpp:(.text._ZN5folly7PromiseINS_4UnitEE9getFutureEv[_ZN5folly7PromiseINS_4UnitEE9getFutureEv]+0x36): undefined reference to `folly::Future
/tmp/ccEeAok8.o: In function `_ZN5folly6FutureIiE12setCallback_IZNS1_18thenImplementationIPFviENS_6detail14callableResultIiS5_EELb0EJOiEEENSt9enable_ifIXntsrNT0_13ReturnsFutureE5valueENSB_6ReturnEE4typeEOT_NS6_9argResultIXT1_ESG_JDpT2_EEEEUlONS_3TryIiEEE_EEvSH_':
follypromise.cpp:(.text._ZN5folly6FutureIiE12setCallback_IZNS1_18thenImplementationIPFviENS_6detail14callableResultIiS5_EELb0EIOiEEENSt9enable_ifIXntsrNT0_13ReturnsFutureE5valueENSB_6ReturnEE4typeEOT_NS6_9argResultIXT1_ESG_IDpT2_EEEEUlONS_3TryIiEEE_EEvSH_[_ZN5folly6FutureIiE12setCallback_IZNS1_18thenImplementationIPFviENS_6detail14callableResultIiS5_EELb0EIOiEEENSt9enable_ifIXntsrNT0_13ReturnsFutureE5valueENSB_6ReturnEE4typeEOT_NS6_9argResultIXT1_ESG_IDpT2_EEEEUlONS_3TryIiEEE_EEvSH_]+0x18): undefined reference to `folly::Future
/tmp/ccEeAok8.o: In function `folly::detail::Core
follypromise.cpp:(.text._ZN5folly6detail4CoreIiED2Ev[_ZN5folly6detail4CoreIiED5Ev]+0x4b): undefined reference to `google::LogMessageFatal::LogMessageFatal(char const*, int)'
follypromise.cpp:(.text._ZN5folly6detail4CoreIiED2Ev[_ZN5folly6detail4CoreIiED5Ev]+0x5c): undefined reference to `google::LogMessage::stream()'
follypromise.cpp:(.text._ZN5folly6detail4CoreIiED2Ev[_ZN5folly6detail4CoreIiED5Ev]+0xa1): undefined reference to `google::LogMessageFatal::~LogMessageFatal()'
/tmp/ccEeAok8.o: In function `folly::detail::Core
follypromise.cpp:(.text._ZN5folly6detail4CoreIiE16CountedReferenceC2EPS2_[_ZN5folly6detail4CoreIiE16CountedReferenceC5EPS2_]+0x4f): undefined reference to `google::LogMessageFatal::LogMessageFatal(char const*, int)'
follypromise.cpp:(.text._ZN5folly6detail4CoreIiE16CountedReferenceC2EPS2_[_ZN5folly6detail4CoreIiE16CountedReferenceC5EPS2_]+0x60): undefined reference to `google::LogMessage::stream()'
follypromise.cpp:(.text._ZN5folly6detail4CoreIiE16CountedReferenceC2EPS2_[_ZN5folly6detail4CoreIiE16CountedReferenceC5EPS2_]+0xa5): undefined reference to `google::LogMessageFatal::~LogMessageFatal()'
/tmp/ccEeAok8.o: In function `folly::detail::Core
follypromise.cpp:(.text._ZN5folly6detail4CoreINS_4UnitEED2Ev[_ZN5folly6detail4CoreINS_4UnitEED5Ev]+0x4b): undefined reference to `google::LogMessageFatal::LogMessageFatal(char const*, int)'
follypromise.cpp:(.text._ZN5folly6detail4CoreINS_4UnitEED2Ev[_ZN5folly6detail4CoreINS_4UnitEED5Ev]+0x5c): undefined reference to `google::LogMessage::stream()'
follypromise.cpp:(.text._ZN5folly6detail4CoreINS_4UnitEED2Ev[_ZN5folly6detail4CoreINS_4UnitEED5Ev]+0xa1): undefined reference to `google::LogMessageFatal::~LogMessageFatal()'
/tmp/ccEeAok8.o: In function `folly::detail::Core
follypromise.cpp:(.text._ZN5folly6detail4CoreINS_4UnitEE16CountedReferenceC2EPS3_[_ZN5folly6detail4CoreINS_4UnitEE16CountedReferenceC5EPS3_]+0x4f): undefined reference to `google::LogMessageFatal::LogMessageFatal(char const*, int)'
follypromise.cpp:(.text._ZN5folly6detail4CoreINS_4UnitEE16CountedReferenceC2EPS3_[_ZN5folly6detail4CoreINS_4UnitEE16CountedReferenceC5EPS3_]+0x60): undefined reference to `google::LogMessage::stream()'
follypromise.cpp:(.text._ZN5folly6detail4CoreINS_4UnitEE16CountedReferenceC2EPS3_[_ZN5folly6detail4CoreINS_4UnitEE16CountedReferenceC5EPS3_]+0xa5): undefined reference to `google::LogMessageFatal::~LogMessageFatal()'
collect2: 错误:ld 返回 1
解决办法:编译的时候加上 -std=c++1y
错误2:
/tmp/cc6gFfIq.o: In function `main':
follypromise.cpp:(.text+0x1c6): undefined reference to `folly::Future
follypromise.cpp:(.text+0x245): undefined reference to `folly::Future
follypromise.cpp:(.text+0x264): undefined reference to `folly::Future
/tmp/cc6gFfIq.o: In function `folly::demangle(std::type_info const&)':
follypromise.cpp:(.text._ZN5folly8demangleERKSt9type_info[_ZN5folly8demangleERKSt9type_info]+0x2a): undefined reference to `folly::demangle(char const*)'
/tmp/cc6gFfIq.o: In function `folly::MicroSpinLock::lock()':
follypromise.cpp:(.text._ZN5folly13MicroSpinLock4lockEv[_ZN5folly13MicroSpinLock4lockEv]+0xd1): undefined reference to `google::LogMessageFatal::LogMessageFatal(char const*, int)'
follypromise.cpp:(.text._ZN5folly13MicroSpinLock4lockEv[_ZN5folly13MicroSpinLock4lockEv]+0xe2): undefined reference to `google::LogMessage::stream()'
follypromise.cpp:(.text._ZN5folly13MicroSpinLock4lockEv[_ZN5folly13MicroSpinLock4lockEv]+0x127): undefined reference to `google::LogMessageFatal::~LogMessageFatal()'
follypromise.cpp:(.text._ZN5folly13MicroSpinLock4lockEv[_ZN5folly13MicroSpinLock4lockEv]+0x13b): undefined reference to `google::LogMessageFatal::~LogMessageFatal()'
/tmp/cc6gFfIq.o: In function `folly::MicroSpinLock::unlock()':
follypromise.cpp:(.text._ZN5folly13MicroSpinLock6unlockEv[_ZN5folly13MicroSpinLock6unlockEv]+0x6b): undefined reference to `google::LogMessageFatal::LogMessageFatal(charconst*, int)'
follypromise.cpp:(.text._ZN5folly13MicroSpinLock6unlockEv[_ZN5folly13MicroSpinLock6unlockEv]+0x7c): undefined reference to `google::LogMessage::stream()'
follypromise.cpp:(.text._ZN5folly13MicroSpinLock6unlockEv[_ZN5folly13MicroSpinLock6unlockEv]+0xc1): undefined reference to `google::LogMessageFatal::~LogMessageFatal()'
follypromise.cpp:(.text._ZN5folly13MicroSpinLock6unlockEv[_ZN5folly13MicroSpinLock6unlockEv]+0x112): undefined reference to `google::LogMessageFatal::~LogMessageFatal()'
/tmp/cc6gFfIq.o: In function `folly::RequestContext::saveContext()':
follypromise.cpp:(.text._ZN5folly14RequestContext11saveContextEv[_ZN5folly14RequestContext11saveContextEv]+0xd): undefined reference to `folly::RequestContext::getStaticContext()'
/tmp/cc6gFfIq.o: In function `folly::RequestContextScopeGuard::RequestContextScopeGuard(std::shared_ptr
follypromise.cpp:(.text._ZN5folly24RequestContextScopeGuardC2ESt10shared_ptrINS_14RequestContextEE[_ZN5folly24RequestContextScopeGuardC5ESt10shared_ptrINS_14RequestContextEE]+0x3e): undefined reference to `folly::RequestContext::setContext(std::shared_ptr
/tmp/cc6gFfIq.o: In function `folly::RequestContextScopeGuard::~RequestContextScopeGuard()':
follypromise.cpp:(.text._ZN5folly24RequestContextScopeGuardD2Ev[_ZN5folly24RequestContextScopeGuardD5Ev]+0x39): undefined reference to `folly::RequestContext::setContext(std::shared_ptr
/tmp/cc6gFfIq.o: In function `folly::Promise
follypromise.cpp:(.text._ZN5folly7PromiseIiE9getFutureEv[_ZN5folly7PromiseIiE9getFutureEv]+0x36): undefined reference to `folly::Future
/tmp/cc6gFfIq.o: In function `_ZN5folly6FutureIiE18thenImplementationIPFviENS_6detail14callableResultIiS4_EELb0EJOiEEENSt9enable_ifIXntsrNT0_13ReturnsFutureE5valueENSA_6ReturnEE4typeEOT_NS5_9argResultIXT1_ESF_JDpT2_EEE':
follypromise.cpp:(.text._ZN5folly6FutureIiE18thenImplementationIPFviENS_6detail14callableResultIiS4_EELb0EIOiEEENSt9enable_ifIXntsrNT0_13ReturnsFutureE5valueENSA_6ReturnEE4typeEOT_NS5_9argResultIXT1_ESF_IDpT2_EEE[_ZN5folly6FutureIiE18thenImplementationIPFviENS_6detail14callableResultIiS4_EELb0EIOiEEENSt9enable_ifIXntsrNT0_13ReturnsFutureE5valueENSA_6ReturnEE4typeEOT_NS5_9argResultIXT1_ESF_IDpT2_EEE]+0x1d): undefined reference to `folly::Future
follypromise.cpp:(.text._ZN5folly6FutureIiE18thenImplementationIPFviENS_6detail14callableResultIiS4_EELb0EIOiEEENSt9enable_ifIXntsrNT0_13ReturnsFutureE5valueENSA_6ReturnEE4typeEOT_NS5_9argResultIXT1_ESF_IDpT2_EEE[_ZN5folly6FutureIiE18thenImplementationIPFviENS_6detail14callableResultIiS4_EELb0EIOiEEENSt9enable_ifIXntsrNT0_13ReturnsFutureE5valueENSA_6ReturnEE4typeEOT_NS5_9argResultIXT1_ESF_IDpT2_EEE]+0x7d): undefined reference to `folly::Future
follypromise.cpp:(.text._ZN5folly6FutureIiE18thenImplementationIPFviENS_6detail14callableResultIiS4_EELb0EIOiEEENSt9enable_ifIXntsrNT0_13ReturnsFutureE5valueENSA_6ReturnEE4typeEOT_NS5_9argResultIXT1_ESF_IDpT2_EEE[_ZN5folly6FutureIiE18thenImplementationIPFviENS_6detail14callableResultIiS4_EELb0EIOiEEENSt9enable_ifIXntsrNT0_13ReturnsFutureE5valueENSA_6ReturnEE4typeEOT_NS5_9argResultIXT1_ESF_IDpT2_EEE]+0x12b): undefined reference to `folly::Future
/tmp/cc6gFfIq.o: In function `folly::Promise
follypromise.cpp:(.text._ZN5folly7PromiseINS_4UnitEE9getFutureEv[_ZN5folly7PromiseINS_4UnitEE9getFutureEv]+0x36): undefined reference to `folly::Future
/tmp/cc6gFfIq.o: In function `_ZN5folly6FutureIiE12setCallback_IZNS1_18thenImplementationIPFviENS_6detail14callableResultIiS5_EELb0EJOiEEENSt9enable_ifIXntsrNT0_13ReturnsFutureE5valueENSB_6ReturnEE4typeEOT_NS6_9argResultIXT1_ESG_JDpT2_EEEEUlONS_3TryIiEEE_EEvSH_':
follypromise.cpp:(.text._ZN5folly6FutureIiE12setCallback_IZNS1_18thenImplementationIPFviENS_6detail14callableResultIiS5_EELb0EIOiEEENSt9enable_ifIXntsrNT0_13ReturnsFutureE5valueENSB_6ReturnEE4typeEOT_NS6_9argResultIXT1_ESG_IDpT2_EEEEUlONS_3TryIiEEE_EEvSH_[_ZN5folly6FutureIiE12setCallback_IZNS1_18thenImplementationIPFviENS_6detail14callableResultIiS5_EELb0EIOiEEENSt9enable_ifIXntsrNT0_13ReturnsFutureE5valueENSB_6ReturnEE4typeEOT_NS6_9argResultIXT1_ESG_IDpT2_EEEEUlONS_3TryIiEEE_EEvSH_]+0x18): undefined reference to `folly::Future
/tmp/cc6gFfIq.o: In function `folly::detail::Core
follypromise.cpp:(.text._ZN5folly6detail4CoreIiED2Ev[_ZN5folly6detail4CoreIiED5Ev]+0x4b): undefined reference to `google::LogMessageFatal::LogMessageFatal(char const*, int)'
follypromise.cpp:(.text._ZN5folly6detail4CoreIiED2Ev[_ZN5folly6detail4CoreIiED5Ev]+0x5c): undefined reference to `google::LogMessage::stream()'
follypromise.cpp:(.text._ZN5folly6detail4CoreIiED2Ev[_ZN5folly6detail4CoreIiED5Ev]+0xa1): undefined reference to `google::LogMessageFatal::~LogMessageFatal()'
/tmp/cc6gFfIq.o: In function `folly::detail::Core
follypromise.cpp:(.text._ZN5folly6detail4CoreIiE16CountedReferenceC2EPS2_[_ZN5folly6detail4CoreIiE16CountedReferenceC5EPS2_]+0x4f): undefined reference to `google::LogMessageFatal::LogMessageFatal(char const*, int)'
follypromise.cpp:(.text._ZN5folly6detail4CoreIiE16CountedReferenceC2EPS2_[_ZN5folly6detail4CoreIiE16CountedReferenceC5EPS2_]+0x60): undefined reference to `google::LogMessage::stream()'
follypromise.cpp:(.text._ZN5folly6detail4CoreIiE16CountedReferenceC2EPS2_[_ZN5folly6detail4CoreIiE16CountedReferenceC5EPS2_]+0xa5): undefined reference to `google::LogMessageFatal::~LogMessageFatal()'
/tmp/cc6gFfIq.o: In function `folly::detail::Core
follypromise.cpp:(.text._ZN5folly6detail4CoreINS_4UnitEED2Ev[_ZN5folly6detail4CoreINS_4UnitEED5Ev]+0x4b): undefined reference to `google::LogMessageFatal::LogMessageFatal(char const*, int)'
follypromise.cpp:(.text._ZN5folly6detail4CoreINS_4UnitEED2Ev[_ZN5folly6detail4CoreINS_4UnitEED5Ev]+0x5c): undefined reference to `google::LogMessage::stream()'
follypromise.cpp:(.text._ZN5folly6detail4CoreINS_4UnitEED2Ev[_ZN5folly6detail4CoreINS_4UnitEED5Ev]+0xa1): undefined reference to `google::LogMessageFatal::~LogMessageFatal()'
/tmp/cc6gFfIq.o: In function `folly::detail::Core
follypromise.cpp:(.text._ZN5folly6detail4CoreINS_4UnitEE16CountedReferenceC2EPS3_[_ZN5folly6detail4CoreINS_4UnitEE16CountedReferenceC5EPS3_]+0x4f): undefined reference to `google::LogMessageFatal::LogMessageFatal(char const*, int)'
follypromise.cpp:(.text._ZN5folly6detail4CoreINS_4UnitEE16CountedReferenceC2EPS3_[_ZN5folly6detail4CoreINS_4UnitEE16CountedReferenceC5EPS3_]+0x60): undefined reference to `google::LogMessage::stream()'
follypromise.cpp:(.text._ZN5folly6detail4CoreINS_4UnitEE16CountedReferenceC2EPS3_[_ZN5folly6detail4CoreINS_4UnitEE16CountedReferenceC5EPS3_]+0xa5): undefined reference to `google::LogMessageFatal::~LogMessageFatal()'
collect2: 错误:ld 返回 1
编译的时候加上:-lfolly
整个程序://功能:处理异步回调功能
#include
#include
using namespace folly;
using namespace std;
void foo(int x) {
// do something with x
cout << "foo(" << x << ")" << endl;
}
// ...
int main() {
cout << "making Promise" << endl;
Promise
Future
f.then(foo);
cout << "Future chain made" << endl;
// ... now perhaps in another event callback
cout << "fulfilling Promise" << endl;
p.setValue(42);
cout << "Promise fulfilled" << endl;
return 0;
}
编译命令:g++ --std=c++11 -std=c++1y -lfolly follypromise.cpp