当我尝试编译时
$ gcc -lcurl try.cpp
/tmp/ccJs0k9m.o: In function `main':
try.cpp:(.text+0x2d): undefined reference to `getURL::fetch(char*, char*)'
collect2: ld returned 1 exit status
该方法出现在标题和类主体中。究竟有什么问题?
尝试.cpp
#include <curl/curl.h>
#include <curl/easy.h>
#include "getURL.h"
int main(void) {
getURL my_getURL;
my_getURL.fetch("http://stackoverflow.com/", "file");
}
获取URL.h
#ifndef _getURL
#define _getURL
class getURL {
public:
void fetch(char *url, char *filename);
};
#endif
获取URL.cpp
#include <curl/curl.h>
#include <curl/easy.h>
#include <stdio.h>
class getURL {
private CURL *curl;
public getURL() {
//code
}
public void fetch(char *url, char *filename) {
//code
}
private size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream) {
//code
}
public ~getURL() {
//code
}
} //end class