Using libokFrontPanel.so in a shared library

Hello,
I have another problem using libokFrontPanel.so:
In a test program I loaded the lib as stated in the examples

if (FALSE == okFrontPanelDLL_LoadLib(NULL)) { printf("FrontPanel DLL could not be loaded.\n"); }else{ printf("Frontpanel DLL loaded.\n"); device= new okCUsbFrontPanel(); }
Everything went fine: i can access the library and its classes/functions.

Now I have to make a program in the form of a shared library which uses libokFrontPanel.so to comunicate with the FPGA.

I tried using the same code and compiling my shared library in this way:

g++ -shared -ldl -o libReadoutModuleRAPS.so okFrontPanelDLL.o ReadoutModuleRAPS.o
where ReadoutModuleRAPS.o is the object of the source in which i used the code above.

When executed the library loads successfully while I have a segmentation fault when calling the constructor device= new okCUsbFrontPanel();

Is there any limitation to use libokFrontPanel.so whithin a shared library?

one more detail:

while calling //wrong snippet device->okCUsbFrontPanel();

//right snippet device=new okCUsbFrontPanel();
it results in a (LONG ~20000) loop of constructor calls:
I modified a bit okFrontPanelDLL.cpp to add some debug messages

static int i=0; okCUsbFrontPanel::okCUsbFrontPanel() { if (i>=21600){ printf("Dentro okUsbFrontPanel() %i time: %i\n",i,time(0)); } i++; h=okUsbFrontPanel_Construct(); //printf("Dentro okUsbFrontPanel() pippo: %i\n",time(0)); }
which outputs :

raps::Constructor entered. Frontpanel DLL loaded. Dentro okUsbFrontPanel() 21500 time: 1247842762 Dentro okUsbFrontPanel() 21501 time: 1247842762 Dentro okUsbFrontPanel() 21502 time: 1247842762 Dentro okUsbFrontPanel() 21503 time: 1247842762 ... Dentro okUsbFrontPanel() 21666 time: 1247842762 Dentro okUsbFrontPanel() 21667 time: 1247842762 Dentro okUsbFrontPanel() 21668 time: 1247842762 Dentro okUsbFrontPanel() 21669
where raps::Constructor entered.
is a debug text print just before loading the lib.

hope it will be of some help…

Why do you call the constructor of an already-constructed object? I’ve never done that before, so I don’t know what result is usually expected.

But to be clear, it looks like you’re calling it like this:

Box *x;
x = new Box();
x->Box();

[QUOTE=Opal Kelly Support;2547]Why do you call the constructor of an already-constructed object? I’ve never done that before, so I don’t know what result is usually expected.

But to be clear, it looks like you’re calling it like this:

Box *x; x = new Box(); x->Box(); [/QUOTE]

I’m not calling the constructor of an already-constructed object:
all I’m doing is calling the constructor okCUsbFrontPanel() to create an object “okCUsbFrontPanel *device;”

@nick2k3

In your second post, you have the following code snippet:

device->okCUsbFrontPanel();

If device is, indeed, a pointer to okCUsbFrontPanel, created like this:

okCUsbFrontPanel *device

Then the compiler shouldn’t even allow this to be compiled. It’s an invalid use of the class. The proper way to call a constructor is using the new operator or creating an instance:

okCUsbFrontPanel device();
// ... OR ...
okCUsbFrontPanel *device;
device = new okCUsbFrontPanel();

[QUOTE=Opal Kelly Support;2549]@nick2k3

In your second post, you have the following code snippet:

device->okCUsbFrontPanel();

If device is, indeed, a pointer to okCUsbFrontPanel, created like this:

okCUsbFrontPanel *device

Then the compiler shouldn’t even allow this to be compiled. It’s an invalid use of the class. The proper way to call a constructor is using the new operator or creating an instance:

okCUsbFrontPanel device(); // ... OR ... okCUsbFrontPanel *device; device = new okCUsbFrontPanel(); [/QUOTE]

I’m sorry!
I copyed/pasted the wrong code snippet.The code which gives me an error is:

device = new okCUsbFrontPanel();

Obviously device is declared as okCUsbFrontPanel *device;

I guess I’d back things out a bit and try your code straight away (not as a static library) to get a handle on things first. I don’t immediately see any problem with loading into a shared library.

— Begin quote from Opal Kelly Support;2551

I guess I’d back things out a bit and try your code straight away (not as a static library) to get a handle on things first. I don’t immediately see any problem with loading into a shared library.

— End quote

If I run my code as a stand-alone application everything works fine:

int main(int argc, char *argv]) { okCUsbFrontPanel *device; //printf("---- FPGA-TEST Application v0.1 ----\n"); if (FALSE == okFrontPanelDLL_LoadLib(NULL)) { printf("FrontPanel DLL could not be loaded.\n"); } device= new okCUsbFrontPanel(); } works fine, just like the DESTester example.

Maybe there’s something wrong in the way I compile/link the shared library?

Um shouldn’t it be

device= new okCUsbFrontPanel;

not

device= new okCUsbFrontPanel();

You want a new object of the class, not a new function call.

Dear all,

where you able to solve this problem?

I am experiencing similar problems.

MyProgram.cpp:

#define LINUX
#include “okFrontPanelDLL.h”
int main ()
{
printf("%i\n", okFrontPanelDLL_LoadLib(NULL));
okCUsbFrontPanel *xem = new okCUsbFrontPanel();
return 0;
}

compiled on debian squeeze (g++ 4.3) with

g++ -I. -L. -ldl -lokFrontPanel okFrontPanelDLL.cpp MyProgram.cpp

gives me:

helmut@salsa:~/src/fpga/pipe$ ./a.out
1
Segmentation fault

I greatly appreciate your help!

Thank you and best greetings,

Helmut

The original poster’s problem stemmed from trying to build a DLL within a DLL. As I recall, he resolved the problems.

Are you able to build and run the samples that are included?

Hello!
I have the same problem. If I build shared object that is trying to use libokFrontPanel.so then test application is segfaults during

new okCUsbFrontPanel();

call.
It seems with windows it works fine but with linux doesn’t.
I would be glad to know how to solve this.
Thank you in advance!

Hello,
I have the same problem using libokFrontPanel.so (4.06).
The code is working fine, if I static-link the okFrontPanelDLL.cpp. If I compile that lib into a shared object, I get a loop in the okCFrontPanel constructor which lead to a stack overflow.
Is there any solution??
Thanks a lot for your help,

Hi, there is thread somewhere here about this problem. Just rename okCUsbFrontPanel class in okCUsbFrontPanel.{h,cpp} files on something like MySuperPuperClass and then in your application create not okCUsbFrontPanel but MySuperPuperClass. For me it worked. гуд лак!