www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - MySQL

reply "Mars" <- -.-> writes:
Hello everyone.
I've been trying to use MySQL in an application on Windows, but I 
always get
 Symbol Undefined _mysql_init
I've put the lib in the correct folder, so I don't know what the problem might be. I've tried several libs, and tried to compile it myself (always converted using coffimplib), but it fails, no matter what. I've also tried to make a def file out of the lib, and the functions are definitly listed as exports there. Any idea what I might doing wrong? Mars
Jan 21 2012
next sibling parent reply DNewbie <run3 myopera.com> writes:
Please check whether your MySQL lib is 64 bit and your app is 32 bit.


On Sat, Jan 21, 2012, at 10:38 PM, Mars wrote:
 Hello everyone.
 I've been trying to use MySQL in an application on Windows, but I 
 always get
 Symbol Undefined _mysql_init
I've put the lib in the correct folder, so I don't know what the problem might be. I've tried several libs, and tried to compile it myself (always converted using coffimplib), but it fails, no matter what. I've also tried to make a def file out of the lib, and the functions are definitly listed as exports there. Any idea what I might doing wrong? Mars
-- D
Jan 21 2012
parent "Mars" <- -.-> writes:
On Saturday, 21 January 2012 at 23:44:12 UTC, DNewbie wrote:
 Please check whether your MySQL lib is 64 bit and your app is 
 32 bit.
The lib is 32 bit, just like my application.
Jan 21 2012
prev sibling next sibling parent reply =?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> writes:
On 01/21/2012 01:38 PM, Mars wrote:
 Hello everyone.
 I've been trying to use MySQL in an application on Windows, but I always
 get
 Symbol Undefined _mysql_init
I've put the lib in the correct folder, so I don't know what the problem might be. I've tried several libs, and tried to compile it myself (always converted using coffimplib), but it fails, no matter what. I've also tried to make a def file out of the lib, and the functions are definitly listed as exports there. Any idea what I might doing wrong? Mars
Are you also including the library on the command line with -L-l? For example, for ncurses: dmd ... -L-lncurses ... And if needed, also -L-L to specify the location of library files for the linker. Ali
Jan 21 2012
parent reply "Mars" <- -.-> writes:
On Sunday, 22 January 2012 at 00:50:28 UTC, Ali Çehreli wrote:
 Are you also including the library on the command line with 
 -L-l? For example, for ncurses:

  dmd ... -L-lncurses ...

 And if needed, also -L-L to specify the location of library 
 files for the linker.

 Ali
Yes, I am including it. Tried pragma and command line. And I don't get a message that the lib couldn't be found. What exactly is -L-l supposed to do? Is this valid in DMD 2.057? I get an error with it (Unknown Option). Mars
Jan 21 2012
parent reply =?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> writes:
On 01/21/2012 06:28 PM, Mars wrote:
 On Sunday, 22 January 2012 at 00:50:28 UTC, Ali Çehreli wrote:
 Are you also including the library on the command line with -L-l? For
 example, for ncurses:

 dmd ... -L-lncurses ...

 And if needed, also -L-L to specify the location of library files for
 the linker.

 Ali
Yes, I am including it. Tried pragma and command line. And I don't get a message that the lib couldn't be found. What exactly is -L-l supposed to do? Is this valid in DMD 2.057? I get an error with it (Unknown Option). Mars
-L is dmd's the linker flag option. Anything after that is passed to the linker. So -L-l passes -l to the linker: http://www.d-programming-language.org/dmd-linux.html Ali
Jan 22 2012
parent reply "Mars" <- -.-> writes:
On Sunday, 22 January 2012 at 08:11:21 UTC, Ali Çehreli wrote:
 -L is dmd's the linker flag option. Anything after that is 
 passed to the linker. So -L-l passes -l to the linker:

  http://www.d-programming-language.org/dmd-linux.html

 Ali
Let me rephrase that, is this valid for OPTLINK?
Unknown Option : LLIBMYSQL
Normally I just include the lib files in the files list (dmd foo.d bar.lib). Mars
Jan 22 2012
parent "Jesse Phillips" <jessekphillips+D gmail.com> writes:
On Sunday, 22 January 2012 at 12:11:58 UTC, Mars wrote:
 Let me rephrase that, is this valid for OPTLINK?
Unknown Option : LLIBMYSQL
Normally I just include the lib files in the files list (dmd foo.d bar.lib). Mars
No, in fact I couldn't find how to pass a library search path to optlink. It can be added to the sc.ini file, but I couldn't find a command line option. -l is an ld flag.
Jan 22 2012
prev sibling next sibling parent reply DNewbie <run3 myopera.com> writes:
On Sun, Jan 22, 2012, at 12:11 AM, Ali =C3=87ehreli wrote:
 On 01/21/2012 06:28 PM, Mars wrote:
 On Sunday, 22 January 2012 at 00:50:28 UTC, Ali =C3=87ehreli wrote:
 Are you also including the library on the command line with -L-l? For
 example, for ncurses:

 dmd ... -L-lncurses ...

 And if needed, also -L-L to specify the location of library files for
 the linker.

 Ali
Yes, I am including it. Tried pragma and command line. And I don't get a message that the lib couldn't be found. What exactly is -L-l supposed to do? Is this valid in DMD 2.057? I get an error with it (Unknown Option). Mars
=20 -L is dmd's the linker flag option. Anything after that is passed to the=
=20
 linker. So -L-l passes -l to the linker:
=20
    http://www.d-programming-language.org/dmd-linux.html
=20
 Ali
=20
I've took a look at MySQL headers, the functions use __stdcall, but in libm= ysql.dll exports table they are not decorated.
Jan 22 2012
parent "Mars" <- -.-> writes:
On Sunday, 22 January 2012 at 10:21:29 UTC, DNewbie wrote:
 I've took a look at MySQL headers, the functions use   stdcall, 
 but in libmysql.dll exports table they are not decorated.
This means...? Shouldn't it at least compile, if they are listed in the def file, coming from the lib?
Jan 22 2012
prev sibling next sibling parent DNewbie <run3 myopera.com> writes:
On Sun, Jan 22, 2012, at 01:13 PM, Mars wrote:
 On Sunday, 22 January 2012 at 10:21:29 UTC, DNewbie wrote:
 I've took a look at MySQL headers, the functions use   stdcall, 
 but in libmysql.dll exports table they are not decorated.
This means...? Shouldn't it at least compile, if they are listed in the def file, coming from the lib?
You should add 'extern(Windows)', but it would not work anyway. Can someone confirm the oplink does not handle this type of module (undecorated stdcall functions)?
Jan 22 2012
prev sibling next sibling parent reply Kapps <Kapps NotValidEmail.com> writes:
The way I did it is
1) Download C connector from mysql's website, 6.0.2 is version headers 
were made for. Remember you'll need the 32-bit one if you're using DMD 
on Windows.
2) Create the binding functions using extern(System).
3) For Windows, use 'coffimplib libmysql.dll libmysql.lib', and build 
with "PathToFile/libmysql.lib". Example: 'dmd test.d libmysql.lib'
3b) For Linux, just link to libmysqlclient. a with -L"libmysqlclient.a" 
or by just passing path.
4) Make sure that libmysql.dll (for Windows) is in the application 
folder otherwise you'll get errors when trying to run.

On 21/01/2012 3:38 PM, Mars wrote:
 Hello everyone.
 I've been trying to use MySQL in an application on Windows, but I always
 get
 Symbol Undefined _mysql_init
I've put the lib in the correct folder, so I don't know what the problem might be. I've tried several libs, and tried to compile it myself (always converted using coffimplib), but it fails, no matter what. I've also tried to make a def file out of the lib, and the functions are definitly listed as exports there. Any idea what I might doing wrong? Mars
Jan 22 2012
parent reply "Mars" <- -.-> writes:
On Sunday, 22 January 2012 at 23:23:23 UTC, Kapps wrote:
 2) Create the binding functions using extern(System).
Oh man... that was the problem. The file I used was using extern(C). Thought that was okay, it's a C lib after all. Thank you! Mars
Jan 22 2012
parent Mike Parker <aldacron gmail.com> writes:
On 1/23/2012 11:29 AM, Mars wrote:
 On Sunday, 22 January 2012 at 23:23:23 UTC, Kapps wrote:
 2) Create the binding functions using extern(System).
Oh man... that was the problem. The file I used was using extern(C). Thought that was okay, it's a C lib after all. Thank you! Mars
A number of libraries on Windows use a different calling convention. Any functions declared WINAPI or PASCAL in the C headers need to be declared either extern(Windows) or, if cross-platform, extern(System).
Jan 23 2012
prev sibling parent DNewbie <run3 myopera.com> writes:
On Sun, Jan 22, 2012, at 11:02 PM, DNewbie wrote:
 On Sun, Jan 22, 2012, at 01:13 PM, Mars wrote:
 On Sunday, 22 January 2012 at 10:21:29 UTC, DNewbie wrote:
 I've took a look at MySQL headers, the functions use   stdcall, 
 but in libmysql.dll exports table they are not decorated.
This means...? Shouldn't it at least compile, if they are listed in the def file, coming from the lib?
You should add 'extern(Windows)', but it would not work anyway. Can someone confirm the oplink does not handle this type of module (undecorated stdcall functions)?
You can try // ----- libmysql.def --------------- LIBRARY "libmysql.dll" EXETYPE NT SUBSYSTEM WINDOWS EXPORTS _mysql_init 4=mysql_init // ---------------------------------------- // ----------- mysqltest.d ---------------- import libmysql; alias void MYSQL; int main() { MYSQL *m = libmysql.mysql_init(null); return 0; } // --------------------------------------------------- // --------------- libmysql.di ------------------- alias void MYSQL; export extern (Windows) MYSQL *mysql_init(MYSQL *); // ---------------------------------------------------- $ implib /system libmysql.lib libmysql.def $ dmd mysqltest.d libmysql.lib It works..
Jan 22 2012