This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Query:linking


I have just joined this list. I am facing some problems when i link .o
files created by gcc and g++ respectively.

In particular i had 3 files

1)Test.h
//Test.h
void print (int j) ;


2)Test.c
//Test.c

#include "Test.h"

void print(int j)
{
    //print j...
}

3) Test1.cc
//Test1.cc

#include "Test.h"

int main()
{

    print(2);
}


And i used gcc as follows

>gcc -c test.c //fine
>g++ -c test1.cc  //fine
>g++ test.o test1.o //oops!!

i get the following error

test1.o : In function main()
test1.o (.text +0x6) :undefined reference to 'print(int)'
collect2: ld returned 1 exit status

I  run RED Hat 6.2 gcc version egcs-2.9166

Can anyone tell me the reason for this behavior?

Thanks in advance!
Bipin


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]