Return to BSD News archive
Path: sserve!newshost.anu.edu.au!harbinger.cc.monash.edu.au!msuinfo!agate!howland.reston.ans.net!pipex!sunic!trane.uninett.no!eunet.no!nuug!EU.net!julienas!news-rocq.inria.fr!alix.inria.fr!soulard
From: soulard@alix.inria.fr (Herve Soulard)
Newsgroups: comp.os.386bsd.questions
Subject: Dynamic C++ object with FreeBSD
Date: 9 Jul 1994 13:43:39 GMT
Organization: INRIA
Lines: 83
Distribution: world
Message-ID: <2vm9ib$kll@news-rocq.inria.fr>
Reply-To: soulard@sor.inria.fr
NNTP-Posting-Host: alix.inria.fr
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
Hello,
I'm looking for an expert in both gcc and FreeBSD to give me some
help in implementing dynamically loaded objects.
Here is what I want to do.
I have the following class in Bar.hxx:
class Bar {
int i;
public:
Bar(void);
~Bar(void);
virtual int set(int);
static Bar* NEW(void);
};
and its code in Bar.cxx:
#include "Bar.hxx"
Bar::Bar(void) {
i = 0;
}
Bar::~Bar(void) {
}
int Bar::set(int a) {
i = a;
return i;
}
Bar* Bar::NEW(void) {
return new Bar;
}
and a test:
#include <stdio.h>
#include <sys/types.h>
#include <nlist.h>
extern "C" {
#include <link.h>
}
#define PATH "./bar.so"
#include "bar.hxx"
main()
{
void *addr;
void *(*fp)(void);
Bar *bar;
addr = dlopen(PATH, 1);
fp = (void *(*)(void))dlsym(addr, "_NEW__3Bar");
bar = (*fp)();
bar->set(3);
}
This code works on SunOS with CC and on OSF1 with cxx (with some change
to includes and mangled symbol for NEW).
I would like to make it works on FreeBSD with gcc. But I cannot get it.
Does somebody know which option to gcc and to ld I must give, and if
I usec correctly the dl functions.
Herve Soulard.
PS: I would prefer email answers.