未定义模板 'std::__1::function<int (double, double, double, double)>' 的隐式实例化

4
在我正在处理的项目中,我尝试使用curlpp库来进行简单的HTML GET请求。当我将cpp文件传递给g++时,我收到以下错误信息:
/usr/local/include/curlpp/internal/CurlHandle.hpp:185:42: error: implicit instantiation of undefined template 'std::__1::function<int (double, double, double, double)>'
curlpp::types::ProgressFunctionFunctor mProgressFunctor;
/usr/local/include/curlpp/internal/CurlHandle.hpp:134:66: error: implicit instantiation of undefined template 'std::__1::function<int (double, double, double, double)>'
void setProgressFunctor(curlpp::types::ProgressFunctionFunctor functor)

我对c++还比较陌生,所以希望能得到帮助。我在macOS Sierra上工作。我使用Homebrew安装了curlpp(即它位于/usr/local/Cellar中)。


这是我的代码:

  1 #include <string>
  2 #include <sstream>
  3 #include <iostream>
  4 #include <curlpp/cURLpp.hpp>
  5 #include <curlpp/Easy.hpp>
  6 #include <curlpp/Options.hpp>
  7 
  8 using namespace curlpp::options;
  9 
 10 int main(int, char **)
 11 {   
 12     try 
 13     {   
 14         curlpp::Cleanup testCleanup;
 15         curlpp::Easy miRequest;
 16         miRequest.setOpt<Url>("http://www.wikipedia.org");
 17         miRequest.perform();
 18     }
 19     catch(curlpp::RuntimeError & e)
 20     {   
 21         std::cout << e.what() << std::endl;
 22     }
 23     catch(curlpp::LogicError & e)
 24     {   
 25         std::cout << e.what() << std::endl;
 26     }
 27     
 28     return 0;
 29 }

你的代码是什么?你能复制粘贴一下你尝试过的吗? - petersohn
@petersohn 完成 - Jack Westmore
我尝试过了,在Ubuntu 16.04和gcc环境下,并没有出现这个错误。 - petersohn
@petersohn,所以代码在你那里编译和运行都没问题吗? - Jack Westmore
不,我遇到了链接器错误。但编译还是没有问题的。 - petersohn
1个回答

2

只需要在编译选项中添加-std=c++11 或者 -std=c++14 来通知编译器您希望使用较新的 C++ 标准。而 std::function 只是其中一个在 2011 年之前不存在的东西。


谢谢,我使用 clang++ -std=c++11 -stdlib=libc++ -I /usr/local/Cellar 进行了编译,但仍然无法正常工作。 - Jack Westmore

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接