Is it possible for f90 link to MySQL?

Is it possible for f90 link to MySQL?

I'm using linux and wander whether it's possible to link to MySQL in f90. Any suggestion is appreciated!

11 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

You probably noticed there is a prior thread about this

http://software.intel.com/en-us/forums/topic/344492

but you aren't at all specific about what problem you are facing.

Well, that other thread is for Windows.  Doing a Google search on "mysql fortran linux" shows several promising links. http://asthomas.com/mysql_dist/MySQL_AST.htm looks especially interesting.

Steve - Intel Developer Support

Thank you very much for the reply!

I have google a lot, and found some solution, but I'm new in both linux and mysql, it's very hard to follow those step. Here is what I did:

I have downloaded mysql.f90by Daniel Kraft. Then I compiled it with ifort -c mysql.f90 to got the myfortran_binding.mod and mysql.o . Then I wrote a main program test.f90 with only one sentenct USE myfortran_binding and compiled it. Then I linked the two together with ifort test.o mysql.o and got the following errors

mysql.o: In function `myfortran_binding_mp_myfortran_connect_':
mysql.f90:(.text+0x61): undefined reference to `mysql_init'
mysql.f90:(.text+0x261): undefined reference to `mysql_connect'
mysql.f90:(.text+0x2b6): undefined reference to `c_error'
mysql.o: In function `myfortran_binding_mp_myfortran_disconnect_':
mysql.f90:(.text+0x344): undefined reference to `mysql_close'

and so on. I'm sure I have missed something important but I don't know what is it

Attachments: 

AttachmentSize
Download mysql.f9010.06 KB

Did you have a mysql library to link against?

I have mysql in the linux server and I can access it without any problem. But I don't know where the library is and how to link it? So I should link my program something like this ?

ifort test.o mysql.o mysql_library.o

The library would be more likely to appear as a libmysql.a or .so file; you could link either by appending the library name, as you suggested, or by adding -L/sql_library_directory/ -lmysql

I tried 

find / -name libmysql

but got nothing. And I tried go to /usr/lib but still find nothing. I tried search on the Internet but still don't know how to install this library (I download mysql-connector-c-6.0.2-linux-glibc2.3-ia64-64bit from http://dev.mysql.com/downloads/ but don't work). I use

apt-cache search libmysql

there is only c++ edition. Please give me some tip how I can install the library?

Hi Hang S.

as TimP mentioned, the thread http://software.intel.com/en-us/forums/topic/344492 contains a lot of information on MySQL and Fortran bindings. In my posts in this thread you will find a slightly modified version of Daniel Kraft's mysql-fortran-bindings. For me this works very nice on Windows x64 with ifort (12.1.x.x) and Linux x64 with GCC 4.6.x as well as ifort. Be shure to use x64. At 32 bit you will get problems with STDCALL and ifort (for Windows, Linux 32 bit no idea whether it works without problems).

As Linux distro we use ScientificLinux 6.3 and SuseEnterprize 11.1 and the most current version of mysql-client for these platforms. Recently I tested Mint 13 LTS also successfully. On all systems we use Eclipse Indigo SR2 for Parallel Applications as IDE. There we set the linker to link against /usr/lib/64/mysql/libmysqlclient_r.so on SELinux. The location of this lib varies on the Linux distributions. I don't know whether the C++ connectors work too. We just installed mysql-client via the package manager.

Hope that helped.

Kind regards,

Johannes

You may use "locate libmysqlclient.so" or "locate libmysqlclient_r.so" to find the location of the necessary lib (/usr/lib/x86_64-linux-gnu/libmysqlclient.so at Mint 13 LTS). No results means that mysqlclient is not installed. Just as an info, the _r version is the thread-save version we use for our parallel application. You don't need to install the connectors if you already have mysql-client.

Regards,

Johannes

Hi TimP, Johannes :

Thank you so much! I finally succeed, using mod-mysqlfortran-binding.f90. And find the libmysqlclient.so under/usr/lib/x86_64-linux-gnu/ .Now I can link my program successfully and do query to mysql. It was wonderful !

Leave a Comment

Please sign in to add a comment. Not a member? Join today