Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Highlighted
Developer
Posts: 121
Registered: ‎03-13-2012
My Device: P'9981, Z10, Q10, Z30, Passport
My Carrier: BT

Issue calling shared library static function

[ Edited ]

Hi all,

 

I've created a shared library project (Utils) containing a UtilsLogger class, which contains a static function logError:

 

Snippet from UtilsLogger.cpp:

 

void UtilLogger::logError(bool logEnabled, QString logName, QString logfileText)
{
	if(logEnabled)
	{
	QString workingDir = QDir::currentPath();
	QDateTime currTime = QDateTime::currentDateTime();

	QFile textfile("file://" + workingDir + "/shared/misc/" + logName + "-" + currTime.toString("dd.MM.yyyy") + ".txt");
	textfile.open(QIODevice::WriteOnly | QIODevice::Text);
	QTextStream out(&textfile);
	out << logfileText;
	textfile.close();
	}
}

 Snippet from UtilityLogger.hpp:

class UtilLogger {
public:
	UtilLogger();
	virtual ~UtilLogger();

	static void logError(bool logEnabled, QString logName, QString logfileText);
};

 The project builds fine.

 

When referenced in my main project using the following line:

UtilLogger::logError(true,"TestLog","Help!");

 I get the following compile error:

undefined reference to `UtilLogger::logError(bool, QString, QString)'

 In my main project I reference the UtilLogger in the hpp file as #include "UtilLogger.hpp".

 

 I've referenced objects in shared libraries before, but I've never done it using a static function.

 

Do I need to add anything to the .pro file?

 

Retired
Posts: 418
Registered: ‎07-18-2012
My Device: Q10
My Carrier: Bell Canada

Re: Issue calling shared library static function

Hi,

 

The two most likely causes:

 

1. It's not actually in the library.

 

Can you use readelf to list all the symbols in the library and check that you see your function.

 

eg: C:\bbndk\host_10_2_0_15\win32\x86\usr\bin>ntoarm-readelf.exe -a libName 

 

2. Library isn't being linked. 

 

What configuration changes did you make to add this library to your project?

 

Thanks.

 

 

 

 

 

ps: Conceptually does this function make sense as a member of a class, or should it just be in a namespace?

--
Rob is no longer associated with BlackBerry.
Developer
Posts: 121
Registered: ‎03-13-2012
My Device: P'9981, Z10, Q10, Z30, Passport
My Carrier: BT

Re: Issue calling shared library static function

[ Edited ]

Hi robbieDubya,

 

To import the library I did the following steps:

 

1) Right click the main project, --> Properties --> Project references --> Selected my Utils project

2) In the same window, expanded C/C++ General --> GNU C --> Added Utils/src

3) References tab --> expanded Utils project and selected Device-Release

 

Other libraries I have imported using the same steps seem to work as expected.

 

I also get the following error when I run the command:

 

C:\bbndk10.2\host_10_2_0_15\win32\x86\usr\bin>ntoarm-readelf.exe -a libUtils
readelf: Error: 'libUtils': No such file

 

So I'm obviously missing a step... (the binary file compiled for the library is libUtils.so) - and as for using a namespace - you are correct - I have altered the code and now I get "error: 'logError' is not a member of 'UtilLogger'" - this is my modified library code (UtilLogger.cpp):

 

namespace UtilLogger{

void logError(bool logEnabled, QString logName, QString logfileText)
{

...

}
}

 

Developer
Posts: 77
Registered: ‎05-21-2012
My Device: DA C, Z10 LE, Passport
My Carrier: TIM

Re: Issue calling shared library static function

have you added in the .pro file a line like this ?

LIBS += -lUtils

 

and maybe add "-L[pathToLibrary]

Developer
Posts: 121
Registered: ‎03-13-2012
My Device: P'9981, Z10, Q10, Z30, Passport
My Carrier: BT

Re: Issue calling shared library static function

[ Edited ]

I've tried:

 

LIBS += -lUtils
LIBS += -LD:/WorkspaceBB10.2/Utils/Device-Release/ -lUtils
LIBS += -L/Utils/Device-Release/ -lUtils
LIBS += -L/Utils/ -lUtils

 

I've removed the line calling the library (as that always errors and it seems to hide the error messages in the .pro file) and I always get the following error:

 

C:\bbndk10.2\host_10_2_0_15\win32\x86\usr\bin\ntoarm-ld: cannot find -lUtils

 

I've also tried adding the library as a project using the "Add Library" wizard (right click project --> Configure --> Add library...)

Developer
Posts: 77
Registered: ‎05-21-2012
My Device: DA C, Z10 LE, Passport
My Carrier: TIM

Re: Issue calling shared library static function

you can try also to modify the LD_LIBRARY PATH in you bar-descriptor.xml. You should have something like:

 

<env var="LD_LIBRARY_PATH" value="app/native/lib:/usr/lib/qt4/libSmiley Very Happy:/WorkspaceBB10.2/Utils/Device-Release"/>

 

I am not sure about the "D:". Also when you added the library with the wizard, you should have lines like:

 

<configuration name="Device-Debug">
	<platformArchitecture>armle-v7</platformArchitecture>
	<asset path="arm/o.le-v7-g/AppName" entry="true" type="Qnx/Elf">AppName</asset>
	<asset path="D:/WorkspaceBB10.2/Utils/Device-Release/libUtils.a" type="Qnx/Elf">lib/libUtils.a</asset>
</configuration>
<configuration name="Device-Release">
	<entryPointType>Qnx/Cascades</entryPointType>
	<platformArchitecture>armle-v7</platformArchitecture>
	<asset path="arm/o.le-v7/AppName.so" entry="true" type="Qnx/Elf">AppName.so</asset>
	<asset path="D:/WorkspaceBB10.2/Utils/Device-Release/libUtils.a" type="Qnx/Elf">lib/libUtils.a</asset>
</configuration>

 Also take care of the compiled version of your library. In the "Device-Release" you should put the library compiled in release mode and the same for "Device-Debug"

Developer
Posts: 121
Registered: ‎03-13-2012
My Device: P'9981, Z10, Q10, Z30, Passport
My Carrier: BT

Re: Issue calling shared library static function

Thanks, i'll take a look this evening.

This is a headless app so there is no bar descriptor for this project - will that make a difference, or do I simply add it into the GUI project?
Retired
Posts: 418
Registered: ‎07-18-2012
My Device: Q10
My Carrier: Bell Canada

Re: Issue calling shared library static function

Hi,

 

Headless app still needs a bar descriptor - its just another entry point in the .xml...

 

Thanks.

--
Rob is no longer associated with BlackBerry.
Developer
Posts: 121
Registered: ‎03-13-2012
My Device: P'9981, Z10, Q10, Z30, Passport
My Carrier: BT

Re: Issue calling shared library static function

So my main GUI project does, but the actual headless project doesn't - one of the guides I followed on the BlackBerry site said bar descriptor and assets folder are not required for the headless project - or is that incorrect?

The app seems to function as expected currently (apart from the issue with accessing the static function).

Cheers -
Retired
Posts: 418
Registered: ‎07-18-2012
My Device: Q10
My Carrier: Bell Canada

Re: Issue calling shared library static function

Ok - AFAIK;

 

Thanks.

--
Rob is no longer associated with BlackBerry.