Has anyone been able to compile the lib files using Microsoft Visual C++ 2008 Express compiler? I downloaded and installed MySQL 5.0 Server yesterday, then downloaded MySQL++ source. Attempted to compile and got a bunch of link errors. I used dumpbin.exe to get a list of all the symbols in libmysql.lib and noted that the function names did not have _ in front of them, but the symbol names the compiler's linker was trying to find did have the underline.

Is there a way to force the compiler to NOT put the underline in front of symbol names so that the linker can resolve the symbols in the libmysql.lib library?

Recommended Answers

All 7 Replies

Has anyone been able to compile the lib files using Microsoft Visual C++ 2008 Express compiler? I downloaded and installed MySQL 5.0 Server yesterday, then downloaded MySQL++ source. Attempted to compile and got a bunch of link errors. I used dumpbin.exe to get a list of all the symbols in libmysql.lib and noted that the function names did not have _ in front of them, but the symbol names the compiler's linker was trying to find did have the underline.

Is there a way to force the compiler to NOT put the underline in front of symbol names so that the linker can resolve the symbols in the libmysql.lib library?

My memory is hazy, but I successfully (after your tip) installed/used MySQL++ on Windows XP with MS Visual Studio 2008 (non-Express) and I didn't have to change any compiler options (except to specify a root directory for MySQL files) or worry about any _ problems. A few notes. One, I was successful using XP, not Vista. Two, when you download MySQL (not MySQL++), make sure you DO NOT just click the default options. Make sure you click the full install, which will get you a bunch of libraries needed by MySQL++. You'll get errors galore if you try to build MySQL++ projects without those MySQL libraries, which aren't included in the default download. Finally, you'll have to probably change your compiler options so that Visual C++ knows where to look for these MySQL files.

Here's my original thread. I ended up using MySQL++ on Windows with Visual Studio rather than Linux and it worked great.

http://www.daniweb.com/forums/thread119309.html

Yes I did all that -- I have the MySQL lib and include files in the MySQL 5.0 server folder. I just now tried a small C program totorial I found and it won't link either

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <winsock.h>
#include "mysql.h"

 MYSQL *mysql;
 MYSQL_RES *results;
 MYSQL_ROW record;
  static char *server_options[] = {"mysql_test", "--defaults-file=my.cnf"};
  int num_elements = sizeof(server_options) / sizeof(char *);

  static char *server_groups[] = {"libmysqd_server", "libmysqd_client"};


 int main()
 {
   mysql_server_init(num_elements, server_options, server_groups);
   mysql = mysql_init(NULL);

   mysql_options(mysql, MYSQL_READ_DEFAULT_GROUP, "libmysqld_client");
   mysql_options(mysql, MYSQL_OPT_USE_EMBEDDED_CONNECTION, NULL);

 }

1>main.obj : error LNK2001: unresolved external symbol _mysql_options@12
1>main.obj : error LNK2001: unresolved external symbol _mysql_init@4
1>main.obj : error LNK2001: unresolved external symbol _mysql_server_init@12
1>C:\dvlp\MySQL\Debug\MySQL.exe : fatal error LNK1120: 3 unresolved externals

I hope I'm not out of place by asking this, but does it have something to do with calling conventions?

>_>

Alex: I tried changing that but it didn's help. I posted a question on MySQL developer's forum, maybe they can tell me what's wrong. If, and when, I find out I'll post the answer here.

I used dumpbin.exe to get a list of all the symbols in libmysql.lib and noted that the function names did not have _ in front of them

Sounds strange, I dumped the libmysql.lib exports

dumpbin /exports libmysql.lib =>
...
_my_realloc
_my_strdup
_myodbc_remove_escape@8
_mysql_affected_rows@4
_mysql_autocommit@8
_mysql_change_user@16
_mysql_character_set_name@4
...

whereas, dumpbin /exports libmysql.dll =>

...
28   1B 00002C2A my_realloc
29   1C 00004502 my_strdup
30   1D 0000454D myodbc_remove_escape
31   1E 00001280 mysql_affected_rows
32   1F 000037A6 mysql_autocommit
33   20 00001C2B mysql_change_user
34   21 0000362F mysql_character_set_name
...

Maybe you accidentally dumped the .DLL?

The sample program you've tried, compiles and links (with libmysql.lib) OK with VS 2005. To me it appears as if the libmysql.lib simply wasn't specified as input to the linker.

I thought of that too, so I added pragma to force link with the library and it still won't link.

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <winsock.h>
#include "mysql.h"
#pragma comment(lib,"C:\\Program Files\\MySQL\\MySQL Server 5.0\\lib\\opt\\libmysql.lib")

I thought of that too, so I added pragma to force link with the library and it still won't link.

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <winsock.h>
#include "mysql.h"
#pragma comment(lib,"C:\\Program Files\\MySQL\\MySQL Server 5.0\\lib\\opt\\libmysql.lib")

Could it be a 32/64-bit mismatch, for example libmysql.lib actually being the 64-bit version?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.