Languages

Menu
Sites
Language
Class not visible from Shared Library

Hi All,

I have created dynamic library for one of my project module. This library has class (Lets say TestClass).

When I link this library to my service app(By specifying library name as well as .so file path and including required header file from C++ build settings).

But normal c APIs are linked when I compile the service app. But I am not able to create TestClass object. It says undefined reference.

I have included header file also. There is no error in including header file.

 

    tizentest(); //Exported API from shared library - Works fine

    MyClass my; //Class in shared library - Gives below Error

----------------------------------------------------------

D:\AWTizenAgent\AWApplist\Debug/../src/awapplist.cpp:121: undefined reference to `MyClass::MyClass()'
D:\AWTizenAgent\AWApplist\Debug/../src/awapplist.cpp:132: undefined reference to `MyClass::~MyClass()'
D:\AWTizenAgent\AWApplist\Debug/../src/awapplist.cpp:132: undefined reference to `MyClass::~MyClass()'

Please help.

Thank you.

Edited by: Dharmesh Guna on 08 Mar, 2015

Responses

2 Replies
Evgeny Bachinin

As a start point... - if linker complains on 'undefuned reference', so you must check that your shared library exports  'TestClass' symbol (i.e. that this symbol is visible for another apps). You can check
1) symbol visibility be means of 'nm - D <your shared library>' or 'readelf' (see man for more info).  
2) if you build by gcc, check that you don't pass "-fvisibility=hidden" to gcc as a parameter

Dharmesh Guna

Hi Evgeny Bachinin,

Thanks for the suggestion. By declaring class with EXPORT_API it worked. (EXPORT_API macro is declared in tizen.h)

#ifndef MYCLASS_H_
#define MYCLASS_H_

#include <tizen.h>

class EXPORT_API MyClass {
public:
    MyClass();
    virtual ~MyClass();
};

#endif /* MYCLASS_H_ */