當我嘗試編譯CPP未定義的參考`類::法」
$ 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
的方法出現在標題和類體。究竟是什麼錯誤?
try.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");
}
getURL.h
#ifndef _getURL
#define _getURL
class getURL {
public:
void fetch(char *url, char *filename);
};
#endif
getURL.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
'$ GCC try.cpp getURL.cpp -lcurl' – jrok
@jrok:圖書館要來在該行的末尾。 –
@Kerrek忍者! :) – jrok