This is the mail archive of the gcc-help@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]
Other format: [Raw text]

simple linking question


Friends,

I am having linking problems with user-generated libraries on my Redhat 7.2
using gcc-3.3.

To demonstrate the problem, I created the following simple example:

/* ----------------------------------------------------------------------------------------------------------------------------
FILE: /home/test/jingjing.hpp
---------------------------------------------------------------------------------------------------------------------------- */

#ifndef JINGJING_H
#define JINGJING_H

void jingjing();

#endif

/* ----------------------------------------------------------------------------------------------------------------------------
FILE: /home/test/jingjing.cpp
---------------------------------------------------------------------------------------------------------------------------- */
#include "jingjing.hpp"
#include <stdio.h>

void jingjing()
{
        fprintf(stderr, "jingjing invoked!\n");
}

/* ----------------------------------------------------------------------------------------------------------------------------
FILE: test.cpp
---------------------------------------------------------------------------------------------------------------------------- */
#include "jingjing.hpp"

int main()
{

        jingjing();

        return 0;
}

-------------------------------------------------------------------------------------------------------------------------------
compilation and linking
-------------------------------------------------------------------------------------------------------------------------------
/home/test>g++ -g -O2 -c jingjing.cpp -o jingjing.o
/home/test>ar cru libjingjing.a jingjing.o
/home/test>ranlib libjingjing.a
/home/test>chmod 755 *.o *.a
/home/test>g++ -o test.exe  -L/usr/lib -L/home/test   -ljingjing     test.cpp

At the linking stage, when I execute the last command shown on the last line (g++ -o test.exe ....),
I get the following error:
-------------------------------------------------------------------------------------------------------------------------------
/tmp/ccuw3cNo.o: In function `main':
/tmp/ccuw3cNo.o(.text+0x11): undefined reference to `jingjing()'
collect2: ld returned 1 exit status
-------------------------------------------------------------------------------------------------------------------------------

when I try 
	/home/test>g++ jingjing.o test.cpp
it generates the executable properly.

but when I try  
	/home/test>g++ libjingjing.a test.cpp
I get the same error.

Can someone tell me what is wrong?!


thanks so much

ramin




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