#19340: Build fails for Visual Studio 16 2019 generator with CMake

499 views
Skip to first unread message

wxTrac

unread,
Dec 3, 2021, 4:50:49 PM12/3/21
to wx-...@googlegroups.com
#19340: Build fails for Visual Studio 16 2019 generator with CMake
-------------------------+-------------------------
Reporter: jdoubleu | Owner:
Type: build error | Status: new
Priority: normal | Milestone:
Component: build | Version: dev-latest
Keywords: | Blocked By:
Blocking: | Patch: 0
-------------------------+-------------------------
The build fails if I'm using Visual Studio 16 2019 generator with CMake on
the latest master branch.

Commands:
{{{
cmake -B build -G "Visual Studio 16 2019"
cmake --build .\build\ --parallel
}}}

There is something going on with libc feature detection, because I get the
following error message:
{{{
C:\wxwidgets\src\common\time.cpp(49,14): fatal error C1083: Cannot open
include file: 'sys/time.h
': No such file or directory [C:\wxwidgets\build\libs\base\wxbase.vcxproj]
{{{

Contents of time.cpp@49
(https://github.com/wxWidgets/wxWidgets/blob/master/src/common/time.cpp#L49):
{{{
#if defined(HAVE_GETTIMEOFDAY)
#include <sys/time.h>
#include <unistd.h>
#elif defined(HAVE_FTIME)
#include <sys/timeb.h>
#endif
}}}

When using the default generator, which seems to be NMake Files on
Windows, this error doesn't occur.

--
Ticket URL: <https://trac.wxwidgets.org/ticket/19340>

wxTrac

unread,
Dec 3, 2021, 5:56:12 PM12/3/21
to wx-...@googlegroups.com
#19340: Build fails for Visual Studio 16 2019 generator with CMake
--------------------------+----------------------------
Reporter: jdoubleu | Owner:
Type: build error | Status: infoneeded_new
Priority: normal | Milestone:
Component: build | Version: dev-latest
Resolution: | Keywords:
Blocked By: | Blocking:
Patch: 0 |
--------------------------+----------------------------
Changes (by MaartenB):

* status: new => infoneeded_new


Comment:

Strange, because win32 does not have a `gettimeofday` function so
`HAVE_GETTIMEOFDAY` should never get defined. What is your CMake output?
It should be like:

{{{
-- Looking for gettimeofday
-- Looking for gettimeofday - not found
}}}

--
Ticket URL: <https://trac.wxwidgets.org/ticket/19340#comment:1>

wxTrac

unread,
Dec 4, 2021, 5:28:22 AM12/4/21
to wx-...@googlegroups.com
#19340: Build fails for Visual Studio 16 2019 generator with CMake
--------------------------+------------------------
Reporter: jdoubleu | Owner:
Type: build error | Status: new
Priority: normal | Milestone:
Component: build | Version: dev-latest
Resolution: | Keywords:
Blocked By: | Blocking:
Patch: 0 |
--------------------------+------------------------
Changes (by jdoubleu):

* cc: hi@… (added)
* status: infoneeded_new => new


Comment:

It actually finds gettimeofday.

Here is the full output of the CMake configure phase:
{{{
C:\wxWidgets> cmake -B build -G "Visual Studio 16 2019"
-- Selecting Windows SDK version 10.0.19041.0 to target Windows
10.0.19043.
-- The C compiler identification is MSVC 19.29.30136.0
-- The CXX compiler identification is MSVC 19.29.30136.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual
Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe -
skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual
Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe -
skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- cotire 1.8.0 loaded.
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Check size of wchar_t
-- Check size of wchar_t - done
-- Looking for pthread.h
-- Looking for pthread.h - not found
-- Found Threads: TRUE
-- Performing Test HAVE_WINHTTP_H
-- Performing Test HAVE_WINHTTP_H - Success
-- Looking for d2d1.h
-- Looking for d2d1.h - found
-- Found OpenGL: opengl32
-- C CXX RC target wxbase cotired without unity build.
-- CXX RC target wxnet cotired without unity build.
-- CXX RC target wxcore cotired without unity build.
-- CXX RC target wxadv cotired without unity build and precompiled header.
Too few applicable sources.
-- CXX RC target wxaui cotired without unity build.
-- CXX RC target wxhtml cotired without unity build.
-- CXX RC target wxpropgrid cotired without unity build.
-- CXX RC target wxribbon cotired without unity build.
-- CXX RC target wxrichtext cotired without unity build.
-- CXX RC target wxwebview cotired without unity build.
-- CXX target wxscintilla cotired without unity build.
-- CXX RC target wxstc cotired without unity build.
-- CXX RC target wxxrc cotired without unity build.
-- CXX RC target wxmedia cotired without unity build.
-- CXX RC target wxgl cotired without unity build.
-- CXX RC target wxqa cotired without unity build.
-- CXX RC target wxxml cotired without unity build.
-- Looking for 4 include files stdlib.h, ..., float.h
-- Looking for 4 include files stdlib.h, ..., float.h - found
-- Performing Test HAVE_STD_STRING_COMPARE
-- Performing Test HAVE_STD_STRING_COMPARE - Success
-- Performing Test HAVE_STD_WSTRING
-- Performing Test HAVE_STD_WSTRING - Success
-- Performing Test HAVE_HASH_MAP
-- Performing Test HAVE_HASH_MAP - Failed
-- Performing Test HAVE_EXT_HASH_MAP
-- Performing Test HAVE_EXT_HASH_MAP - Failed
-- Performing Test HAVE_STD_UNORDERED_MAP
-- Performing Test HAVE_STD_UNORDERED_MAP - Success
-- Performing Test HAVE_TR1_UNORDERED_MAP
-- Performing Test HAVE_TR1_UNORDERED_MAP - Failed
-- Performing Test HAVE_GCC_ATOMIC_BUILTINS
-- Performing Test HAVE_GCC_ATOMIC_BUILTINS - Failed
-- Looking for localtime_r
-- Looking for localtime_r - not found
-- Looking for gmtime_r
-- Looking for gmtime_r - not found
-- Performing Test wxSIZE_T_IS_NOT_UINT
-- Performing Test wxSIZE_T_IS_NOT_UINT - Success
-- Performing Test wxSIZE_T_IS_NOT_ULONG
-- Performing Test wxSIZE_T_IS_NOT_ULONG - Success
-- Performing Test wxWCHAR_T_IS_REAL_TYPE
-- Performing Test wxWCHAR_T_IS_REAL_TYPE - Success
-- Performing Test HAVE_PW_GECOS
-- Performing Test HAVE_PW_GECOS - Failed
-- Looking for ftime
-- Looking for ftime - not found
-- Looking for wcsftime
-- Looking for wcsftime - found
-- Looking for wprintf
-- Looking for wprintf - found
-- Looking for putws
-- Looking for putws - not found
-- Looking for fputws
-- Looking for fputws - found
-- Looking for vswprintf
-- Looking for vswprintf - found
-- Looking for vswscanf
-- Looking for vswscanf - found
-- Looking for wcsdup
-- Looking for wcsdup - found
-- Looking for wcsnlen
-- Looking for wcsnlen - found
-- Looking for wcscasecmp
-- Looking for wcscasecmp - not found
-- Looking for wcsncasecmp
-- Looking for wcsncasecmp - not found
-- Looking for wcsrctombs
-- Looking for wcsrctombs - not found
-- Looking for wcstoull
-- Looking for wcstoull - found
-- Looking for wcslen
-- Looking for wcslen - found
-- Looking for fsync
-- Looking for fsync - not found
-- Looking for snprintf
-- Looking for snprintf - not found
-- Looking for vsnprintf
-- Looking for vsnprintf - not found
-- Looking for strnlen
-- Looking for strnlen - found
-- Looking for strtoull
-- Looking for strtoull - found
-- Looking for setpriority
-- Looking for setpriority - not found
-- Looking for gettimeofday
-- Looking for gettimeofday - found
-- Looking for vsscanf
-- Looking for vsscanf - found
-- Looking for round
-- Looking for round - found
-- Looking for C++ include tr1/type_traits
-- Looking for C++ include tr1/type_traits - not found
-- Looking for C++ include type_traits
-- Looking for C++ include type_traits - found
-- Looking for fcntl.h
-- Looking for fcntl.h - found
-- Looking for langinfo.h
-- Looking for langinfo.h - not found
-- Looking for sched.h
-- Looking for sched.h - not found
-- Looking for unistd.h
-- Looking for unistd.h - not found
-- Looking for wchar.h
-- Looking for wchar.h - found
-- Looking for wcstr.h
-- Looking for wcstr.h - not found
-- Performing Test wxTEST_TZ_timezone
-- Performing Test wxTEST_TZ_timezone - Failed
-- Performing Test wxTEST_TZ__timezone
-- Performing Test wxTEST_TZ__timezone - Success
-- Performing Test WX_GMTOFF_IN_TM
-- Performing Test WX_GMTOFF_IN_TM - Failed
-- Looking for dlopen
-- Looking for dlopen - not found
-- Looking for sys/epoll.h
-- Looking for sys/epoll.h - not found
-- Looking for sys/select.h
-- Looking for sys/select.h - not found
-- Looking for sys/inotify.h
-- Looking for sys/inotify.h - not found
-- Looking for sys/event.h
-- Looking for sys/event.h - not found
-- Looking for xlocale.h
-- Looking for xlocale.h - not found
-- Check size of locale_t
-- Check size of locale_t - failed
-- Check size of size_t
-- Check size of size_t - done
-- Check size of int
-- Check size of int - done
-- Check size of long
-- Check size of long - done
-- Check size of short
-- Check size of short - done
-- Check size of long long
-- Check size of long long - done
-- Check size of ssize_t
-- Check size of ssize_t - failed
-- Which libraries should wxWidgets use?
wxUSE_STL: OFF (use C++ STL classes)
wxUSE_REGEX: builtin (enable support for wxRegEx class)
wxUSE_ZLIB: builtin (use zlib for LZW compression)
wxUSE_EXPAT: builtin (use expat for XML parsing)
wxUSE_LIBJPEG: builtin (use libjpeg (JPEG file format))
wxUSE_LIBPNG: builtin (use libpng (PNG image format))
wxUSE_LIBTIFF: builtin (use libtiff (TIFF file format))
wxUSE_LIBLZMA: OFF (use liblzma for LZMA compression)

-- Configured wxWidgets 3.1.6 for Windows-10.0.19043
Min OS Version required at runtime: Windows Vista /
Windows Server 2008 (x64 Edition)
Which GUI toolkit should wxWidgets use? msw
Should wxWidgets be compiled into single library? OFF
Should wxWidgets be linked as a shared library? ON
Should wxWidgets support Unicode? ON
What wxWidgets compatibility level should be used? 3.0
-- Configuring done
-- Generating done
-- Build files have been written to: C:/wxWidgets/build
}}}

--
Ticket URL: <https://trac.wxwidgets.org/ticket/19340#comment:2>

wxTrac

unread,
Dec 4, 2021, 5:56:09 AM12/4/21
to wx-...@googlegroups.com
#19340: Build fails for Visual Studio 16 2019 generator with CMake
--------------------------+------------------------
Reporter: jdoubleu | Owner:
Type: build error | Status: new
Priority: normal | Milestone:
Component: build | Version: dev-latest
Resolution: | Keywords:
Blocked By: | Blocking:
Patch: 0 |
--------------------------+------------------------
Changes (by jdoubleu):

* cc: hi@… (removed)


Comment:

CMake is using the `CheckFunctionExists.c` template (see
https://gitlab.kitware.com/cmake/cmake/-/blob/master/Modules/CheckFunctionExists.c)
to check for existing function. You need to define
`CHECK_FUNCTION_EXISTS=gettimeofday` when you compile this C code.

With
{{{
cmake -B build -G "Visual Studio 16 2019" --debug-trycompile
}}}
you can keep the actual `.sln` CMake uses to build that file.


----

I noticed, while compiling this test with Visual Studio in a custom
solution, that it only works for C code. If I compile it as C++ it
complains about a missing `_gettimeofday` symbol.

Throwing the compiled C obj into Ghidra, I confirmed my suspicion: MSVC is
injecting a `gettimeofday` function which internally calls the WIN32 API:
{{{#!c
int gettimeofday(timeval *param_1,void *param_2)

{
longlong lVar1;
undefined4 *puVar2;
undefined auStack72 [32];
undefined4 local_28 [2];
_FILETIME local_20 [3];

lVar1 = 8;
puVar2 = local_28;
while (lVar1 != 0) {
lVar1 = lVar1 + -1;
*puVar2 = 0xcccccccc;
puVar2 = puVar2 + 1;
}
GetSystemTimeAsFileTime((LPFILETIME)local_20);
param_1->tv_usec = (long)(((longlong)local_20[0] / 10) % 1000000);
param_1->tv_sec = (long)(((longlong)local_20[0] + -0x19db1ded53e8000) /
10000000);
_RTC_CheckStackVars(auStack72,(_RTC_framedesc *)&DAT_140019c00);
return 0;
}
}}}

--
Ticket URL: <https://trac.wxwidgets.org/ticket/19340#comment:3>

wxTrac

unread,
Dec 4, 2021, 6:31:39 AM12/4/21
to wx-...@googlegroups.com
#19340: Build fails for Visual Studio 16 2019 generator with CMake
--------------------------+------------------------
Reporter: jdoubleu | Owner:
Type: build error | Status: new
Priority: normal | Milestone:
Component: build | Version: dev-latest
Resolution: | Keywords:
Blocked By: | Blocking:
Patch: 0 |
--------------------------+------------------------

Comment (by MaartenB):

The weird thing is, this doesn't happen to me. I'm using VS2022 now, but
until last week I never had problems with VS2019.

If I use the temp solution that CMake creates, it result in:
{{{
1>cl /c /Zi /W1 /WX- /diagnostics:column /MP1 /Od /Ob0 /D _MBCS /D WIN32
/D _WINDOWS /D CHECK_FUNCTION_EXISTS=gettimeofday /D __WINDOWS__ /D
__WIN32__ /D "CMAKE_INTDIR=\"Debug\"" /Gm- /RTC1 /MDd /GS /fp:precise
/Zc:wchar_t /Zc:forScope /Zc:inline /Fo"cmTC_33f60.dir\Debug\\"
/Fd"cmTC_33f60.dir\Debug\vc143.pdb" /external:W1 /Gd /TC
/errorReport:prompt "C:\Program
Files\CMake\share\cmake-3.22\Modules\CheckFunctionExists.c"
1>CheckFunctionExists.c
1>CheckFunctionExists.obj : error LNK2019: unresolved external symbol
gettimeofday referenced in function main
}}}

Maybe we can use `check_symbol_exists` instead of `check_function_exists`?
For example, removing `gettimeofday` from `setup.cmake:571`, and adding
this instead?

{{{#!cmake
check_symbol_exists(gettimeofday sys/time.h HAVE_GETTIMEOFDAY)
}}}

Another solution could be adding `check_include_file(sys/time.h HAVE_...)`
and unsetting `HAVE_GETTIMEOFDAY` if this fails.

--
Ticket URL: <https://trac.wxwidgets.org/ticket/19340#comment:4>

wxTrac

unread,
Dec 4, 2021, 10:49:15 AM12/4/21
to wx-...@googlegroups.com
#19340: Build fails for Visual Studio 16 2019 generator with CMake
--------------------------+------------------------
Reporter: jdoubleu | Owner:
Type: build error | Status: new
Priority: normal | Milestone:
Component: build | Version: dev-latest
Resolution: | Keywords:
Blocked By: | Blocking:
Patch: 0 |
--------------------------+------------------------
Changes (by pb101):

* cc: pbfordev@… (added)


Comment:

FWIW, I have been building wxWidgets master with CMake-generated MSVS 2019
solution frequently for quite some time and have never encountered this
issue. I have tried just now with CMake 3.22 and current wxWidgets master,
still works as expected just as it worked a couple days ago when I did
this.

{{{
Selecting Windows SDK version 10.0.22000.0 to target Windows 10.0.19043.
The C compiler identification is MSVC 19.29.30137.0
The CXX compiler identification is MSVC 19.29.30137.0
Detecting C compiler ABI info
Detecting C compiler ABI info - done
Check for working C compiler: C:/Program Files (x86)/Microsoft Visual
Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe -
skipped
Detecting C compile features
Detecting C compile features - done
Detecting CXX compiler ABI info
Detecting CXX compiler ABI info - done
Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual
Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe -
skipped
....
Looking for gettimeofday
Looking for gettimeofday - not found
....
Which libraries should wxWidgets use?
wxUSE_STL: OFF (use C++ STL classes)
wxUSE_REGEX: builtin (enable support for wxRegEx class)
wxUSE_ZLIB: builtin (use zlib for LZW compression)
wxUSE_EXPAT: builtin (use expat for XML parsing)
wxUSE_LIBJPEG: builtin (use libjpeg (JPEG file format))
wxUSE_LIBPNG: builtin (use libpng (PNG image format))
wxUSE_LIBTIFF: builtin (use libtiff (TIFF file format))
wxUSE_LIBLZMA: OFF (use liblzma for LZMA compression)

Configured wxWidgets 3.1.6 for Windows-10.0.19043
Min OS Version required at runtime: Windows Vista /
Windows Server 2008 (x64 Edition)
Which GUI toolkit should wxWidgets use? msw
Should wxWidgets be compiled into single library? OFF
Should wxWidgets be linked as a shared library? ON
Should wxWidgets support Unicode? ON
What wxWidgets compatibility level should be used? 3.0
Configuring done
}}}

I have slightly newer versions of MSVC (MSVS 2019 Community v16.11.7) and
Windows SDK but that should make no difference. Out of curiosity, what is
the difference between OP's and mine setups which makes OP's fail? I use
CMakeGUI to generate the solution and MSVS to build it but that should not
matter?

--
Ticket URL: <https://trac.wxwidgets.org/ticket/19340#comment:5>

wxTrac

unread,
Dec 4, 2021, 11:22:58 AM12/4/21
to wx-...@googlegroups.com
#19340: Build fails for Visual Studio 16 2019 generator with CMake
--------------------------+------------------------
Reporter: jdoubleu | Owner:
Type: build error | Status: closed
Priority: normal | Milestone:
Component: build | Version: dev-latest
Resolution: invalid | Keywords:
Blocked By: | Blocking:
Patch: 0 |
--------------------------+------------------------
Changes (by jdoubleu):

* cc: hi@… (added)
* status: new => closed
* resolution: => invalid


Comment:

It's an issue with my build environment. Apparently, MSVC automatically
included the static version of `libcheck`, which probably had a fallback
`gettimeofday`:
{{{
Searching C:\vcpkg\installed\\x64-windows\lib\check.lib:
1> Found gettimeofday
1> Referenced in Source.obj
1> Loaded check.lib(gettimeofday.c.obj)
}}}

I can confirm, that on a clean Windows without any dependencies installed,
it fails as well.

What I don't understand is why MSVC automatically links that library
although I didn't manually instruct it to do.


Thanks for you help!

--
Ticket URL: <https://trac.wxwidgets.org/ticket/19340#comment:6>
Reply all
Reply to author
Forward
0 new messages