Pergunta

I am trying to compile a c++ project, but I'm getting a

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.

Foi útil?

Solução

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) { ... }
                         ^^^^^^^
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top