mimalloc icon indicating copy to clipboard operation
mimalloc copied to clipboard

mimalloc.o not available in vcpkg

Open muhammadhamzasajjad opened this issue 1 year ago • 4 comments

According to the docs for static override we should do

> gcc -o myprogram mimalloc.o  myfile1.c ...

I am using mimalloc from vcpkg. But the mimalloc.o file is not built by the vcpkg configuration of mimalloc as the target mimalloc-obj is also not built. In fact, MIMALLOC_OBJECT_DIR is not available which is supposed to be used for obtaining mimalloc.o.

How can we use mimalloc.o in vcpkg? Ideally I would want to be able to access mimalloc.o via CMake and then link it with the target. #532 seems similar but vcpkg build process for mimalloc doesn't make mimalloc-obj target available.

muhammadhamzasajjad avatar Jun 05 '24 17:06 muhammadhamzasajjad

To use mimalloc.o with vcpkg, follow these steps: 1. Install mimalloc via vcpkg:

vcpkg install mimalloc

2.	Build mimalloc.o manually:
•	Clone the mimalloc repository:

git clone https://github.com/microsoft/mimalloc.git cd mimalloc

•	Build mimalloc and generate mimalloc.o:

mkdir build
cd build
cmake ..
cmake --build . --target mimalloc

3.	Link mimalloc.o in your CMake project:

In your CMakeLists.txt, add:


target_sources(my_target PRIVATE ${CMAKE_SOURCE_DIR}/path/to/mimalloc/build/src/mimalloc.o)
4.	Build your project:

cmake --build .

This ensures you can use mimalloc.o with static overriding and link it manually in your project.

This summary highlights the main actions required and keeps it concise for easy reading.

imsharukh1994 avatar Dec 25 '24 10:12 imsharukh1994

To use mimalloc.o with vcpkg, follow these steps: 1. Install mimalloc via vcpkg: 2. Build mimalloc.o manually:

This does not make sense. Why build mimalloc manually in step 2 when you already installed it in step 1?

This comment, like any of yours recently, look like it's copied mostly straight out of the answer from some AI. What's the point here? To me, the utility of those comments is, at best, doubtful - they typically contain a lot of explanation, which overshadows any useful answer, if there even is any.

I'm not really important here, but as someone who reads the discussions & issues around mimalloc out of interest: Please Stop.

res2k avatar Dec 25 '24 11:12 res2k

I'm not really important here,

But you are Frank :-) Thank you for all your help and insightful comments over time!

With regards to vcpkg -- I am not maintaining this as those scripts are part of the vcpkg repo. It would be good though if it would build the mimalloc.o file too -- not sure why that would be disabled?

(ps. I am hesitant to start maintaining the vcpkg part of mimalloc but maybe someone can help out the current maintainer? I recently updated the CMakeFiles.txt for windows as well to generate mimalloc.dll instead of mimalloc-override.dll to be consistent across platforms; that might affect vcpkg as well)

daanx avatar Dec 25 '24 18:12 daanx

But you are Frank :-) Thank you for all your help and insightful comments over time!

Thanks for the kind words!

(ps. I am hesitant to start maintaining the vcpkg part of mimalloc but maybe someone can help out the current maintainer? I recently updated the CMakeFiles.txt for windows as well to generate mimalloc.dll instead of mimalloc-override.dll to be consistent across platforms; that might affect vcpkg as well)

While I'm not using mimalloc through vcpkg myself, I took a quick look at it's "port":

  • mimalloc-override.dll doesn't seem to be mentioned at all by name, so any change to it's name would probably not affect the port.
  • Generally, I think the version used by the vcpkg port has to be updated manually, so I don't think you have to worry about any git changes etc. surprisingly affecting the vcpkg side.
  • It looks as if the vcpkg package will be assembled using cmake install... don't know if mimalloc.o is included in the set of installed files, but maybe that's worth considering?

And judging from the git log for mimallloc in vcpkg (https://github.com/microsoft/vcpkg/commits/master/ports/mimalloc) there's no singular maintainer...

That said, it looks like the "organic" approach - someone has an issue with the port, writes an issue and/or provides a patch - seemed to work out okay in the past; maybe hope it continues to do so? There's also vcpkg's own issue tracker, so if you think anyone needs a heads-up for the next port update, maybe that could be a suitable place as well to at least leave some info for whoever may pick it up?

res2k avatar Dec 26 '24 11:12 res2k