Mail Archives: djgpp/1994/05/20/15:44:15
I am having a problem which involves g++ and Gnu versions of ar and ld.
This problem does not seem to be specific to djgpp but I thought
someone out there might be able to help me out.
What I amd trying to do involves two libraries which are to be linked into
a third bit of code. Some sample code ( which demonstrates my problem )
look like :
================lib1.a sources============================
---file1.h------
class A {
public:
virtual void fn1( void );
protected:
virtual void fn2( void ){}
};
class B : public A {
protected:
void fn2( void );
};
----file1.cc------
#include "file1.h"
#include <iostream.h>
void A::fn1( void ){
cerr <<"A::fn1() calling fn2" <<endl;
this->fn2();
}
void B::fn2( void ){
cerr <<"B::fn2()" <<endl;
}
================lib2.a sources==============================
---file2.h-----
#include "file1.h"
extern B b;
---file2.cc----
#include "file2.h"
B b;
===============main program==================================
---main.cc---
#include "file2.h"
#include <iostream.h>
main()
{
cerr <<"main() calling b.fn1()" <<endl;
b.fn1();
}
===============end=================================================
The libraries are created using the following :
ar crs lib1.a file1.o
ar crs lib2.a file2.o
And the program is made with :
g++ main.cc -l1 -l2
This all works fine ( no warnings or errors ), but when the binary is run
the following happens:
smaug > a.out
main() calling b.fn1()
A::fn1() calling fn2
Segmentation fault
So I am wondering if I am making an error in the use of the library tools, or
there is a bug in g++, ar, or ld. The program does run as expected if the
object files are all linked directly ( ex g++ *.o ). Any help would be
appreciated.
Mike Romberg ( romberg AT spot DOT colorado DOT edu )
- Raw text -