emoon/minifb

Building as submodule & subdirectory as dependency using CMake fails on Windows

Dashbloxx opened this issue · 5 comments

Building as submodule & subdirectory as dependency using CMake fails on Windows

I'm on Windows attempting to use MiniFB as a dependency, however I get an explosion of errors when building it with MinGW makefiles (cmake .. -G "MinGW Makefiles" & mingw32-make -j8):

lld-link: error: <root>: undefined symbol: mainCRTStartup
lld-link: error: undefined symbol: __acrt_iob_func
>>> referenced by C:\Users\REDACTED\Documents\rtxngin\minifb\tests\input_events_cpp.cpp:23
>>>               CMakeFiles/input_events_cpp.dir/tests/input_events_cpp.cpp.obj:(public: void __cdecl Events::active(struct mfb_window *, bool))
>>> referenced by C:\Users\REDACTED\Documents\rtxngin\minifb\tests\input_events_cpp.cpp:34
>>>               CMakeFiles/input_events_cpp.dir/tests/input_events_cpp.cpp.obj:(public: void __cdecl Events::resize(struct mfb_window *, int, int))
>>> referenced by C:\Users\REDACTED\Documents\rtxngin\minifb\tests\input_events_cpp.cpp:51
>>>               CMakeFiles/input_events_cpp.dir/tests/input_events_cpp.cpp.obj:(public: bool __cdecl Events::close(struct mfb_window *))
>>> referenced 10 more times

lld-link: error: undefined symbol: __CxxFrameHandler3
>>> referenced by CMakeFiles/input_events_cpp.dir/tests/input_events_cpp.cpp.obj:(.xdata)
>>> referenced by CMakeFiles/input_events_cpp.dir/tests/input_events_cpp.cpp.obj:(.xdata)
>>> referenced by CMakeFiles/input_events_cpp.dir/tests/input_events_cpp.cpp.obj:(.xdata)
>>> referenced 59 more times

lld-link: error: undefined symbol: __stdio_common_vfprintf
>>> referenced by C:\Program Files (x86)\Windows Kits\10\Include\10.0.22621.0\ucrt\stdio.h:645
>>>               CMakeFiles/input_events_cpp.dir/tests/input_events_cpp.cpp.obj:(_vfprintf_l)
>>> referenced by minifb.lib(WinMiniFB.c.obj)
>>> referenced by minifb.lib(MiniFB_GL.c.obj)

lld-link: error: undefined symbol: __std_terminate
>>> referenced by C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\include\tuple:361
>>>               CMakeFiles/input_events_cpp.dir/tests/input_events_cpp.cpp.obj:(int `public: __cdecl std::tuple<class Events *, struct std::_Ph<1>, struct std::_Ph<2>>::tuple<class Events *, struct std::_Ph<1>, struct std::_Ph<2>><class Events *, struct std::_Ph<1> const &, struct std::_Ph<2> const &, 0>(class Events *&&, struct tuple<class Events *, struct std::_Ph<1>, struct std::_Ph<2>>::_Ph<1> const &, struct tuple<class Events *, struct std::_Ph<1>, struct std::_Ph<2>>::_Ph<2> const &)'::`1'::dtor$2)
>>> referenced by C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\include\tuple:361
>>>               CMakeFiles/input_events_cpp.dir/tests/input_events_cpp.cpp.obj:(int `public: __cdecl std::tuple<struct mfb_window *&&, bool &&>::tuple<struct mfb_window *&&, bool &&><struct mfb_window *, bool, 0>(struct mfb_window *&&, bool &&)'::`1'::dtor$2)
>>> referenced by C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\include\xmemory:261
>>>               CMakeFiles/input_events_cpp.dir/tests/input_events_cpp.cpp.obj:(int `void __cdecl std::_Deallocate<8, 0>(void *, unsigned __int64)'::`1'::dtor$4)
>>> referenced 21 more times

lld-link: error: undefined symbol: void __cdecl operator delete(void *, unsigned __int64)
>>> referenced by C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\include\xmemory:264
>>>               CMakeFiles/input_events_cpp.dir/tests/input_events_cpp.cpp.obj:(void __cdecl std::_Deallocate<8, 0>(void *, unsigned __int64))
>>> referenced by C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\include\xmemory:264
>>>               minifb.lib(MiniFB_cpp.cpp.obj):(void __cdecl std::_Deallocate<16, 0>(void *, unsigned __int64))
>>> referenced by libcpmtd.lib(xthrow.obj):($LN4)
>>> referenced 7 more times

lld-link: error: undefined symbol: _CrtDbgReport
>>> referenced by C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\include\xmemory:163
>>>               CMakeFiles/input_events_cpp.dir/tests/input_events_cpp.cpp.obj:(void __cdecl std::_Adjust_manually_vector_aligned(void *&, unsigned __int64 &))
>>> referenced by C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\include\xmemory:173
>>>               CMakeFiles/input_events_cpp.dir/tests/input_events_cpp.cpp.obj:(void __cdecl std::_Adjust_manually_vector_aligned(void *&, unsigned __int64 &))
>>> referenced by C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\include\xmemory:144
>>>               minifb.lib(MiniFB_cpp.cpp.obj):(void * __cdecl std::_Allocate_manually_vector_aligned<struct std::_Default_allocate_traits>(unsigned __int64))
>>> referenced 10 more times

lld-link: error: undefined symbol: _invalid_parameter
>>> referenced by C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\include\xmemory:163
>>>               CMakeFiles/input_events_cpp.dir/tests/input_events_cpp.cpp.obj:(void __cdecl std::_Adjust_manually_vector_aligned(void *&, unsigned __int64 &))
>>> referenced by C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\include\xmemory:173
>>>               CMakeFiles/input_events_cpp.dir/tests/input_events_cpp.cpp.obj:(void __cdecl std::_Adjust_manually_vector_aligned(void *&, unsigned __int64 &))
>>> referenced by C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\include\xmemory:144
>>>               minifb.lib(MiniFB_cpp.cpp.obj):(void * __cdecl std::_Allocate_manually_vector_aligned<struct std::_Default_allocate_traits>(unsigned __int64))
>>> referenced 10 more times

lld-link: error: undefined symbol: const type_info::`vftable'
>>> referenced by CMakeFiles/input_events_cpp.dir/tests/input_events_cpp.cpp.obj:(class std::_Func_impl_no_alloc<class std::_Binder<struct std::_Unforced, void (__cdecl Events::*)(struct mfb_window *, bool), class Events *, struct std::_Ph<1> const &, struct std::_Ph<2> const &>, void, struct mfb_window *, bool> `RTTI Type Descriptor')
>>> referenced by CMakeFiles/input_events_cpp.dir/tests/input_events_cpp.cpp.obj:(class std::_Func_base<void, struct mfb_window *, bool> `RTTI Type Descriptor')
>>> referenced by CMakeFiles/input_events_cpp.dir/tests/input_events_cpp.cpp.obj:(class std::_Binder<struct std::_Unforced, void (__cdecl Events::*)(struct mfb_window *, bool), class Events *, struct std::_Ph<1> const &, struct std::_Ph<2> const &> `RTTI Type Descriptor')
>>> referenced 43 more times

lld-link: error: undefined symbol: _fltused
>>> referenced by CMakeFiles/input_events_cpp.dir/tests/input_events_cpp.cpp.obj
>>> referenced by minifb.lib(MiniFB_common.c.obj)
>>> referenced by minifb.lib(MiniFB_cpp.cpp.obj)

lld-link: error: undefined symbol: _tls_index
>>> referenced by C:\Users\REDACTED\Documents\rtxngin\minifb\src\MiniFB_cpp.cpp:32
>>>               minifb.lib(MiniFB_cpp.cpp.obj):(private: static class mfb_stub * __cdecl mfb_stub::GetInstance(struct mfb_window *))

lld-link: error: undefined symbol: _Init_thread_epoch
>>> referenced by C:\Users\REDACTED\Documents\rtxngin\minifb\src\MiniFB_cpp.cpp:32
>>>               minifb.lib(MiniFB_cpp.cpp.obj):(private: static class mfb_stub * __cdecl mfb_stub::GetInstance(struct mfb_window *))

lld-link: error: undefined symbol: _Init_thread_header
>>> referenced by C:\Users\REDACTED\Documents\rtxngin\minifb\src\MiniFB_cpp.cpp:32
>>>               minifb.lib(MiniFB_cpp.cpp.obj):(private: static class mfb_stub * __cdecl mfb_stub::GetInstance(struct mfb_window *))

lld-link: error: undefined symbol: atexit
>>> referenced by C:\Users\REDACTED\Documents\rtxngin\minifb\src\MiniFB_cpp.cpp:32
>>>               minifb.lib(MiniFB_cpp.cpp.obj):(private: static class mfb_stub * __cdecl mfb_stub::GetInstance(struct mfb_window *))
>>> referenced by D:\a\_work\1\s\src\vctools\crt\github\stl\src\xlock.cpp:60
>>>               libcpmtd.lib(xlock.obj):(void __cdecl `dynamic initializer for 'std::initlocks''(void))

lld-link: error: undefined symbol: _Init_thread_footer
>>> referenced by C:\Users\REDACTED\Documents\rtxngin\minifb\src\MiniFB_cpp.cpp:32
>>>               minifb.lib(MiniFB_cpp.cpp.obj):(private: static class mfb_stub * __cdecl mfb_stub::GetInstance(struct mfb_window *))

lld-link: error: undefined symbol: void __cdecl operator delete(void *)
>>> referenced by C:\Users\REDACTED\Documents\rtxngin\minifb\src\MiniFB_cpp.cpp:15
>>>               minifb.lib(MiniFB_cpp.cpp.obj):(public: __cdecl `private: static class mfb_stub * __cdecl mfb_stub::GetInstance(struct mfb_window *)'::`2'::stub_vector::~stub_vector(void))
>>> referenced by C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\include\vcruntime_exception.h:134
>>>               minifb.lib(MiniFB_cpp.cpp.obj):(public: virtual void * __cdecl std::bad_array_new_length::`scalar deleting dtor'(unsigned int))
>>> referenced by C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\include\vcruntime_exception.h:114
>>>               minifb.lib(MiniFB_cpp.cpp.obj):(public: virtual void * __cdecl std::bad_alloc::`scalar deleting dtor'(unsigned int))
>>> referenced 1 more times

lld-link: error: undefined symbol: void * __cdecl operator new(unsigned __int64)
>>> referenced by C:\Users\REDACTED\Documents\rtxngin\minifb\src\MiniFB_cpp.cpp:25
>>>               minifb.lib(MiniFB_cpp.cpp.obj):(public: class mfb_stub * __cdecl `private: static class mfb_stub * __cdecl mfb_stub::GetInstance(struct mfb_window *)'::`2'::stub_vector::Get(struct mfb_window *))
>>> referenced by C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\include\xmemory:86
>>>               minifb.lib(MiniFB_cpp.cpp.obj):(public: static void * __cdecl std::_Default_allocate_traits::_Allocate(unsigned __int64))

lld-link: error: undefined symbol: _CxxThrowException
>>> referenced by C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\include\exception:331
>>>               minifb.lib(MiniFB_cpp.cpp.obj):(void __cdecl std::_Throw_bad_array_new_length(void))
>>> referenced by C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\include\vector:851
>>>               minifb.lib(MiniFB_cpp.cpp.obj):(int `private: class mfb_stub ** __cdecl std::vector<class mfb_stub *, class std::allocator<class mfb_stub *>>::_Emplace_reallocate<class mfb_stub *>(class std **const, class std *&&)'::`1'::catch$7)
>>> referenced by D:\a\_work\1\s\src\vctools\crt\github\stl\src\xthrow.cpp:13
>>>               libcpmtd.lib(xthrow.obj):($LN3)
>>> referenced 7 more times

lld-link: error: undefined symbol: __std_exception_copy
>>> referenced by C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\include\vcruntime_exception.h:73
>>>               minifb.lib(MiniFB_cpp.cpp.obj):(public: __cdecl std::exception::exception(class std::exception const &))
>>> referenced by D:\a\_work\1\s\src\vctools\crt\vcruntime\inc\vcruntime_exception.h:61
>>>               libcpmtd.lib(xthrow.obj):($LN3)

lld-link: error: undefined symbol: memset
>>> referenced by C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\include\vcruntime_exception.h:66
>>>               minifb.lib(MiniFB_cpp.cpp.obj):(public: __cdecl std::exception::exception(char const *const, int))
>>> referenced by C:\Users\REDACTED\Documents\rtxngin\minifb\src\windows\WinMiniFB.c:379
>>>               minifb.lib(WinMiniFB.c.obj):(WndProc)
>>> referenced by C:\Users\REDACTED\Documents\rtxngin\minifb\src\windows\WinMiniFB.c:451
>>>               minifb.lib(WinMiniFB.c.obj):(mfb_open_ex)
>>> referenced 4 more times

lld-link: error: too many errors emitted, stopping now (use /errorlimit:0 to see all errors)
CLANG_~1: error: linker command failed with exit code 1 (use -v to see invocation)
minifb\CMakeFiles\input_events_cpp.dir\build.make:99: recipe for target 'minifb/input_events_cpp.exe' failed
mingw32-make[2]: *** [minifb/input_events_cpp.exe] Error 1
CMakeFiles\Makefile2:329: recipe for target 'minifb/CMakeFiles/input_events_cpp.dir/all' failed
mingw32-make[1]: *** [minifb/CMakeFiles/input_events_cpp.dir/all] Error 2
[100%] Built target RTXNGIN
Makefile:134: recipe for target 'all' failed
mingw32-make: *** [all] Error 2
emoon commented

I haven't done any of the CMake setup, so @Darky-Lucera may know more about it. The thing that stands out for me tho is that you say you are using mingw32 but include directories (such as C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\include\vcruntime_exception.h) is from Visual Studio so I'm not really sure what is going on here.

I'm asking CMake to generate MinGW Makefiles, although I build using Microsoft's official toolchain.

I haven't done any of the CMake setup, so @Darky-Lucera may know more about it. The thing that stands out for me tho is that you say you are using mingw32 but include directories (such as C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\include\vcruntime_exception.h) is from Visual Studio so I'm not really sure what is going on here.

emoon commented

Ah,

Could you try to generate a Visual Studio Project instead just to see if that works?

Sure, this kind of mix does not have much sense.
if you use MingGW makefiles you need to use the MinGW toolchain, if you use VS projects you have to use MSVC toolchain or clang (the one that comes with MSVC).