Bug #58076 libmysql fails incremental build in some VS versions
Submitted: 9 Nov 2010 9:22 Modified: 3 Jan 2019 11:32
Reporter: Bernd Ocklin Email Updates:
Status: Won't fix Impact on me:
None 
Category:MySQL Server: Compiling Severity:S3 (Non-critical)
Version:mysql-5.X OS:Windows
Assigned to: CPU Architecture:Any
Tags: SEAGULL

[9 Nov 2010 9:22] Bernd Ocklin
Description:
In some versions of VS cmake fails to build libmysql due to bugs or insufficiencies in the VS incremental linker. 

How to repeat:
Build libmysql.

Suggested fix:
Switch incremental linking off as proposed by Microsoft's KB.

=== modified file 'libmysql/CMakeLists.txt'
--- libmysql/CMakeLists.txt	2010-06-28 12:39:45 +0000
+++ libmysql/CMakeLists.txt	2010-08-25 13:31:02 +0000
@@ -113,6 +113,8 @@
 ADD_LIBRARY(libmysql          SHARED ${CLIENT_SOURCES} dll.c libmysql.def)
 ADD_DEPENDENCIES(libmysql GenError)
 TARGET_LINK_LIBRARIES(libmysql wsock32 ws2_32)
+# workaround for http://support.microsoft.com/?scid=kb%3Ben-us%3B948127&x=7&y=15
+SET_TARGET_PROPERTIES(libmysql PROPERTIES LINK_FLAGS "/INCREMENTAL:NO")
 INSTALL_SYMLINK(${linkname} libmysql ${INSTALL_LIBDIR} COMPONENT SharedLibraries)
 MYSQL_INSTALL_TARGETS(libmysql DESTINATION ${INSTALL_LIBDIR} COMPONENT Development)
[9 Nov 2010 10:45] MySQL Verification Team
Thank you for the bug report.
[4 Mar 2011 13:20] Mattias Jonsson
I have the same problem with mysql-5.1 (not 5.5+):
LINK : fatal error LNK1104: cannot open file 'C:\...\mysql-bzr\test-5.1\mysql-test\lib\My\SafeProcess\RelWithDebInfo\my_safe_process.map'

which makes some needed binaries (comp_err, comp_sql, echo, my_print_defaults, perror, resolveip, replace etc) fails to build, which later fails generation of mysqld_error.h etc.

This patch fixes all these issues in 5.1:
=== modified file 'CMakeLists.txt'
--- CMakeLists.txt	2010-11-18 16:02:37 +0000
+++ CMakeLists.txt	2011-03-04 12:41:21 +0000
@@ -117,6 +117,8 @@
     # generate map files, set stack size (see bug#20815)
     SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /MAP /MAPINFO:EXPORTS")
     SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /STACK:1048576")
+    # Don't do incremental linking, since that can fail with .map files.
+    SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /INCREMENTAL:NO")
 
     # remove support for Exception handling
     STRING(REPLACE "/GX"   "" CMAKE_CXX_FLAGS            ${CMAKE_CXX_FLAGS})
[4 Mar 2011 13:26] Mattias Jonsson
I had problems with the first compile on both Win XP 32 bit with VS 2010 Express and Win 7 with VS 2010 Pro (both with and without SP1 beta).

if just running the compilation again a couple of times it will complete before. But the above diff will make it complete the first time.