2013-10-02 4 views
0

먼저 호출하려고하는 함수는 외부 라이브러리에 없습니다. 그것은 다음의 일부입니다 (나는 C++로 다시 얻고, 그래서 난 내 자신의 cron 디먼 구현을 작성하여 시작할 것이라고 생각했다) 여기 C++ 코드에서 구현되고 템플릿화된 함수에 대한 정의되지 않은 참조

내 코드입니다 : 여기

#include <iostream> 
#include <fstream> 
#include <cstdlib> 
#include <time.h> 

using namespace std; 

//Global Variables: 
    //local time in the form of a tm struct 
    struct tm sysclocktime; 
    /* 
    * tm_sec int seconds after the minute 0-60* 
    * tm_min int minutes after the hour 0-59 
    * tm_hour int hours since midnight 0-23 
    * tm_mday int day of the month 1-31 
    * tm_mon int months since January 0-11 
    * tm_year int years since 1900  
    * tm_wday int days since Sunday 0-6 
    * tm_yday int days since January 1 0-365 
    * tm_isdst int Daylight Saving Time flag 0-? 
    */ 



//Function Declarations: 
    bool fexists(const char *filename); 
    char* timetostring(struct tm timeobj); 

//Functions:  
int main(int argc, char* argv[]){ 
    //error counter 
    int errors = 0; 

    //Set the current time by the system's clock 
    time_t  now = time(0); 
    sysclocktime = *localtime(&now); 
    //Print the current time to cout: 
    cout << "Current time is: " << timetostring(sysclocktime) << endl; 

    //See if mcron.cfg (mcron config file) exists 
    if(fexists("mcron.cfg")){ 
     //if mcron.cfg exists, read data from it 
     cout << "mcron.cfg existiert bereits!" << endl; 
    }else{ 
     //if mcron.cfg doesn't exist, create it 
     cout << "mcron.cfg existiert nicht! :(" << endl; 
    } 
    return errors; 
} 


/* 
* Function which tells whether a file exists 
*/ 
bool fexists(const char *filename){ 
    ifstream ifile(filename); 
    return ifile; 
} 

/* 
* Converts the pointer to a time struct into dates and times in a string 
* format like so: YYYY-MM-DD-HH-MM-SS 
* For example: 2013-07-15-16-14-36 
*/ 
char* timetostring(struct tm* timeobj){ 
//Declare local variable charstring which will be used to create the string of characters 
    char* charstring = new char[20]; 
    //Initialize charstring with relevant time data 
sprintf(charstring,"%4d-%2d-%2d-%2d-%2d-%2d",(timeobj->tm_year+1900), (timeobj->tm_mon+1),timeobj->tm_mday,timeobj->tm_hour,timeobj->tm_min,timeobj->tm_sec); 
    //Print the string of characters to the command line: 
    cout << "timetostring(): " << charstring; 
    return charstring; 
} 

그리고 것은 내가 무엇을 얻을 컴파일하려고 할 때 :

[[email protected] ~/code/mcron]$ g++ mcron.cpp -o mcron 
/tmp/cc9M4We8.o: In function `main': 
mcron-nostring.cpp:(.text+0xd1): undefined reference to `timetostring(tm)' 
collect2: Error: ld returned 1 as it's exit status 

내가 뭘 잘못하고 있니?

+1

'문자 * timetostring (구조체 TM의 timeobj을),'문자'대 * timetostring (구조체 TM *을 timeobj);'차이점에 유의 하시겠습니까? – jrok

답변

1
귀하의 선언은 포인터없는

:

char* timetostring(struct tm* timeobj); 
         //^here 

(플러스 당신이 전화에 적응해야하는)

+0

감사합니다. 나는 그것을 놓쳤다는 것을 믿을 수 없다. – KG6ZVP

관련 문제