mesonbuild / sdl2

Meson build files for SDL2
MIT License
4 stars 6 forks source link

sdl2 wrap doesn't link on windows #17

Closed miffe closed 4 years ago

miffe commented 4 years ago

Versions

Windows 10 (20H2) (19042.572) (Clean install in a VM) Visual Studio 16.7.7 (With .NET desktop development & Desktop development with C++) Meson+Ninja combo installer 0.56.0

meson.build

project('example', 'c')
sdl2_dep = dependency('sdl2')
executable('example', 'example.c', dependencies: [sdl2_dep])

example.c

#include <SDL.h>
int main(int argc, char ** argv) {
    SDL_Init(0);
    return 0;
}

From 'x86 Native Tools Command Prompt for VS 2019'

cd somewhere
md subprojects
meson wrap install sdl2
meson builddir
ninja -C builddir

meson builddir

The Meson build system
Version: 0.56.0
Source dir: C:\Users\miffe\Desktop\mesontest
Build dir: C:\Users\miffe\Desktop\mesontest\builddir
Build type: native build
Project name: example
Project version: undefined
C compiler for the host machine: cl (msvc 19.27.29112 "Microsoft (R) C/C++ Optimizing Compiler Version 19.27.29112 for x86")
C linker for the host machine: link link 14.27.29112.0
Host machine cpu family: x86
Host machine cpu: x86
Did not find pkg-config by name 'pkg-config'
Found Pkg-config: NO
sdl2-config found: NO
Run-time dependency sdl2 found: NO (tried pkgconfig and config-tool)
Looking for a fallback subproject for the dependency sdl2
Downloading sdl2 source from https://www.libsdl.org/release/SDL2-2.0.12.tar.gz
Download size: 5720162
Downloading: ..........
Downloading sdl2 patch from https://wrapdb.mesonbuild.com/v1/projects/sdl2/2.0.12/1/get_zip
Download size: 23570
Downloading: ..........

|Executing subproject sdl2 method meson
|
|Project name: sdl2
|Project version: 2.0.12
|C compiler for the host machine: cl (msvc 19.27.29112 "Microsoft (R) C/C++ Optimizing Compiler Version 19.27.29112 for x86")
|C linker for the host machine: link link 14.27.29112.0
|Library m found: NO
|Library dl found: NO
|Library pthread found: NO
|Has header "alloca.h" : NO
|Has header "sys/types.h" : YES
|Has header "stdio.h" : YES
|Has header "stdlib.h" : YES
|Has header "stdarg.h" : YES
|Has header "malloc.h" : YES
|Has header "memory.h" : YES
|Has header "string.h" : YES
|Has header "strings.h" : NO
|Has header "inttypes.h" : YES
|Has header "stdint.h" : YES
|Has header "ctype.h" : YES
|Has header "math.h" : YES
|Has header "iconv.h" : NO
|Has header "signal.h" : YES
|Has header "altivec.h" : NO
|Has header "pthread/np.h" : NO
|Has header "libudev.h" : NO
|Has header "dbus/dbus.h" : NO
|Has header "stdarg.h" : YES (cached)
|Has header "stddef.h" : YES
|Checking for function "malloc" : YES
|Checking for function "calloc" : YES
|Checking for function "realloc" : YES
|Checking for function "free" : YES
|Checking for function "alloca" : NO
|Checking for function "setenv" : NO
|Checking for function "setenv" : NO
|Checking for function "putenv" : YES
|Checking for function "unsetenv" : NO
|Checking for function "qsort" : YES
|Checking for function "abs" : YES
|Checking for function "bcopy" : NO
|Checking for function "memset" : YES
|Checking for function "memcpy" : YES
|Checking for function "memmove" : YES
|Checking for function "memcmp" : YES
|Checking for function "strlen" : YES
|Checking for function "strlcpy" : NO
|Checking for function "strlcat" : NO
|Checking for function "strdup" : YES
|Checking for function "_strrev" : YES
|Checking for function "_strupr" : YES
|Checking for function "_strlwr" : YES
|Checking for function "index" : NO
|Checking for function "rindex" : NO
|Checking for function "strchr" : YES
|Checking for function "strrchr" : YES
|Checking for function "strstr" : YES
|Checking for function "itoa" : YES
|Checking for function "_ltoa" : NO
|Checking for function "_uitoa" : NO
|Checking for function "_ultoa" : YES
|Checking for function "strtol" : YES
|Checking for function "strtoul" : YES
|Checking for function "_i64toa" : YES
|Checking for function "_uit64toa" : NO
|Checking for function "strtoll" : YES
|Checking for function "strtoull" : YES
|Checking for function "strtod" : YES
|Checking for function "atoi" : YES
|Checking for function "atof" : YES
|Checking for function "strcmp" : YES
|Checking for function "strncmp" : YES
|Checking for function "_stricmp" : YES
|Checking for function "strcasecmp" : NO
|Checking for function "_strnicmp" : YES
|Checking for function "strncasecmp" : NO
|Checking for function "vsscanf" : YES
|Checking for function "vsnprintf" : YES
|Checking for function "atan" : YES
|Checking for function "atan2" : YES
|Checking for function "acos" : YES
|Checking for function "asin" : YES
|Checking for function "ceil" : YES
|Checking for function "copysign" : YES
|Checking for function "cos" : YES
|Checking for function "cosf" : YES
|Checking for function "fabs" : YES
|Checking for function "floor" : YES
|Checking for function "log" : YES
|Checking for function "pow" : YES
|Checking for function "scalbn" : YES
|Checking for function "sin" : YES
|Checking for function "sinf" : YES
|Checking for function "sqrt" : YES
|Checking for function "fseeko" : NO
|Checking for function "fseeko64" : NO
|Checking for function "sigaction" : NO
|Checking for function "setjmp" : NO
|Checking for function "nanosleep" : NO
|Checking for function "sysconf" : NO
|Checking for function "sysctlbyname" : NO
|Checking for function "clock_gettime" : NO
|Checking for function "getpagesize" : NO
|Checking for function "mprotect" : NO
|Checking for function "pthread_setname_np" : NO
|Checking for function "pthread_set_name_np" : NO
|Checking if "M_PI" compiles: NO
|Library winmm found: YES
|Library version found: YES
|Library imm32 found: YES
|Found CMake: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.EXE (3.17.20032601)
|Run-time dependency alsa found: NO (tried pkgconfig and cmake)
|Run-time dependency x11 found: NO (tried pkgconfig and cmake)
|Run-time dependency xi found: NO (tried pkgconfig and cmake)
|Run-time dependency xext found: NO (tried pkgconfig and cmake)
|Run-time dependency gl found: YES
|Run-time dependency xrandr found: NO (tried pkgconfig and cmake)
|Run-time dependency xinerama found: NO (tried pkgconfig and cmake)
|Library setupapi found: YES
|Build targets in project: 2
|Subproject sdl2 finished.

Dependency sdl2 from subproject subprojects/SDL2-2.0.12 found: YES 2.0.12
Build targets in project: 3

example undefined

  Subprojects
    sdl2: YES

Found ninja-1.10.1 at "C:\Program Files\Meson\ninja.EXE"

ninja -C builddir

ninja: Entering directory `builddir'
[173/175] Linking target subprojects/SDL2-2.0.12/sdl2.dll
FAILED: subprojects/SDL2-2.0.12/sdl2.dll subprojects/SDL2-2.0.12/sdl2.pdb
"link" @subprojects/SDL2-2.0.12/sdl2.dll.rsp
MSVCRTD.lib(ftol2.obj) : error LNK2005: __ftol2_sse already defined in src_stdlib_SDL_stdlib.c.obj
   Creating library subprojects\SDL2-2.0.12\sdl2.lib and object subprojects\SDL2-2.0.12\sdl2.exp
src_test_SDL_test_common.c.obj : error LNK2019: unresolved external symbol __imp____acrt_iob_func referenced in function _printf
src_test_SDL_test_common.c.obj : error LNK2019: unresolved external symbol __imp____stdio_common_vfprintf referenced in function __vfprintf_l
src_test_SDL_test_harness.c.obj : error LNK2019: unresolved external symbol __imp__exit referenced in function _SDLTest_BailOut
src_test_SDL_test_harness.c.obj : error LNK2019: unresolved external symbol __imp__clock referenced in function _GetClock
src_test_SDL_test_random.c.obj : error LNK2001: unresolved external symbol __imp__clock
src_test_SDL_test_log.c.obj : error LNK2019: unresolved external symbol __imp___localtime64 referenced in function _localtime
src_test_SDL_test_log.c.obj : error LNK2019: unresolved external symbol __imp__strftime referenced in function _SDLTest_TimestampToString
src_test_SDL_test_log.c.obj : error LNK2019: unresolved external symbol __imp___time64 referenced in function _time
src_test_SDL_test_random.c.obj : error LNK2001: unresolved external symbol __imp___time64
src_test_SDL_test_random.c.obj : error LNK2019: unresolved external symbol __imp__srand referenced in function _SDLTest_RandomInitTime
src_test_SDL_test_random.c.obj : error LNK2019: unresolved external symbol __imp__rand referenced in function _SDLTest_RandomInitTime
MSVCRTD.lib(init.obj) : error LNK2019: unresolved external symbol __CrtDbgReport referenced in function __CRT_RTC_INIT
MSVCRTD.lib(init.obj) : error LNK2019: unresolved external symbol __CrtDbgReportW referenced in function __CRT_RTC_INITWMSVCRTD.lib(ftol3.obj) : error LNK2001: unresolved external symbol __except1
MSVCRTD.lib(error.obj) : error LNK2019: unresolved external symbol _strcpy_s referenced in function "void __cdecl _RTC_StackFailure(void *,char const *)" (?_RTC_StackFailure@@YAXPAXPBD@Z)
MSVCRTD.lib(error.obj) : error LNK2019: unresolved external symbol _strcat_s referenced in function "void __cdecl _RTC_StackFailure(void *,char const *)" (?_RTC_StackFailure@@YAXPAXPBD@Z)
MSVCRTD.lib(error.obj) : error LNK2019: unresolved external symbol ___stdio_common_vsprintf_s referenced in function __vsprintf_s_l
MSVCRTD.lib(pdblkup.obj) : error LNK2019: unresolved external symbol __wmakepath_s referenced in function "int __cdecl GetPdbDllPathFromFilePath(wchar_t const *,wchar_t *,unsigned int)" (?GetPdbDllPathFromFilePath@@YAHPB_WPA_WI@Z)
MSVCRTD.lib(pdblkup.obj) : error LNK2019: unresolved external symbol __wsplitpath_s referenced in function "int __cdecl GetPdbDllPathFromFilePath(wchar_t const *,wchar_t *,unsigned int)" (?GetPdbDllPathFromFilePath@@YAHPB_WPA_WI@Z)
MSVCRTD.lib(pdblkup.obj) : error LNK2019: unresolved external symbol _wcscpy_s referenced in function "int __cdecl GetPdbDllPathFromFilePath(wchar_t const *,wchar_t *,unsigned int)" (?GetPdbDllPathFromFilePath@@YAHPB_WPA_WI@Z)
MSVCRTD.lib(pdblkup.obj) : error LNK2019: unresolved external symbol ___vcrt_GetModuleFileNameW referenced in function "struct HINSTANCE__ * __cdecl GetPdbDll(void)" (?GetPdbDll@@YAPAUHINSTANCE__@@XZ)
MSVCRTD.lib(pdblkup.obj) : error LNK2019: unresolved external symbol ___vcrt_GetModuleHandleW referenced in function "struct HINSTANCE__ * __cdecl GetPdbDll(void)" (?GetPdbDll@@YAPAUHINSTANCE__@@XZ)
MSVCRTD.lib(pdblkup.obj) : error LNK2019: unresolved external symbol ___vcrt_LoadLibraryExW referenced in function "struct HINSTANCE__ * __cdecl GetPdbDll(void)" (?GetPdbDll@@YAPAUHINSTANCE__@@XZ)
MSVCRTD.lib(chandler4_noexcept.obj) : error LNK2019: unresolved external symbol _terminate referenced in function __except_handler4_noexcept
MSVCRTD.lib(chandler4_noexcept.obj) : error LNK2019: unresolved external symbol ___current_exception referenced in function __except_handler4_noexcept
MSVCRTD.lib(chandler4_noexcept.obj) : error LNK2019: unresolved external symbol ___current_exception_context referenced in function __except_handler4_noexcept
MSVCRTD.lib(chandler4gs.obj) : error LNK2019: unresolved external symbol __except_handler4_common referenced in function __except_handler4
subprojects\SDL2-2.0.12\sdl2.dll : fatal error LNK1120: 25 unresolved externals
ninja: build stopped: subcommand failed.

"Solutions‽"

Adding "vcruntimed.lib" "ucrtd.lib" to LINK_ARGS for the sdl2.dll target in the build.ninja file cuts the errors down to:

ninja: Entering directory `builddir'
[1/3] Linking target subprojects/SDL2-2.0.12/sdl2.dll
FAILED: subprojects/SDL2-2.0.12/sdl2.dll subprojects/SDL2-2.0.12/sdl2.pdb
"link" @subprojects/SDL2-2.0.12/sdl2.dll.rsp
MSVCRTD.lib(ftol2.obj) : error LNK2005: __ftol2_sse already defined in src_stdlib_SDL_stdlib.c.obj
   Creating library subprojects\SDL2-2.0.12\sdl2.lib and object subprojects\SDL2-2.0.12\sdl2.exp
subprojects\SDL2-2.0.12\sdl2.dll : fatal error LNK1169: one or more multiply defined symbols found

No idea how to fix this last one.

jpakkane commented 4 years ago

You need to at least add win_subsystem to your executable's kwargs. See for example https://github.com/jpakkane/sdltest/blob/master/meson.build

miffe commented 4 years ago

Adding win_subsystem: 'windows' to executable doesn't make a difference, still the same errors.

But adding default_options : ['default_library=static', 'buildtype=debugoptimized'] to project from your example makes it work. It however links sdl2 statically, which is not ideal.

jpakkane commented 4 years ago

Sadly shared libraries on Windows are a bit of a pain. If you can get away with static libraries, they are usually simpler to get working.

miffe commented 4 years ago

Static sdl2 will work for me.

Thanks for meson btw, it's by far the nicest build system!