mesonbuild / meson

The Meson Build System
http://mesonbuild.com
Apache License 2.0
5.41k stars 1.55k forks source link

MSVC + Rust + C++ + GLM/GLFW3 don't work #13288

Open Nautilus-1021 opened 1 month ago

Nautilus-1021 commented 1 month ago

Describe the bug Compiling a project that uses a combination of Rust and C++, with GLM and GLFW3 causes the compilation to fail.

"link"  /MACHINE:x64 /OUT:main.exe main.exe.p/main.cpp.obj main.exe.p/lib_glad.c.obj main.exe.p/lib_functions.cpp.obj "/release" "/nologo" "/DEBUG" "/PDB:main.pdb" "librustlib.a" "subprojects/glfw-3.3.10/glfw3.lib" "kernel32.lib" "advapi32.lib" "ntdll.lib" "userenv.lib" "ws2_32.lib" "msvcrt.lib" "/SUBSYSTEM:CONSOLE" "user32.lib" "gdi32.lib" "winspool.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "comdlg32.lib"
LINK : warning LNK4098: conflit entre la bibliothèque par défaut 'MSVCRTD' et les autres bibliothèques ; utilisez /NODEFAULTLIB:library
main.cpp.obj : error LNK2019: symbole externe non résolu __imp__invalid_parameter référencé dans la fonction "void * __cdecl std::_Allocate_manually_vector_aligned<struct std::_Default_allocate_traits>(unsigned __int64)" (??$_Allocate_manually_vector_aligned@U_Default_allocate_traits@std@@@std@@YAPEAX_K@Z)
main.cpp.obj : error LNK2019: symbole externe non résolu __imp__CrtDbgReport référencé dans la fonction "void * __cdecl std::_Allocate_manually_vector_aligned<struct std::_Default_allocate_traits>(unsigned __int64)" (??$_Allocate_manually_vector_aligned@U_Default_allocate_traits@std@@@std@@YAPEAX_K@Z)
msvcprtd.lib(locale0_implib.obj) : error LNK2019: symbole externe non résolu __imp__free_dbg référencé dans la fonction "public: static void __cdecl std::_Fac_node::operator delete(void *)" (??3_Fac_node@std@@SAXPEAX@Z)   
msvcprtd.lib(locale0_implib.obj) : error LNK2019: symbole externe non résolu __imp__malloc_dbg référencé dans la fonction "public: static void * __cdecl std::_Fac_node::operator new(unsigned __int64)" (??2_Fac_node@std@@SAPEAX_K@Z)
main.exe : fatal error LNK1120: 4 externes non résolus
ninja: build stopped: subcommand failed.

In a basic hello world with some Rust code and some C++ code, it just throws a warning (LINK : warning LNK4098: conflit entre la bibliothèque par défaut 'MSVCRTD' et les autres bibliothèques ; utilisez /NODEFAULTLIB:library), but when I try to compile a basic OpenGL project, conflicts appear, and the compilation fails. After some debugging, I found that Meson asks explecitly MSVC to link the executable with msvcrt.lib, even though MSVC does that itself. I think that by default, MSVC link executables with msvcrtd in a debug build, so if Meson asks it also to link with msvcrt.lib, MSVC fails to link the executable. So to correct the problem I manually removed the explicit msvcrt.lib from the build.ninja file and the project compiled juste fine without even a warning. I am sorry for the crash log, the errors are in french.

To Reproduce

project('SampleOpenGLProject', 'c', 'cpp', 'rust')

rust_sources = ['rustsrc/lib.rs']
rustlib = static_library('rustlib', rust_sources, rust_abi: 'c')

sources = ['main.cpp', 'lib/glad.c', 'lib/functions.cpp']
include_dir = include_directories('Include')
glfw_dep = dependency('glfw3')
glm_dep = dependency('glm')

executable('main', sources: sources, include_directories: include_dir, dependencies: [glfw_dep, glm_dep], link_with: rustlib)

system parameters

Windows 11 Visual Studio Build Tools 2022 17.10.1 / MSVC 19.40.33811 Python 3.12.3 Meson 1.4.1 Ninja 1.11.1

Nautilus-1021 commented 1 month ago

The issue maybe shares the same root as this issue (#13236)