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
New Developer
Posts: 6
Registered: ‎08-13-2013
My Device: BlackBerry 10 - Developer
My Carrier: Telus
Accepted Solution

Compiler error - undefined reference to QMYSQLDriver

Hello all,

 

I'm trying to write C++ code to connect to a remote database in a BB10 application using a third party MySQL C++ library. However when trying to create a QMYSQLDriver object (QMYSQLDriver *driver = new QMYSQLDriver()) I get an "undefined reference to 'QMYSQLDriver::QMYSQLDriver(QObject*)'" error. I'm including <QtSql/QMYSQLDriver> and my .pro file looks like this:

 

QT += sql
CONFIG += qt warn_on cascades10
INCLUDEPATH += /Users/crrd/mysql-connector-c-6.1.1-winx64/mysql-connector-c-6.1.1-winx64/include
LIBS+= -L/Users/crrd/mysql-connector-c-6.1.1-winx64/mysql-connector-c-6.1.1-winx64/lib/mysqlclient.lib -L/Users/crrd/mysql-connector-c-6.1.1-winx64/mysql-connector-c-6.1.1-winx64/lib/libmysql.lib

 

I think it's just a linker problem, but I'm not sure exactly what needs to be linked or included. Related documents I've found aren't clear (enough for me) on this. I've also found posts of similar problems on other forums but the answers were not useful. Any ideas would be appreciated.

 

Thanks

 

 

 

Retired
Posts: 170
Registered: ‎09-06-2010
My Device: None
My Carrier: None

Re: Compiler error - undefined reference to QMYSQLDriver

Here's what I code in my .pro file if I want o include an external library in my project. Assuming my library is called libMqtt.so and it's in the <PROJECT>/assets/lib folder in my ject..

 

 

LIBS += -L../assets/lib -lMqtt

 

the -L adds the path ../assets/lib to the path of libraries to be searched and the -lMqtt identifies that libMqtt.so is to be used in my project and found on the library search path.

 

Since I'm using a shared library I wouldn't need to do anything else if the library already existed on the device. In my case it doesn't ( libMqtt.so is a private library of my own ) I need to make sure that thelibrary is available at run time. You can do this easily by adding the library path (assets/lib) as an asset in the bar-descriptor.xml file and then modifyint the LD_LIBRARY_PATH environment variable to be used at run time to include the path to the pacjaged asset. Like this:

 

<asset path="assets/lib">lib</asset>
<env var="LD_LIBRARY_PATH" value="app/native/lib:/usr/lib/qt4/lib"/>

 

Hope this helps you with your particular issue.

New Developer
Posts: 6
Registered: ‎08-13-2013
My Device: BlackBerry 10 - Developer
My Carrier: Telus

Re: Compiler error - undefined reference to QMYSQLDriver

Thanks for the tip, I made sure to add paths to my bar-descriptor, but I still don't know which library I'm missing. QMYSQLDriver is a part of the BlackBerry QtSql API reference but it's still being treated as an undefined reference. This morning I tried linking to the standard BB library libQtSql.so, but that didn't solve the problem. Something is missing, I just don't know what it is. My instincts are telling me its a library of some kind, but it might not even be that, could be just a line of code somewhere.

Retired
Posts: 170
Registered: ‎09-06-2010
My Device: None
My Carrier: None

Re: Compiler error - undefined reference to QMYSQLDriver

Ok, looking at the QMYSQLDriver BlackBerry 10 documentation I did the following:

 

ApplicationIU.cpp:

 

...
#include <QtSql>
#include <QtSql/QMYSQLDriver>
...
ApplicationUI::ApplicationUI(bb::cascades::Application *app) :
        QObject(app)
{
...
    QMYSQLDriver *foo = new QMYSQLDriver(this);
...
}

 

.pro:

 

APP_NAME = Hello_10_2

QT += sql

CONFIG += qt warn_on cascades10

include(config.pri)

 

I see the following compile error (???? = version of SDK):

 

In file included from c:/bbndk/target_10_2_0_????/qnx6/usr/include/qt4/QtSql/QMYSQLDriver:1:0,
                 from ../src/applicationui.cpp:9:
c:/bbndk/target_10_2_0_????/qnx6/usr/include/qt4/QtSql/qsql_mysql.h:52:19: fatal error: mysql.h: No such file or directory
compilation terminated.

Indeed I can't see "mysql.h" in that folder which doesn't seem right. If there's a failing #include then that sounds liek a bug to me and a DIT should be raied for it (see: http://supportforums.blackberry.com/t5/Java-Development/Developer-Issue-Tracker/td-p/271768). 

 

Just checking on the external library refences, if I remove the references to QMSQLDriver like this:

 

...
#include <QtSql>
//#include <QtSql/QMYSQLDriver>
...
ApplicationUI::ApplicationUI(bb::cascades::Application *app) :
        QObject(app)
{
...
    //QMYSQLDriver *foo = new QMYSQLDriver(this);
...
}

 

I get a clean build with the link step:

 

qcc -Vgcc_ntoarmv7le -lang-c++ -Wl,-rpath-link,C:/bbndk/target_10_2_0_????/qnx6/armle-v7/lib -Wl,-rpath-link,C:/bbndk/target_10_2_0_????/qnx6/armle-v7/usr/lib -Wl,-rpath-link,C:/bbndk/target_10_2_0_????/qnx6/armle-v7/usr/lib/qt4/lib -o o.le-v7-g/Hello_10_2 o.le-v7-g/.obj/applicationui.o o.le-v7-g/.obj/main.o o.le-v7-g/.obj/moc_applicationui.o    -LC:/bbndk/target_10_2_0_????/qnx6/armle-v7/lib -LC:/bbndk/target_10_2_0_????/qnx6/armle-v7/usr/lib -LC:/bbndk/target_10_2_0_????/qnx6/armle-v7/usr/lib/qt4/lib -LC:/bbndk/target_10_2_0_????/qnx6//usr/lib/qt4/lib -lbbcascades -lQtDeclarative -lQtScript -lQtSvg -lQtXmlPatterns -lQtGui -lQtNetwork -lsocket -lQtSql -lsqlite3 -lz -lQtCore -lm -lbps 

 So, it looks to me that the "QT += sql" flag in the .pro file has correctly sorted out the external libraries to link to via "-lQtQsl and -lsqlite3" which are in the paths "C:\bbndk\target_10_2_0_????\qnx6\armle-v7\usr\lib\qt4\lib" and "C:\bbndk\target_10_2_0_????\qnx6\armle-v7\usr\lib".

 

If you  follow  this do you see the same? What version of the SDK are you using?

 

 

 

New Developer
Posts: 6
Registered: ‎08-13-2013
My Device: BlackBerry 10 - Developer
My Carrier: Telus

Re: Compiler error - undefined reference to QMYSQLDriver

Following your instructions I see the same build output you do. I'm using version 10.1 of the sdk.

 

The reason for the "mysql.h: no such file or directory" error is that a third party mysql connector library is required to run this. You can get the appropriate one here: http://www.mysql.com/products/connector. You see these includes in my .pro in my original post.

 

Once you successfully include this library, you will no longer see the "mysql.h: no such file or directory", and instead will see the error I'm getting: "undefined reference to `QMYSQLDriver::QMYSQLDriver(QObject*)'"

Retired
Posts: 170
Registered: ‎09-06-2010
My Device: None
My Carrier: None

Re: Compiler error - undefined reference to QMYSQLDriver

Ok, we're getting there a step at a time. So, you've obtained a copy of the interfaces for MYSQL from this site  http://www.mysql.com/products/connector in the form of a header file "mysql.h" to resolve the compile time references and presumably a library ( shared object .so or static .a ) to resolve the link time external references to the.

 

I can't see a pre-made build for a BlackBerry 10 version of this library so I'm guessing you've taken the Generic Linux build and creeated a version of this library yourself using a BlackBerry 10 Library project in the NDK?  Can you verify that you've built either a dynamic or static library ( libFoo.so or libFoo.a ) successsfuly?

New Developer
Posts: 6
Registered: ‎08-13-2013
My Device: BlackBerry 10 - Developer
My Carrier: Telus

Re: Compiler error - undefined reference to QMYSQLDriver

Hmm, no I have not created my own BB10 version of the library, I've just been using the library files provided in the download. I will try to do this now and let you know how it goes.

New Developer
Posts: 6
Registered: ‎08-13-2013
My Device: BlackBerry 10 - Developer
My Carrier: Telus

Re: Compiler error - undefined reference to QMYSQLDriver

OK I'm having a lot of trouble converting the mysql connector into a BlackBerry library from its source. In between endless compiler errors and not knowing exactly which folders are needed, I'm not sure if this is going to work. I'll continue trying for now, unless you have any other ideas.

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

Re: Compiler error - undefined reference to QMYSQLDriver

Reading this thread I ended up that to make use of QMYSQLDriver, it's needed to download mysql connector source and cross compile it.

It uses cmake so I look for a toolchain for BB and I found this from lpapp blog.

I made a subdirectory named "build" and run this command inside it:

cmake .. -DCMAKE_TOOLCHAIN_FILE="/path/to/toolchai.cmake" -DSTACK_DIRECTION=1 -DCMAKE_INSTALL_PREFIX=`pwd`/install

 but after doing make it gives std errors. So I commented the lines in toolchain starting with "SET(CMAKE_CXX_" and all gone well since 91% of compilation. It complains about "comp_err not found". So I built mysq connector on host and all goes well.

I copied that comp_err executable in the build directory and run make again. Now it gives error at 96%: 

$ make
[  0%] Built target INFO_BIN
[  0%] Built target INFO_SRC
[  6%] Built target zlib
[ 11%] Built target yassl
[ 21%] Built target taocrypt
[ 40%] Built target strings
[ 81%] Built target mysys
[ 82%] Built target dbug
[ 85%] Built target vio
[ 87%] Built target regex
[ 91%] Built target mysys_ssl
[ 91%] Generating ../include/mysqld_error.h, ../sql/share/english/errmsg.sys
[ 91%] Built target GenError
Scanning dependencies of target clientlib
[ 91%] Building C object libmysql/CMakeFiles/clientlib.dir/get_password.c.o
[ 92%] Building C object libmysql/CMakeFiles/clientlib.dir/libmysql.c.o
[ 92%] Building C object libmysql/CMakeFiles/clientlib.dir/errmsg.c.o
[ 93%] Building C object libmysql/CMakeFiles/clientlib.dir/__/sql-common/client.c.o
/tmp/mysql/mysql-connector-c-6.1.2-src/sql-common/client.c:2290:1: warning: 'my_os_charset_to_mysql_charset' defined but not used [-Wunused-function]
[ 93%] Building C object libmysql/CMakeFiles/clientlib.dir/__/sql-common/my_time.c.o
[ 94%] Building C object libmysql/CMakeFiles/clientlib.dir/__/sql-common/client_plugin.c.o
[ 94%] Building CXX object libmysql/CMakeFiles/clientlib.dir/__/sql-common/client_authentication.cc.o
[ 94%] Building CXX object libmysql/CMakeFiles/clientlib.dir/__/sql/net_serv.cc.o
[ 95%] Building C object libmysql/CMakeFiles/clientlib.dir/__/sql-common/pack.c.o
[ 95%] Building C object libmysql/CMakeFiles/clientlib.dir/__/sql/auth/password.c.o
[ 96%] Building C object libmysql/CMakeFiles/clientlib.dir/mysql_trace.c.o
Linking CXX static library libclientlib.a
[ 96%] Built target clientlib
Scanning dependencies of target libmysql
[ 96%] Building CXX object libmysql/CMakeFiles/libmysql.dir/libmysql_exports_file.cc.o
Linking CXX shared library libmysqlclient.so
/usr/bin/ld: libclientlib.a(get_password.c.o): Relocations in generic ELF (EM: 40)
/usr/bin/ld: libclientlib.a(get_password.c.o): Relocations in generic ELF (EM: 40)
/usr/bin/ld: libclientlib.a(get_password.c.o): Relocations in generic ELF (EM: 40)
/usr/bin/ld: libclientlib.a(get_password.c.o): Relocations in generic ELF (EM: 40)
/usr/bin/ld: libclientlib.a(get_password.c.o): Relocations in generic ELF (EM: 40)
libclientlib.a: could not read symbols: File in wrong format
collect2: error: ld returned 1 exit status
make[2]: *** [libmysql/libmysqlclient.so.18.1.0] Error 1
make[1]: *** [libmysql/CMakeFiles/libmysql.dir/all] Error 2
make: *** [all] Error 2

 

Seems that something goes wrong compiled for host instead of qnx.

Any advice are very welcomed.

Thanks

Retired
Posts: 35
Registered: ‎10-15-2013
My Device: BlackBerry Z30
My Carrier: O2 UK

Re: Compiler error - undefined reference to QMYSQLDriver

libclientlib.a: could not read symbols: File in wrong format
This implies that your library is not built for ARM. Do
file libclientlib.a
to see what it is.