 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Andrew Fenton Guest
|
Posted: Tue Jan 13, 2004 8:46 pm Post subject: Using MySQL with Borland C++ 5.5 Compiler |
|
|
My difficulty is in linking my object code to create a working, albeit
trivial MySQL Client console application. I believe the problem I am having
is related to the library files I am using for my linking procedure or
possibly to the default make file.
Here is what I am attempting: using MySQL 4.0.15, WinXP Pro, and Borland
Command Line tools 5.5.1, I have written a source code file in C that lists
all names from a database file starting with the letter "A". I ended up
writing this in C because apparently the native MySQL API is in C and the
included header files would not work using a C++ compilation. (Yes, I know
that there is a MySQL++ API available for Borland, but I am a little bit
skeptical of using an API that its own author describes as "not tested very
much.")
Upon reading the MySQL Reference Manual and another source, I note several
requirements to consider when compiling:
1) MySQL requires WinSock 2.
2) Because MySQL client libraries were compiled as multi-threaded, my own
compilation should also be multi-threaded.
3) The header files to include from MySQL are <my_global.h> and <mysql.h>
in that order.
4) When compiling, the data alignment should be set to quad word.
I also know that I will need to have an import library to utilize the
included libmySQL.dll file, so I create one using the following command
line:
| Quote: | implib bcmysql.lib libmySQL.dll
|
This seems to work with no errors or warnings from implib.
I then compile my source code using the following:
| Quote: | bcc32 -c -tWC -tWM -tWR -a8 trialrun.c
|
Again, this works with no complaints from the compiler. A file named
"trialrun.obj" is produced as expected. The options I use are justified
below:
| Quote: | -c compile without linking, so that I have explicit control over the
linked libraries
-tWC this will be a Windows console application...
-tWM that will be multi-threaded...
-tWR and that will use the dynamic runtime library which I assume I need
to work with a .dll
-a8 this aligns the data to "quad word"
|
Now linking is where I run into trouble. I use...
| Quote: | ilink32 /Tpe /ap c0x32.obj trialrun.obj, trial.exe, trial.map, bcmysql.lib
cw32mti.lib ws2_32.lib |
The options and various files I use are explained immediately below:
| Quote: | /Tpe targets a Windows executable
/ap builds a 32-bit Windows console application
c0x32.obj 32-bit console-mode executable startup module
trialrun.obj the result of my compiled source code
trial.exe the name of the executable that I hope to produce
trial.map the name of the .map file I include to avoid a "Fatal: Too many
MAP file names: cw32mti.lib" error
bcmysql.lib my import library for the libmySQL.dll
cw32mti.lib the import library for multi-threaded dynamic RTL use
ws2_32.lib the import library for 32-bit WinSock 2.0's API
|
The resulting linking errors are as follows:
Error: Unresolved external 'GetModuleHandleA' referenced from
C:BORLANDBCC55LIBCW32MTI.LIB|xxv
Error: Unresolved external 'GetProcAddress' referenced from
C:BORLANDBCC55LIBCW32MTI.LIB|xxv
Error: Unresolved external 'HeapAlloc' referenced from
C:BORLANDBCC55LIBC0X32.OBJ
Error: Unresolved external 'GetProcessHeap' referenced from
C:BORLANDBCC55LIBC0X32.OBJ
Error: Unresolved external 'HeapFree' referenced from
C:BORLANDBCC55LIBC0X32.OBJ
Does anyone have a clue as to what I am doing incorrectly?
Is it possible that the default MAKE file is interfering with my linking?
Can anyone tell that I am a newbie way in over my head?
Any help would be appreciated.
Regards,
Andrew Fenton
|
|
| Back to top |
|
 |
Andrew Fenton Guest
|
Posted: Tue Jan 13, 2004 10:17 pm Post subject: Re: Using MySQL with Borland C++ 5.5 Compiler |
|
|
How embarrassing! I left off my IMPORT32.LIB. It seems I had the notion
that it wasn't needed on a console application.
The linker had no complaints when I typed the following:
| Quote: | ilink32 /Tpe /ap c0x32.obj trialrun.obj, trial.exe, trial.map, bcmysql.lib
import32.lib cw32mti.lib ws2_32.lib |
Now, however, I have a run-time error that causes Windows to offer to
collect a report on my application. MySQL is probably outside of the venue
of this forum, but if anyone is interested, my code is shown below. Thanks.
Andrew Fenton
#include <my_global.h>
#include <mysql.h>
#include <stdio.h>
int main () {
//Note: The "my" header files exploited above require a C compilation.
// This means that the source code below must also comply with C
// requirements.
MYSQL testData;
MYSQL_RES *res;
MYSQL_ROW row;
char sqs [] = "select name from namelist where name like 'a%' "; //My
single SQL statement
short int c;
mysql_real_connect(&testData, NULL, NULL, NULL, NULL, MYSQL_PORT, NULL, 0);
mysql_select_db(&testData, "manifest");
mysql_query(&testData, sqs);
res = mysql_store_result(&testData);
for (c = 0; c < mysql_num_rows(res); c++) {
row = mysql_fetch_row(res);
printf("%i: %sn", c, row);
}
mysql_close(&testData);
return 0;
}
|
|
| Back to top |
|
 |
Bob Gonder Guest
|
Posted: Wed Jan 14, 2004 12:17 am Post subject: Re: Using MySQL with Borland C++ 5.5 Compiler |
|
|
Andrew Fenton wrote:
| Quote: | ilink32 /Tpe /ap c0x32.obj trialrun.obj, trial.exe, trial.map, bcmysql.lib
cw32mti.lib ws2_32.lib
trial.map the name of the .map file I include to avoid a "Fatal: Too many
MAP file names: cw32mti.lib" error
|
Not that this has any bearing on your troubles, but just FYI....
Instead of EXE COMMA MAP COMMA LIBS you can do
EXE COMMA COMMA LIBS like this.
ilink32 /Tpe /ap c0x32 trialrun, trial, , bcmysql cw32mti ws2_32
That error "Too many MAP files names" is because you left out the
(extra) comma, so it thinks your LIBS are MAPS.
|
|
| Back to top |
|
 |
Andrew Fenton Guest
|
Posted: Wed Jan 14, 2004 3:52 pm Post subject: Re: Using MySQL with Borland C++ 5.5 Compiler |
|
|
Bob,
Thanks. This does help my understanding of the use of ilink32 a bit better
and is so appreciated.
For anyone else who is interested, the MySQL code was remedied by several
things:
1) Inclusion of a mysql_init(NULL) statement,
2) addition of a mysql_free_result(res) statement (to prevent memory
leakage), and
3) a row array reference (row[0]) in my printf statement.
I have also changed the MYSQL testData structure to a pointer (*testData) in
its initialization. I am not certain if this was necessary, but some of the
example code that I have seen uses this method. If both are valid, I wonder
which would be preferable. That is, perhaps, a question better posed in the
borland.public.cpp.borlandcpp NG, though.
Thanks again,
Andrew Fenton
"Bob Gonder" <notbg (AT) notmindspring (DOT) invalid> wrote
| Quote: | ilink32 /Tpe /ap c0x32.obj trialrun.obj, trial.exe, trial.map,
bcmysql.lib
cw32mti.lib ws2_32.lib
trial.map the name of the .map file I include to avoid a "Fatal: Too
many
MAP file names: cw32mti.lib" error
Not that this has any bearing on your troubles, but just FYI....
Instead of EXE COMMA MAP COMMA LIBS you can do
EXE COMMA COMMA LIBS like this.
ilink32 /Tpe /ap c0x32 trialrun, trial, , bcmysql cw32mti ws2_32
That error "Too many MAP files names" is because you left out the
(extra) comma, so it thinks your LIBS are MAPS.
|
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|