Bug #45326 Linker failure for libmysqld with VC++ 2008
Submitted: 4 Jun 2009 10:13 Modified: 12 Aug 2009 15:55
Reporter: Magnus Blåudd Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Compiling Severity:S1 (Critical)
Version:mysql-5.1.34 OS:Windows
Assigned to: Magnus Blåudd CPU Architecture:Any

[4 Jun 2009 10:13] Magnus Blåudd
Description:
Build started: Project: libmysqld, Configuration: RelWithDebInfo|Win32
Linking...
201>C:\cygwin\home\club\magnus\mysql-5.1.34-ndb-7.0.7-pb114\libmysqld\libmysqld.def(2) : warning LNK4017: DESCRIPTION statement not supported for the target platform; ignored
libmysqld.def : warning LNK4022: cannot find unique match for symbol 'mysql_stmt_close'
libmysqld.def : warning LNK4002: "void __cdecl mysql_stmt_close(class THD *,char *)" (?mysql_stmt_close@@YAXPAVTHD@@PAD@Z) defined in RelWithDebInfo\mysqlserver.lib
libmysqld.def : warning LNK4002: _mysql_stmt_close@4 defined in RelWithDebInfo\mysqlserver.lib
libmysqld.def : warning LNK4002: _mysql_stmt_close@4 defined in
c:\cygwin\home\club\magnus\mysql-5.1.34-ndb-7.0.7-pb114\libmysqld\RelWithDebInfo\mysqlserver.lib
libmysqld.def : warning LNK4022: cannot find unique match for symbol 'mysql_stmt_execute'
libmysqld.def : warning LNK4002: "void __cdecl mysql_stmt_execute(class THD *,char *,unsigned int)" (?mysql_stmt_execute@@YAXPAVTHD@@PADI@Z) defined in RelWithDebInfo\mysqlserver.lib
libmysqld.def : warning LNK4002: _mysql_stmt_execute@4 defined in RelWithDebInfo\mysqlserver.lib
libmysqld.def : warning LNK4002: _mysql_stmt_execute@4 defined in c:\cygwin\home\club\magnus\mysql-5.1.34-ndb-7.0.7-pb114\libmysqld\RelWithDebInfo\mysqlserver.lib
libmysqld.def : warning LNK4022: cannot find unique match for symbol 'mysql_stmt_fetch'
libmysqld.def : warning LNK4002: "void __cdecl mysql_stmt_fetch(class THD *,char *,unsigned int)" (?mysql_stmt_fetch@@YAXPAVTHD@@PADI@Z) defined in RelWithDebInfo\mysqlserver.lib
libmysqld.def : warning LNK4002: _mysql_stmt_fetch@4 defined in RelWithDebInfo\mysqlserver.lib
libmysqld.def : warning LNK4002: _mysql_stmt_fetch@4 defined in c:\cygwin\home\club\magnus\mysql-5.1.34-ndb-7.0.7-pb114\libmysqld\RelWithDebInfo\mysqlserver.lib
libmysqld.def : warning LNK4022: cannot find unique match for symbol 'mysql_stmt_prepare'
libmysqld.def : warning LNK4002: "void __cdecl mysql_stmt_prepare(class THD *,char const *,unsigned int)" (?mysql_stmt_prepare@@YAXPAVTHD@@PBDI@Z) defined in RelWithDebInfo\mysqlserver.lib
libmysqld.def : warning LNK4002: _mysql_stmt_prepare@12 defined in RelWithDebInfo\mysqlserver.lib
libmysqld.def : warning LNK4002: _mysql_stmt_prepare@12 defined in c:\cygwin\home\club\magnus\mysql-5.1.34-ndb-7.0.7-pb114\libmysqld\RelWithDebInfo\mysqlserver.lib
libmysqld.def : warning LNK4022: cannot find unique match for symbol 'mysql_stmt_reset'
libmysqld.def : warning LNK4002: "void __cdecl mysql_stmt_reset(class THD *,char *)" (?mysql_stmt_reset@@YAXPAVTHD@@PAD@Z) defined in RelWithDebInfo\mysqlserver.lib
libmysqld.def : warning LNK4002: _mysql_stmt_reset@4 defined in RelWithDebInfo\mysqlserver.lib
libmysqld.def : warning LNK4002: _mysql_stmt_reset@4 defined in c:\cygwin\home\club\magnus\mysql-5.1.34-ndb-7.0.7-pb114\libmysqld\RelWithDebInfo\mysqlserver.lib
libmysqld.def : error LNK2001: unresolved external symbol mysql_stmt_close
libmysqld.def : error LNK2001: unresolved external symbol mysql_stmt_execute
libmysqld.def : error LNK2001: unresolved external symbol mysql_stmt_fetch
libmysqld.def : error LNK2001: unresolved external symbol mysql_stmt_prepare
libmysqld.def : error LNK2001: unresolved external symbol mysql_stmt_reset
C:\cygwin\home\club\magnus\mysql-5.1.34-ndb-7.0.7-pb114\libmysqld\RelWithDebInfo\libmysqld.lib : fatal error LNK1120: 5 unresolved externals
Build log was saved at "file://c:\cygwin\home\club\magnus\mysql-5.1.34-ndb-7.0.7-pb114\libmysqld\libmysqld.dir\RelWithDebInfo\BuildLog.htm"
libmysqld - 6 error(s), 21 warning(s)
Build started: Project: mysql_client_test_embedded, Configuration: RelWithDebInfo|Win32
Linking...
LINK : fatal error LNK1104: cannot open file '..\RelWithDebInfo\libmysqld.lib'
Build log was saved at "file://c:\cygwin\home\club\magnus\mysql-5.1.34-ndb-7.0.7-pb114\libmysqld\examples\mysql_client_test_embedded.dir\RelWithDebInfo\BuildLog.htm"
mysql_client_test_embedded - 1 error(s), 0 warning(s) 

How to repeat:
Building MySQL Cluster 7.0 with VC++ Express 2008 on Vista and WITH_EMBEDDED_SERVER, I get the above linker problem because there is two mysql_stmt_close functions int the libmysqld lib. When processing libmysqld.def, it can't distinguish them apart and thus no such symbol is exported.

The first function is 'extern "C" my_bool mysql_stmt_close(MYSQL* mysql)" from libmysql.c, and I that's one which should be exported.

The second function is 'void mysql_stmt_close(THD* thd, char* packet)' from sql_prepare.cc( a part of mysqld).

Suggested fix:
Rename the functions that are part of mysqld to mysqld_xxx

Ie.
-void mysql_stmt_close(THD* thd, char* packet)
+void mysqld_stmt_close(THD* thd, char* packet)
[4 Jun 2009 10:37] Magnus Blåudd
No, I changed my mind after seeing it being a big patch for MySQL Server, will change libmysqld.def to use the mangled name 

For example:
  mysql_stmt_prepare@4
[4 Jun 2009 10:44] Magnus Blåudd
No good! What did I do wrong now?

99>Build started: Project: libmysqld, Configuration: RelWithDebInfo|Win32
99>Linking...
99>C:\cygwin\home\club\magnus\mysql-5.1.36-pb72\libmysqld\libmysqld.def(2) : warning LNK4017: DESCRIPTION statement not supported for the target platform; ignored
99>   Creating library C:\cygwin\home\club\magnus\mysql-5.1.36-pb72\libmysqld\RelWithDebInfo\libmysqld.lib and object C:\cygwin\home\club\magnus\mysql-5.1.36-pb72\libmysqld\RelWithDebInfo\libmysqld.exp
99>libmysqld.exp : error LNK2001: unresolved external symbol mysql_stmt_close@4
99>libmysqld.exp : error LNK2001: unresolved external symbol mysql_stmt_execute@4
99>libmysqld.exp : error LNK2001: unresolved external symbol mysql_stmt_fetch@4
99>libmysqld.exp : error LNK2001: unresolved external symbol mysql_stmt_prepare@4
99>libmysqld.exp : error LNK2001: unresolved external symbol mysql_stmt_reset@4
99>C:\cygwin\home\club\magnus\mysql-5.1.36-pb72\libmysqld\RelWithDebInfo\libmysqld.dll : fatal error LNK1120: 5 unresolved externals
99>Build log was saved at "file://c:\cygwin\home\club\magnus\mysql-5.1.36-pb72\libmysqld\libmysqld.dir\RelWithDebInfo\BuildLog.htm"
99>libmysqld - 6 error(s), 1 warning(s)
[4 Jun 2009 10:54] Magnus Blåudd
Trying __declspec(dllexport)
[4 Jun 2009 10:54] Vladislav Vaintroub
Magnus, I believe .def does not understand the mangled (in this case stdcall) names.
besides, stdcall mangling (<function_name>@<sizeof_of_params>) does not exist in x64, so this patch is not universal:)
[4 Jun 2009 11:21] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/75603
[5 Jun 2009 11:17] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/75686
[5 Jun 2009 11:25] Bugs System
Pushed into 5.1.34-ndb-7.0.7 (revid:magnus.blaudd@sun.com-20090605112404-r89gl0ulm3n0mz1e) (version source revid:magnus.blaudd@sun.com-20090605112404-r89gl0ulm3n0mz1e) (merge vers: 5.1.34-ndb-7.0.7) (pib:6)
[5 Jun 2009 11:28] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/75691
[5 Jun 2009 11:28] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/75692
[5 Jun 2009 11:29] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/75695
[16 Jun 2009 11:04] Bugs System
Pushed into 5.1.36 (revid:joro@sun.com-20090616102155-3zhezogudt4uxdyn) (version source revid:azundris@mysql.com-20090606160500-zm37psz7u1m96y5l) (merge vers: 5.1.36) (pib:6)
[17 Jun 2009 19:27] Bugs System
Pushed into 5.4.4-alpha (revid:alik@sun.com-20090616183122-chjzbaa30qopdra9) (version source revid:azundris@mysql.com-20090606160423-aym8s5rn51nmg387) (merge vers: 6.0.12-alpha) (pib:11)
[12 Aug 2009 15:55] Paul DuBois
Noted in 5.1.36, 5.4.4 changelogs.

Linker failures with libmysqld on VC++ 2008 were fixed.
[26 Aug 2009 13:46] Bugs System
Pushed into 5.1.37-ndb-7.0.8 (revid:jonas@mysql.com-20090826132541-yablppc59e3yb54l) (version source revid:jonas@mysql.com-20090826132541-yablppc59e3yb54l) (merge vers: 5.1.37-ndb-7.0.8) (pib:11)
[26 Aug 2009 13:46] Bugs System
Pushed into 5.1.37-ndb-6.3.27 (revid:jonas@mysql.com-20090826105955-bkj027t47gfbamnc) (version source revid:jonas@mysql.com-20090826105955-bkj027t47gfbamnc) (merge vers: 5.1.37-ndb-6.3.27) (pib:11)
[26 Aug 2009 13:48] Bugs System
Pushed into 5.1.37-ndb-6.2.19 (revid:jonas@mysql.com-20090825194404-37rtosk049t9koc4) (version source revid:jonas@mysql.com-20090825194404-37rtosk049t9koc4) (merge vers: 5.1.37-ndb-6.2.19) (pib:11)
[27 Aug 2009 16:33] Bugs System
Pushed into 5.1.35-ndb-7.1.0 (revid:magnus.blaudd@sun.com-20090827163030-6o3kk6r2oua159hr) (version source revid:jonas@mysql.com-20090826132541-yablppc59e3yb54l) (merge vers: 5.1.37-ndb-7.0.8) (pib:11)
[7 Oct 2009 18:35] Paul DuBois
The 5.4 fix has been pushed to 5.4.2.