Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 14 Oct 2000 17:49:04 +0200
From:      "Nicolai Petri" <nppsecure@swamp.dk>
To:        <freebsd-questions@freebsd.org>
Subject:   How to compile and link a lib for use with dlopen() ?
Message-ID:  <000701c035f6$47f66190$6732a8c0@atomic.dk>

next in thread | raw e-mail | index | archive | help
I'm porting some software from Windows (I know it....) and it is using
external dll's that's dynamic loaded with LoadModule() and GetProcAddr().
The Unix equivalent i think is dlopen() and dlsym().

My question is how to compile and link the following 2 pieces of code to
make it work.

The code is just out of the head written and just as an example... It can't
compile,

I've tried some different compiler settings... But 'nm' does not list my
exported functions... ?? Please help.

----------- utility.cpp ----------- This should be in test.so.1 lib.
#include <stuff.>

class A
{
    public:
    int GetValue();
    void SetValue(int);
};

extern "C"
{
    A* GetNewA()    /* This function I want exported */
    {
        return new A;
    }
};

------ use.cpp ----------
#include <stuff.h>

typedef  (A*)(EntryFunc*)();

int main()
{
    int h = dlopen("test.so.1");
    EntryFunc GetA=dlsym(h,"GetNewA");
    A* test = GetA();
 /* Do other stuff */
};


Thanx for any help you can give me :o).

---
Nicolai Petri




To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?000701c035f6$47f66190$6732a8c0>