microsoft / microsoft/mimalloc
Mimalloc together with MFC on Windows causes link errors
- Dominant language
- C
- Stars
- 13.4k
- Forks
- 1.2k
- Avg merge
- 4d 45m
- Merged PRs (30d)
- 13
Description
Hi,
I am trying to use mimalloc on Windows to speed up an existing application that is currently using MFC. I am using the following CMake to include mimalloc:
```cmake
add_subdirectory(external/mimalloc)
target_link_libraries(myProject PUBLIC mimalloc-static)
```
and then at the top of the main file I have
```cpp
#include "mimalloc-new-delete.h"
```
When building I get the following error:
```
FAILED: myProject/myProject.exe
cmd.exe /C "cd . && "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E vs_link_exe --intdir=myProject\CMakeFiles\myProject.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100183~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100183~1.0\x64\mt.exe --manifests ..\..\..\os.manifest -- C:\PROGRA~2\MICROS~4\2019\PROFES~1\VC\Tools\MSVC\1428~1.299\bin\Hostx64\x64\link.exe /nologo myProject\CMakeFiles\myProject.dir\myProject_Source\myProject\myProject.CPP.obj myProject\CMakeFiles\myProject.dir\myProject_Source\myProject\myProject.RC.res /out:myProject\myProject.exe /implib:myProject\myProject.lib /pdb:myProject\myProject.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:windows /NODEFAULTLIB:libcmt.lib myProject\myProject_Lib.lib _deps\mimalloc-build\mimalloc-static-debug.lib myProject_REPORT\myProject_REPORT.lib OSGUI\OSGUI.lib OS_ODBC\OS_ODBC.lib psapi.lib fuzzy\fuzzy.lib myProject_CALC\myProject_CALC.lib myProject_RESULT\myProject_RESULT.lib OPSIMINPUT_FORMS\OPSIMINPUT_FORMS.lib OSDB\OSDB.lib external\JsonCpp.lib OPSIMINPUT\OPSIMINPUT.lib OSBASE\OSBASE.lib ..\..\..\external\SuperPro\x64\spromeps.lib ..\..\..\external\SentinelRMS\x64\lsapiw64.lib legacy_stdio_definitions.lib psapi.lib shell32.lib user32.lib advapi32.lib bcrypt.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cmd.exe /C "cd /D C:\Users\siry\code\os-src\out\build\x64-Debug\myProject && "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe" -E copy_if_different C:/Users/siry/code/os-src/external/SuperPro/x64/USAFE64.DLL C:/Users/siry/code/os-src/out/build/x64-Debug/myProject""
LINK Pass 1: command "C:\PROGRA~2\MICROS~4\2019\PROFES~1\VC\Tools\MSVC\1428~1.299\bin\Hostx64\x64\link.exe /nologo myProject\CMakeFiles\myProject.dir\myProject_Source\myProject\myProject.CPP.obj myProject\CMakeFiles\myProject.dir\myProject_Source\myProject\myProject.RC.res /out:myProject\myProject.exe /implib:myProject\myProject.lib /pdb:myProject\myProject.pdb /version:0.0 /machine:x64 /debug /INCREMENTAL /subsystem:windows /NODEFAULTLIB:libcmt.lib myProject\myProject_Lib.lib _deps\mimalloc-build\mimalloc-static-debug.lib myProject_REPORT\myProject_REPORT.lib OSGUI\OSGUI.lib OS_ODBC\OS_ODBC.lib psapi.lib fuzzy\fuzzy.lib myProject_CALC\myProject_CALC.lib myProject_RESULT\myProject_RESULT.lib OPSIMINPUT_FORMS\OPSIMINPUT_FORMS.lib OSDB\OSDB.lib external\JsonCpp.lib OPSIMINPUT\OPSIMINPUT.lib OSBASE\OSBASE.lib ..\..\..\external\SuperPro\x64\spromeps.lib ..\..\..\external\SentinelRMS\x64\lsapiw64.lib legacy_stdio_definitions.lib psapi.lib shell32.lib user32.lib advapi32.lib bcrypt.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:myProject\CMakeFiles\myProject.dir/intermediate.manifest myProject\CMakeFiles\myProject.dir/manifest.res" failed (exit code 1169) with the following output:
C:\Users\siry\code\os-src\out\build\x64-Debug\nafxcwd.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new(unsigned __int64)" (??2@YAPEAX_K@Z) already defined in myProject.CPP.obj
C:\Users\siry\code\os-src\out\build\x64-Debug\nafxcwd.lib(afxmem.obj) : error LNK2005: "void __cdecl operator delete(void *)" (??3@YAXPEAX@Z) already defined in myProject.CPP.obj
C:\Users\siry\code\os-src\out\build\x64-Debug\nafxcwd.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new[](unsigned __int64)" (??_U@YAPEAX_K@Z) already defined in myProject.CPP.obj
C:\Users\siry\code\os-src\out\build\x64-Debug\nafxcwd.lib(afxmem.obj) : error LNK2005: "void __cdecl operator delete[](void *)" (??_V@YAXPEAX@Z) already defined in myProject.CPP.obj
C:\Users\siry\code\os-src\out\build\x64-Debug\myProject\myProject.exe : fatal error LNK1169: one or more multiply defined symbols found
```
As far as I can tell, mimalloc and MFC both override `new/delete`. Is there a way to get around this while still using MFC?
Best regards,
Simon
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the CMake target linking _deps/mimalloc-build/mimalloc-static-debug.lib and the main file's inclusion of mimalloc-new-delete.h. Compare those definitions with the MFC symbols reported from nafxcwd.lib/afxmem.obj, then verify the chosen integration still links with MFC without LNK2005 or LNK1169 errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cmake, cpp
- Domain
- build-system, desktop
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100