使用Folly Futures时的编译问题

时间:2016-03-07 17:16:26

标签: c++ ld folly

#include <folly/futures/Future.h>
#include<iostream>
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<int> p;
  Future<int> f = p.getFuture();
  return 0;
}

LD_LIBRARY_PATH设置为/usr/local/lib

当我编译时,使用

g++ -std=c++11 sample.cpp -pthread  -llzma -lz -lsnappy -llz4 -liberty \
    -ljemalloc -levent -ldouble-conversion -lssl -lgflags -lglog -lboost_system

我收到此错误消息:

/tmp/ccuDCM19.o: In function `main':
sample.cpp:(.text+0x1a7): undefined reference to `folly::Future<int>::~Future()'
/tmp/ccuDCM19.o: In function `folly::RequestContext::setContext(std::shared_ptr<folly::RequestContext>)':
sample.cpp:(.text._ZN5folly14RequestContext10setContextESt10shared_ptrIS0_E[_ZN5folly14RequestContext10setContextESt10shared_ptrIS0_E]+0x11): undefined reference to `folly::RequestContext::getStaticContext()'
/tmp/ccuDCM19.o: In function `folly::Promise<int>::getFuture()':
sample.cpp:(.text._ZN5folly7PromiseIiE9getFutureEv[_ZN5folly7PromiseIiE9getFutureEv]+0x36): undefined reference to `folly::Future<int>::Future(folly::detail::Core<int>*)'
collect2: error: ld returned 1 exit status

1 个答案:

答案 0 :(得分:0)

通过添加-lfolly来解决问题。