Mass confusion regarding New API

I am having many difficulties with the C++ API in Linux. Most of this probably due to my lack of knowledge with the new DLL files.

Using my old setup: g++ -o test test.cpp -lokFrontPanel -lusb

The following code segfaults:

okCUsbFrontPanel* target = new okCUsbFrontPanel;
delete target;

This code also segfaults;

okCUsbFrontPanel target;

The errors seemed to point to improper initialization and cleanup (using an invalid pointer to free memory).

I looked in the documentation and found a C++ example (pg 23) similar to that above and found another example (pg 27) that uses the following (which does in fact work):

xem = okUsbFrontPanel_Construct();

Digging around in the DLL files I find that the standard constructor okCUsbFrontPanel() calls the okUsbFrontPanel_Construct() so I am assuming either way should work?

Now, if I compile the DLL files into an object file and include this in my project, leaving out the library (and adding libdl), everything seems to work just fine (assuming you have the in the local directory and load/unload the library as needed).

So can someone tell me, what is the proper method for writing a C++ application to communicate with the FPGA? I don’t like the _Construct() _Destruct() stuff because I typically use smart pointers to handle allocation and this requires writing my own which defeats the purpose of using one in the first place.


Hello rseal-

You should not be linking the shared object with your final executable. It is intended to be dynamically-linked.

You only need to compile okFrontPanelDLL.cpp with your final object. Please see the example DESTester Makefile.lnx for an example.

okFrontPanelDLL.cpp allows two ways to communicate with the API. The first is through the _Construct, _Destruct methods. These are strict C and provide access to those who do not want to use C++.

The other is through a C++ wrapper written around the _Construct, et. al. methods. This is closest to your existing static library setup and would be recommended for you. As you can see in the .cpp file, this C++ class calls the C methods to do the heavy lifting.

I stumbled across this method in the DLL files and it seemed to work well but I didn’t know if this was considered standard as I found no official documentation.

One thing that might prove a little troublesome for new users is the function that loads the library. If you pass a NULL argument (which is implied in the source comments) then you had better make sure that the library resides in the current directory.

Thanks again,


Yes, I think you are right. I think this functionality needs to be a bit better documented for folks not familiar with how DLLs work. We’ll update the documentation.

It’s also not very clear what the argument there is expecting and should be better documented. Thanks for the feedback!