Bug #93906 MySQL 5.7 fails to compile with Visual Studio 2015
Submitted: 14 Jan 2019 2:11 Modified: 26 Jun 2019 10:36
Reporter: wu winnie Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: Compiling Severity:S3 (Non-critical)
Version:5.7.24 OS:Windows
Assigned to: CPU Architecture:Any

[14 Jan 2019 2:11] wu winnie
Description:
Building under Visual Studio 2015 fails with  the error message:

"D:\work_code\Intersect\mysql\mysql-5.7.24\x64\sql\mysqld.vcxproj" (default target) (1) ->
(Link target) ->
  sql.lib(item_geofunc.obj) : error LNK2019: unresolved external symbol "public: void __cdecl Field::copy_data(__int64)
" (?copy_data@Field@@QEAAX_J@Z) referenced in function "public: virtual void __cdecl Field::set_default(void)" (?set_de
fault@Field@@UEAAXXZ) [D:\work_code\Intersect\mysql\mysql-5.7.24\x64\sql\mysqld.vcxproj]
  D:\work_code\Intersect\mysql\mysql-5.7.24\x64\sql\Debug\mysqld.exe : fatal error LNK1120: 1 unresolved externals [D:\
work_code\Intersect\mysql\mysql-5.7.24\x64\sql\mysqld.vcxproj]

How to repeat:
1. Install Visual Studio 2015 with applicable C++ components
2. Install CMake 3.12.2
3. Configure, e.g.: cmake -Bx64 -G "Visual Studio 14 2015 Win64" -H. -DWITH_INNOBASE_STORAGE_ENGINE=yes -DWITH_PARTITION_STORAGE_ENGINE=yes -DWITH_PERFSCHEMA_STORAGE_ENGINE=yes -DWITHOUT_FEDERATED_STORAGE_ENGINE=1 -DINNODB_PAGE_ATOMIC_REF_COUNT=no -DWITH_BOOST=C:/dev/boost_1_59_0 -DTMPDIR=\\ -Wno-dev

4. Build: msbuild /nologo x64\sql\mysqld.vcxproj /p:Configuration=Debug
note:msbuild.exe is located at: C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe
[14 Jan 2019 10:26] wu winnie
it looks like I know what makes the error happens.

before I configured x64 compile environment, I've configured x86 environment by:
cmake -B. -G "Visual Studio 14 2015" -H. -DWITH_INNOBASE_STORAGE_ENGINE=yes -DWITH_PARTITION_STORAGE_ENGINE=yes -DWITH_PERFSCHEMA_STORAGE_ENGINE=yes -DWITHOUT_FEDERATED_STORAGE_ENGINE=1 -DINNODB_PAGE_ATOMIC_REF_COUNT=no -DWITH_BOOST=C:/dev/boost_1_59_0 -DTMPDIR=\\ -Wno-dev

I haven't created a new directory for storing the x86 configuration files, so \mysql-5.7.24\include\my_config.h would be created(it was x86 configuration file). 

when I tried to compile x64 source code, in file \mysql-5.7.24\include\my_global.h(line 28), it has:

#include "my_config.h"

note: it used double quote to include my_config.h file, which means it would tried to find my_config.h in the same folder as my_global.h, unfortuanately, at this time, my_config.h for x86 exists, which would be used for compile for x64, then error happens.

suggestion: use  #include <my_config.h> instead of #include "my_config.h", 
which would make it always find the correct head file.
[15 Jan 2019 2:20] wu winnie
so the steps to reproduce this issue should be:

cd D:\work_code\Intersect\mysql\mysql-5.7.24

cmake -B. -G "Visual Studio 14 2015" -H. -DWITH_INNOBASE_STORAGE_ENGINE=yes -DWITH_PARTITION_STORAGE_ENGINE=yes -DWITH_PERFSCHEMA_STORAGE_ENGINE=yes -DWITHOUT_FEDERATED_STORAGE_ENGINE=1 -DINNODB_PAGE_ATOMIC_REF_COUNT=no -DWITH_BOOST=C:/dev/boost_1_59_0 -DTMPDIR=\\ -Wno-dev

cmake -Bx64 -G "Visual Studio 14 2015 Win64" -H. -DWITH_INNOBASE_STORAGE_ENGINE=yes -DWITH_PARTITION_STORAGE_ENGINE=yes -DWITH_PERFSCHEMA_STORAGE_ENGINE=yes -DWITHOUT_FEDERATED_STORAGE_ENGINE=1 -DINNODB_PAGE_ATOMIC_REF_COUNT=no -DWITH_BOOST=C:/dev/boost_1_59_0 -DTMPDIR=\\ -Wno-dev

msbuild /nologo x64\sql\mysqld.vcxproj /p:Configuration=Debug
[15 Jan 2019 8:21] MySQL Verification Team
Thank you for the bug report.
[23 Jan 2019 11:14] Tor Didriksen
Posted by developer:
 
So this is effectively one in-source, and one out-of-source build against the same source tree.
In-source builds are not recommended (in 8.0 sources I have added a MESSAGE(FATAL_ERROR) for this case)
I suggest using separate build directories for both builds.
And btw, I recommend building with cmake, rather than 'msbuild':
cmake --build . --config debug