I am trying to compile a c++ project, but I'm getting a
我正在尝试编译一个c ++项目,但我得到了一个
undefined reference to `Webdl::GetURLS(std::string const&)'
error. My code in the calling class looks like this
错误。我在调用类中的代码看起来像这样
#include <iostream>
#include "Webdl.h"
int main()
{
using namespace std;
try
{
string hp= Webdl::GetHP("www.google.de","/webhp?output=search&sclient=psy-ab&btnG=");
vector<string> urls = Webdl::GetURLS( hp );
}
catch (std::exception& e)
{
string str(e.what());
cout << "Exception: " << str <<endl;
}
return 0;
}
The header class is:
标题类是:
#ifndef WEBDL_H
#define WEBDL_H
#include <iostream>
#include <istream>
#include <ostream>
#include <string>
#include <vector>
#include <boost/asio.hpp>
class Webdl
{
public:
static std::string GetHP(std::string url, std::string page);
static std::vector<std::string> GetURLS(const std::string &html);
};
#endif
For the compile I used
对于我使用的编译
g++ -MM ./test.cpp ./Webdl.cpp > Makefile.dep
g++ -g -Wall -O2 -std=c++11 -march=native -c -o test.o test.cpp
g++ -g -Wall -O2 -std=c++11 -march=native -c -o Webdl.o Webdl.cpp
g++ test.o Webdl.o -lboost_system -o test
I also tried compiling it in eclipse, but with the same result. I hope you can help me.
我也尝试在eclipse中编译它,但结果相同。我希望你能帮助我。
1 个解决方案
#1
1
According to your comment, you define a different, non-member function
根据您的评论,您定义了一个不同的非成员函数
std::vector<std::string> GetURLS(const std::string &html) { ... }
instead of the member function
而不是成员函数
std::vector<std::string> Webdl::GetURLS(const std::string &html) { ... }
^^^^^^^
#1
1
According to your comment, you define a different, non-member function
根据您的评论,您定义了一个不同的非成员函数
std::vector<std::string> GetURLS(const std::string &html) { ... }
instead of the member function
而不是成员函数
std::vector<std::string> Webdl::GetURLS(const std::string &html) { ... }
^^^^^^^