使用clock_gettime对函数进行未定义的引用

时间:2014-12-03 22:57:22

标签: c++

我正在尝试创建一个简单的测试来计算某些功能。我正在使用以下文件main.cpp和testTiming.hpp。我无法编译,我收到以下错误:main.cpp:16:未定义的引用`startProfile(TIME_ID)'。我的函数定义有什么不正确的吗?

testTiming.hpp

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

enum TIME_ID
{
    TIME1 = 0,
    TIME2 = 1,
    NUM_TIMES = 2
};

typedef struct timeTable
{
    timespec lastStartTime;
    timespec totalTime;
} timeTable;

timeTable mTimeTable[NUM_TIMES];

void inline stopProfile( TIME_ID timeId );

timespec inline diff(timespec start, timespec end)
{
    timespec temp;
    if ((end.tv_nsec-start.tv_nsec) < 0) {
        temp.tv_sec = end.tv_sec - start.tv_sec - 1;
        temp.tv_nsec = 1000000000+end.tv_nsec-start.tv_nsec;
     } else {
        temp.tv_sec = end.tv_sec - start.tv_sec;
        temp.tv_nsec = end.tv_nsec - start.tv_nsec;
     }
     return temp;
}

void inline startprofile( TIME_ID timeId)
{
    if (timeId = TIME1)
    {
        stopProfile(TIME1);
    }

    clock_gettime(CLOCK_THREAD_CPUTIME_ID, &(mTimeTable[timeId].lastStartTime));
    //clock_gettime(CLOCK_REALTIME, &(mTimeTable[timeId].lastStartTime));
};

void inline stopProfile( TIME_ID timeId)
{
    timespec stopTime;
    timespec diffTime;
    clock_gettime(CLOCK_THREAD_CPUTIME_ID, &(stopTime));
    //clock_gettime(CLOCK_REALTIME, &(stopTime));
    diffTime = diff(mTimeTable[timeId].lastStartTime, stopTime);
    mTimeTable[timeId].totalTime.tv_sec += diffTime.tv_sec;
    mTimeTable[timeId].totalTime.tv_nsec += diffTime.tv_nsec;

    if (timeId != TIME1)
    {
        startprofile(TIME1);
    }
};

void printprofile(void)
{
    int i;
    for(i = 0; i < NUM_TIMES; i++)
    {
        switch( i)
        {
        case TIME1:
        printf("PROFILE : TIME1: %f s\n", (float) mTimeTable[i].totalTime.tv_sec + float                  
        (mTimeTable[i].totalTime.tv_nsec / 1000000000.0f) );
        break;
        case TIME2:
        printf("PR0FILE : TIME2P: %d %f s\n", (float) mTimeTable[i].totalTime.tv_sec + float 
        (mTimeTable[i].totalTime.tv_nsec / 1000000000.0f) );
        printf("PR0FILE : TIME2W: %d %f s\n", (float) mTimeTable[i].totalTime.tv_sec + float   
        (mTimeTable[i].totalTime.tv_nsec) );
        break;
        default:
        break;
        } 
    }
};

的main.cpp

#include "testTiming.hpp"
#include <time.h>

using namespace std;

void inline startProfile( TIME_ID timeId );
void inline printProfile( void );

int main(int argc, char** argv)
{
int sec = 5;

startProfile(TIME1);
sleep(sec);
stopProfile(TIME1);
//printProfile();

return 0;
}

生成文件

ls SHELL = /bin/csh

all :
    g++ main.cpp -g -o timeTest

clean:
    rm -f timeTest

0 个答案:

没有答案