버전에 따른 문제점
아래의 프로그램이 red hat 9에서는
$ gcc -O2 time-timers.cpp -o time-timers
$ ./time-timers
으로 정상적으로 실행되지만, 동일한 명령
$ gcc -O2 time-timers.cpp -o time-timers
을 Fedora Core 3에서 실행하면
/tmp/ccduuohe.o(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
처럼 오류가 납니다. 뭘 고쳐주면 될까요?
#include <stdio.h>
#include <string.h>
#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <sys/time.h>
#include <unistd.h>
static struct timeval _tstart, _tend;
static struct timezone tz;
void tstart(void)
{
gettimeofday(&_tstart, &tz);
}
void tend(void)
{
gettimeofday(&_tend,&tz);
}
double tval()
{
double t1, t2;
t1 = (double)_tstart.tv_sec + (double)_tstart.tv_usec/(1000*1000);
t2 = (double)_tend.tv_sec + (double)_tend.tv_usec/(1000*1000);
return t2-t1;
}
#include <sys/utsname.h>
#define SLASHC '/'
#define SLASHSTR "/"
#include <stdio.h>
char *ver()
{
struct utsname ubuf;
static char verbuf[4*SYS_NMLN + 4];
if(uname(&ubuf))
return "LINUX UNKNOWN";
sprintf(verbuf,"%s %s %s %s",
ubuf.sysname,
ubuf.release,
ubuf.version,
ubuf.machine);
return verbuf;
}
#include <ctype.h>
size_t atoik(char *s)
{
size_t ret = 0;
size_t base;
if(*s == '0') {
base = 8;
if(*++s == 'x' || *s == 'X') {
base = 16;
s++;
}
}
else
base = 10;
for(; isxdigit(*s); s++) {
if(base == 16)
if(isalpha(*s))
ret = base*ret + (toupper(*s) - 'A');
else
ret = base*ret + (*s - '0');
else if(isdigit(*s))
ret = base*ret + (*s - '0');
else
break;
}
for(; isalpha(*s); s++) {
switch(toupper(*s)) {
case 'K': ret *= 1024; break;
case 'M': ret *= 1024*1024; break;
default:
return ret;
}
}
return ret;
}
char *applname;
int main(int ac, char *av[])
{
long count = 100000;
long i;
double t;
char *v = ver();
char *q;
applname = av[0];
if(strrchr(applname,SLASHC))
applname = strrchr(applname,SLASHC) + 1;
if(ac > 1) {
count = atoik(av[1]);
ac--;
av++;
if(count < 0)
count = 100000;
}
tstart();
for(i = 0; i < count; i++)
tend();
tend();
t = tval();
printf("%s: ",applname);
printf("%d calls to tend() = %8.3f seconds %8.3f usec/call\n",
count,
t,
(t/( (double) count ))*1E6);
return 0;
}
C++파일은 gcc 말고 g++로 컴파일해주세요..
C++파일은 gcc 말고 g++로 컴파일해주세요..
댓글 달기