accessing class in shared object (library)

In short: I have a library (.so) that has C++ classes implemented. Now I want to be able to access a class in the lib. Example:

#include "myclass.h"
main (int arc, char** argv){
class myclass x();
x.myclassfunc();
}

What should be in "myclass.h"? Or is there another method to do this?

Any help greatly appreciated.
TIA

ken
The class itself is presumably declared in the header, so it's a matter of linking the library correctly. Assuming you've doing that correctly, the issue with your code is that

class myclass x(); is not an object. It's a function declaration, of a function that takes in 0 parameters, and returns a myclass object.

Just do:
1
2
myclass x;
x.myclassfunc();


PS: it should be int main, not just main.

If you are still getting linker errors, post how you're building your library and program. I am assuming this is some *nix system you're on?
Last edited on
This is a tizen app (using Tizen Studio). As I said, the classes are defined/implemented in the lib (I created the lib in a separate project). I guessed that the lib needs to create a header file to be used to define the classes that are exported within it. That is the part I am missing. How do I create that, or, what is in it?

Also, the IDE has a bug that adds the -l<name> before the -L<path> for the linker command, so that part of the linking fails.

About PS: yes I know it is int main, I didn't think it was too important. The "class" part was just an attempt; actually extern myclass x; compiles, but because of the above IDE bug, won't link.
And:
 
myclass x(); // (should) call myclass::myclass(). myclass x; does the same 


Just being a bit too nerdy :-).

thanks for the response.

myclass x(); // (should) call myclass::myclass(). myclass x; does the same

No. As Ganado pointed out, this declares x as a function accepting no parameters and returning myclass.
Last edited on
If the IDE has a bug, then I'm not quite sure what we can do, but maybe you have the IDE invoke a separate build script that you yourself create?

If you're trying to create a myclass object, the file you're compiling needs to know what a myclass is (this is before the linking stage). So does your header contain something along the lines of :
1
2
3
class myclass {
  // ...
};
in it?
Last edited on
Topic archived. No new replies allowed.