即使已链接类,也会出现未定义的引用错误

时间:2014-05-09 00:00:47

标签: c++ linux eclipse linker

我正在尝试编译一个c ++项目,但我得到了一个

undefined reference to `Webdl::GetURLS(std::string const&)'

错误。我在调用类中的代码看起来像这样

#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;
}

标题类是:

#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

对于我使用的编译

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

我也尝试在eclipse中编译它,但结果相同。我希望你能帮助我。

1 个答案:

答案 0 :(得分:1)

根据您的评论,您定义了一个不同的非成员函数

std::vector<std::string> GetURLS(const std::string &html) { ... }

而不是成员函数

std::vector<std::string> Webdl::GetURLS(const std::string &html) { ... }
                         ^^^^^^^
相关问题