[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
undefined reference Error in compiling *.cpp with gcc
From: |
bozloo |
Subject: |
undefined reference Error in compiling *.cpp with gcc |
Date: |
19 Jan 2006 20:21:15 -0800 |
User-agent: |
G2/0.2 |
Fedora linux system.
i woudl like to complie simple sample cpp file.
files are main.cpp a.cpp b.cpp.
when i compile this files. undefined reference error is occured.
i dont know reason why...
that is link error i thought.
thx alot.
----------------------------------------------
main.cpp
#include <stdio.h>
#include "a.h"
#include "b.h"
int main(void)
{
int x = 1;
int y = 3;
int z = 0;
float a = 3.0f;
float b = 2.0f;
float c = 0.0f;
printf("entered main\n");
z = a_sum(x, y);
c = b_sum(a, b);
printf("z=%d, c=%f\n", z, c);
}
a.cpp
int a_sum(int x, int y)
{
return x+y;
}
b.cpp
float b_sum(float x, float y)
{
return x + y;
}
a.h
extern "C" {
extern int a_sum(int a, int b);
}
b.h
extern "C"
{
extern float b_sum(float x, float y);
}
---------------------
gcc -D_REENTRANT -I/home/bozlo/test1 -lpthread -L. -o test.out
/home/bozlo/test1/a.o /home/bozlo/test1/b.o /home/bozlo/test1/main.o
/home/bozlo/test1/main.o(.text+0x63): In function `main':
main.cpp: undefined reference to `a_sum'
/home/bozlo/test1/main.o(.text+0x77):main.cpp: undefined reference to
`b_sum'
/home/bozlo/test1/main.o(.eh_frame+0x11): undefined reference to
`__gxx_personality_v0'
collect2: ld returned 1 exit status
- undefined reference Error in compiling *.cpp with gcc,
bozloo <=