microsoft / microsoft/mimalloc
Multiple definition errors when including mimalloc-new-delete.h.
- Dominant language
- C
- Stars
- 13.4k
- Forks
- 1.2k
- Avg merge
- 4d 45m
- Merged PRs (30d)
- 13
Description
I am trying to override the new/delete operators as suggested in the [documentation](https://microsoft.github.io/mimalloc/using.html). I am using vcpkg and added the following statements in my CMakeLists.txt file:
```
find_package(mimalloc 1.6 REQUIRED)
...
target_link_libraries(my_webserver PUBLIC mimalloc-static)
```
My program compiles just fine with the above changes but when I include `mimalloc-new-delete.h`, it starts to give linker errors as follows:
```
/usr/bin/ld: /vcpkg/installed/x64-linux/share/mimalloc/../../lib/libmimalloc.a(alloc.c.o): in function `operator delete[](void*)':
alloc.c:(.text+0x140): multiple definition of `operator delete[](void*)'; CMakeFiles/my_webserver .dir/service/my_webserver .cpp.o:my_webserver .cpp:(.text+0x10): first defined here
/usr/bin/ld: /vcpkg/installed/x64-linux/share/mimalloc/../../lib/libmimalloc.a(alloc.c.o): in function `operator delete[](void*, std::align_val_t)':
...
```
How do I avoid these multiple definition errors? Any help is appreciated. Thanks in advance !
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the linked mimalloc using documentation, then inspect the CMakeLists.txt entries for find_package and target_link_libraries alongside the inclusion of mimalloc-new-delete.h. Reproduce the link with mimalloc-static and compare the duplicate operator definitions; done means the program links without multiple-definition errors while retaining the intended allocator override.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, cmake
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100