Compiling against ROOT libraries

Hi,
I’m trying to get an executable to access a MySQL database. I’ve seen that ROOT has some classes to IO into this kind of DB. Below here there’s an “Hello World” attempt that I’m not able to run without errors (on Yosemite and with ROOT 6.02/02). I’ve put together different suggestions to write the Makefile so I’m not sure this is the best way to set it up.
This first attempt wants to create a new table but I think it crashes at the very beginning.

What am I missing?

Thanks.

main.cpp:

[code]#include
#include “TSQLServer.h”
#include “TSQLResult.h”

using namespace std;

int main(int argc, char *argv[])
{
TSQLServer *db = TSQLServer::Connect(“mysql://localhost”, “admin”, “”);
TSQLResult *res;

res = db->Query(“CREATE TABLE MyTest”);
delete res;
delete db;

return EXIT_SUCCESS;
}
[/code]

Makefile:

[code] CC = g++
EXTENSION =
VERSION = .v0.0
CFLAGS = -c -Wall root-config --cflags
LDFLAGS = root-config --glibs
INC = -I. -I$(ROOTSYS)/include
SOURCES = main.cpp
DEPS =
OBJECTS = $(SOURCES:.cpp=.o)
EXECUTABLE = TestMySQL

all: $(SOURCES) $(EXECUTABLE)

$(EXECUTABLE): $(OBJECTS)
$(CC) $(LDFLAGS) $(INC) $(OBJECTS) -o $@$(VERSION)${EXTENSION}

.cpp.o:
$(CC) $(CFLAGS) $(INC) $< -o $@

clean:
rm -f *.o $(EXECUTABLE)[/code]

I get the following error:

[code]Error in TMacOSXSystem::FindDynamicLibrary: RMySQL[.so | .dll | .dylib | .sl | .dl | .a] does not exist in /Applications/ROOT/root-v6-02-02/lib:/Applications/ROOT/root-v6-02-02/lib::.:/Applications/ROOT/root-v6-02-02/lib::/usr/local/lib:/usr/X11R6/lib:/usr/lib:/lib:/lib/x86_64-linux-gnu:/usr/local/lib64:/usr/lib64:/lib64:

*** Break *** segmentation violation
Generating stack trace…
0x0000000000000001 in [/code]

Bye…

Hi,

the runtime system of ROOT is not able to dynamically load the library you need for TMySQLServer libRMySQL.so.
Some questions to get near the solution:
How did you compile ROOT?
Is the shared library available in $ROOTSYS? (it looks like in your case it is /Applications/ROOT/root-v6-02-02/lib)
Does the following line show the same error on the root prompt?

root[0] TSQLServer *db = TSQLServer::Connect("mysql://localhost", "admin", "");

Cheers,
Danilo

Hi Danilo. Thanks a lot for your reply. My answers below.

[quote=“dpiparo”]Hi,

the runtime system of ROOT is not able to dynamically load the library you need for TMySQLServer libRMySQL.so.
Some questions to get near the solution:
How did you compile ROOT?[/quote]

sudo ./configure macosx64 --all
sudo make -j 2

[quote=“dpiparo”]
Is the shared library available in $ROOTSYS? (it looks like in your case it is /Applications/ROOT/root-v6-02-02/lib)[/quote]

Nope:
ll $ROOTSYS/lib/libRM*
ls: /Applications/ROOT/root-v6-02-02/lib/libRM*: No such file or directory

The option “–all” doesn’t really mean all?

No:
root -l
root [0] TSQLServer *db = TSQLServer::Connect(“mysql://localhost”, “admin”, “”);
root (cont’ed, cancel with .@) [1].@
root [2]

See if you have “mysql” in the list returned by:
root-config --features
or if you get “yes” when you try:
root-config --has-mysql

root-config --has-mysql
no

root-config --features
asimage astiff bonjour builtin_afterimage builtin_ftgl builtin_freetype builtin_glew builtin_pcre builtin_lzma builtin_llvm libcxx cocoa explicitlink fink fftw3 gdml genvector http krb5 ldap memstat minuit2 opengl python roofit rpath shared sqlite ssl table tmva unuran vc vdt xml thread

I’m not a MacOS X expert -> for Linux you can find some hints in [url=https://root-forum.cern.ch/t/root-and-mysql-without-installing-mysql/12014/2 old thread[/url].

You need to configure and build your ROOT completely from scratch again.
Right after the “configure” step (before running “make”), see the newly created “config.log” file and make sure that you see “mysql” in the list “Result: Enabled support for …” (almost in the end of this file).

BTW. For your “TestMySQL”, I think you will need:
LDFLAGS = root-config --glibs -lRMySQL

Thanks a lot!
I will try asap!

Hi,

to integrate a little the comments of Wile, you can take advantage of brew, fink or macports to obtain sql.

Cheers,
Danilo

I already have it from XAMPP.
I’m trying to understand how to give to ./configure all the paths needed to locate include files and libraries (hoping that this makes sense).

Little step ahead:

sudo ./configure macosx64 --enable-mysql --with-mysql-incdir=/Applications/XAMPP/xamppfiles/include --with-mysql-libdir=/Applications/XAMPP/xamppfiles/lib | grep mysql

INFO: --enable-mysql: already enabled by default.
Checking for mysql_config … not found
Checking for mysql.h … /Applications/XAMPP/xamppfiles/include
Checking for libmysqlclient_r, libmysqlclient, or mysqlclient … no
Unable to find any JVMs matching version “(null)”.
No Java runtime present, try --request to install.

1 - How can I specify where mysql_config is? I tried:
export MYSQL=/Applications/XAMPP/xamppfiles/bin
but nothing changed

2 - ./configure doesn’t find the client’s libs but they are all there:
ls /Applications/XAMPP/xamppfiles/lib/libmysqlclient*
/Applications/XAMPP/xamppfiles/lib/libmysqlclient.18.dylib /Applications/XAMPP/xamppfiles/lib/libmysqlclient_r.18.dylib
/Applications/XAMPP/xamppfiles/lib/libmysqlclient.a /Applications/XAMPP/xamppfiles/lib/libmysqlclient_r.a
/Applications/XAMPP/xamppfiles/lib/libmysqlclient.dylib /Applications/XAMPP/xamppfiles/lib/libmysqlclient_r.dylib

What am I missing?

Hi,

some more diagnosis.
How did you install mysql?
I tried with Brew and it is recognised by ROOT.

Cheers,
Danilo

I’ve it in XAMPP which is a package that gives Apache, MySQL and PHP ready to go in a tarball.

Hi,

what happens if you try with Brew?
Note that with this package manager it is particularly easy to remove packages in order not to pollute the system.

Danilo

Well, you could try to find the place where the “mysql_config” script is present:
find /Applications/XAMPP -name mysql_config -print

If you really have the “mysql_config” script in “/Applications/XAMPP/xamppfiles/bin” then, before running “configure”, try to:
export PATH="/Applications/XAMPP/xamppfiles/bin:${PATH}"

Hi Danilo and Wile,
thanks for you suggestions!

Danilo …
your option seems to work; after installing brew and its mysql formula, configure finds all the stuff (I’ve not compiled it). The problem with this solution is that during the installation I get:
A “/etc/my.cnf” from another install may interfere with a Homebrew-built
I’d like to avoid conflicts with XAMPP because I’m already using its mysql.

Wile …
With your suggestion (that doesn’t create any conflict) I move a step forward but something is still missing:
sudo ./configure macosx64 --all | grep mysql
Checking for mysql_config … /Applications/XAMPP/xamppfiles/bin/mysql_config
Checking for libmysqlclient version >= 3.23.* … ok
Checking for mysql.h … no
How can I pass to configure the path to mysql.h?

You can try to manually add:
–with-mysql-incdir=
–with-mysql-libdir=

However, it should be done automatically by the “configure” script.
See what you get from:
mysql_config --cflags
mysql_config --libs

I tried it but it forgets about mysql_config and libmysql*:

echo $PATH
/Applications/XAMPP/xamppfiles/bin:/Applications/ROOT/root-v6-02-02Compiled/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/texbin:/usr/texbin

sudo ./configure macosx64 --with-mysql-incdir=/Applications/XAMPP/xamppfiles/include --with-mysql-libdir=/Applications/XAMPP/xamppfiles/lib | grep mysql
Password:
Checking for mysql_config … not found
Checking for mysql.h … /Applications/XAMPP/xamppfiles/include
Checking for libmysqlclient_r, libmysqlclient, or mysqlclient … no
Unable to find any JVMs matching version “(null)”.
No Java runtime present, try --request to install.

mysql_config --cflags
-I/Applications/XAMPP/xamppfiles/include -I/Applications/XAMPP/xamppfiles/include/c-client -I/Applications/XAMPP/xamppfiles/include/freetype2 -L/Applications/XAMPP/xamppfiles/lib -I/Applications/XAMPP/xamppfiles/include -I/Applications/XAMPP/xamppfiles/include/ncurses -arch x86_64 -Os -g -fno-strict-aliasing

mysql_config --libs
-L/Applications/XAMPP/xamppfiles/lib -lmysqlclient -lpthread -lssl -lcrypto

Well, it a bug in ROOT’s “configure” script.
When parsing the output of your “mysql_config --cflags”, it will happily take “mysqlincdir=/Applications/XAMPP/xamppfiles/include/ncurses”.

I’ve tried to fix it changing:
mysqlincdir=$mysql_config --cflags | sed -e 's,^.*-I\([^ ]*\).*$,\1,' -e s/\'//g

into:
mysqlincdir=$mysql_config --cflags | tr " " "\n" | grep include | grep -v include/ | tail -n 1 | sed -e 's,^.*-I\([^ ]*\).*$,\1,' -e s/\'//g

I’m trying to recompile now.

Another step forward. The library now exists but ROOT (and the exe that I’m creating) can’t load it:

ll /Applications/ROOT/root-v6-02-02Compiled/lib/ | grep MySQL
-rw-r–r-- 1 root admin 220B Jan 19 10:05 libRMySQL.rootmap
-rwxr-xr-x 1 root admin 90K Jan 19 10:05 libRMySQL.so
-rw-r–r-- 1 root admin 370B Jan 19 10:05 libRMySQL_rdict.pcm

./TestMySQL.v0.0
cling::DynamicLibraryManager::loadLibrary(): dlopen(/Applications/ROOT/root-v6-02-02Compiled/lib/libRMySQL.so, 9): Library not loaded: libmysqlclient.18.dylib
Referenced from: /Applications/ROOT/root-v6-02-02Compiled/lib/libRMySQL.so
Reason: image not found
Error in TInterpreter::TCling::AutoLoad: failure loading library libRMySQL.so for TMySQLServer
cling::DynamicLibraryManager::loadLibrary(): dlopen(/Applications/ROOT/root-v6-02-02Compiled/lib/libRMySQL.so, 9): Library not loaded: libmysqlclient.18.dylib
Referenced from: /Applications/ROOT/root-v6-02-02Compiled/lib/libRMySQL.so
Reason: image not found

*** Break *** segmentation violation
Generating stack trace…
0x0000000000000001 in

root -l
root [0] gSystem->Load("/Applications/ROOT/root-v6-02-02Compiled/lib/libRMySQL. (*** TAB to check if ROOT finds it ***)

libRMySQL.rootmap
libRMySQL.so
root [0] gSystem->Load("/Applications/ROOT/root-v6-02-02Compiled/lib/libRMySQL.so");
cling::DynamicLibraryManager::loadLibrary(): dlopen(/Applications/ROOT/root-v6-02-02Compiled/lib/libRMySQL.so, 9): Library not loaded: libmysqlclient.18.dylib
Referenced from: /Applications/ROOT/root-v6-02-02Compiled/lib/libRMySQL.so
Reason: image not found