grabURL.cpp 및 grabURL.hpp 파일이 두 개 있습니다. gcc로 둘 다 컴파일하면 여러 정의 오류가 발생합니다.C에서 다중 정의 오류가 발생했습니다
grabURL.cpp
#include "grabURL.hpp"
size_t buffer(void *ptr, size_t size, size_t nmemb, void *stream) {
int numbytes = size*nmemb;
char lastchar = *((char *) ptr + numbytes - 1);
*((char *) ptr + numbytes - 1) = '\0';
ret.append((char *)ptr);
ret.append(1,lastchar);
*((char *) ptr + numbytes - 1) = lastchar;
return size*nmemb;
}
void grabURL(std::string url, std::string *theRet){
curl_easy_setopt(curl,CURLOPT_URL,url.c_str());
curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION, buffer);
res = curl_easy_perform(curl);
*theRet = ret;
}
grabURL.hpp :
#ifndef CURLURLGRAB_HPP
#define CURLURLGRAB_HPP
#include <string>
#include <curl/curl.h>
CURL * curl;
CURLcode res;
std::string ret;
size_t buffer(void *ptr, size_t size, size_t nmemb, void *stream);
void grabURL(std::string url,std::string* theRet);
#endif
가 내가 뭘 잘못 몰라, 내가 제대로 ifndef가 일을했다 생각했다. 정확히 무엇이 잘못 되었습니까? 헤더 파일에
* 정확한 * 오류 메시지 란 무엇입니까? –
g ++ main.cpp grabURL.cpp -o test -lcurl /tmp/cceVAPGI.o:(bss+0x0) : 'curl'다중 정의 /tmp/ccC6uR4k.o:(.bss+0x0) : 첫 번째 여기서 정의 됨 /tmp/cceVAPGI.o:(.bss+0x8) :'res '의 다중 정의 /tmp/ccC6uR4k.o:(.bss+0x8) : 여기서 처음 정의 됨 /tmp/cceVAPGI.o :(.bss + 0x10) :'ret '의 다중 정의 /tmp/ccC6uR4k.o:(.bss+0x10) : 여기에서 처음 정의 됨 – Thundaboom