microsoft / microsoft/mimalloc
Cannot build C project using mimalloc on mac m1
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 13.4k
- Forks
- 1.2k
- Avg merge
- 4d 45m
- Merged PRs (30d)
- 13
Description
I have built a simple C project using mimalloc on my mac m1, but when I try to build it, it throw an error
```
Undefined symbols for architecture arm64:
"std::bad_alloc::bad_alloc()", referenced from:
mi_try_new_handler(bool) in libmimalloc-debug.a[2](alloc.c.o)
"std::bad_alloc::~bad_alloc()", referenced from:
mi_try_new_handler(bool) in libmimalloc-debug.a[2](alloc.c.o)
"std::get_new_handler()", referenced from:
mi_try_new_handler(bool) in libmimalloc-debug.a[2](alloc.c.o)
"std::terminate()", referenced from:
___clang_call_terminate in libmimalloc-debug.a[2](alloc.c.o)
"typeinfo for std::bad_alloc", referenced from:
mi_try_new_handler(bool) in libmimalloc-debug.a[2](alloc.c.o)
"___cxa_allocate_exception", referenced from:
mi_try_new_handler(bool) in libmimalloc-debug.a[2](alloc.c.o)
"___cxa_begin_catch", referenced from:
___clang_call_terminate in libmimalloc-debug.a[2](alloc.c.o)
"___cxa_throw", referenced from:
mi_try_new_handler(bool) in libmimalloc-debug.a[2](alloc.c.o)
"___gxx_personality_v0", referenced from:
/Users/phuc/.vcpkg-clion/vcpkg/installed/arm64-osx/debug/lib/libmimalloc-debug.a[2](alloc.c.o)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
```
I use vcpkg to install mimalloc and integrate with my IDE is Clion, this is my .c file and CMakeLists.txt:
test.c:
```{c}
#include
#include
int main(void) {
int n;
scanf("%d", &n);
int *a = mi_malloc(n * sizeof(int));
for (int i = 0; i < n; i++) {
a[i] = i;
}
for (int i = 0; i < n - 1; i++) {
a[i] *= 2;
}
for (int i = 0; i < n - 1; i++) {
printf("%d ", a[i]);
}
mi_free(a);
return 0;
}
```
CMakeLists.txt:
```
cmake_minimum_required(VERSION 4.0)
project(test C)
set(CMAKE_C_STANDARD 23)
set(CMAKE_OSX_ARCHITECTURES "x86_64;arm64" CACHE STRING "Target macOS architectures")
add_executable(test main.c)
find_package(mimalloc CONFIG REQUIRED)
target_link_libraries(test PRIVATE $,mimalloc-static,mimalloc>)
```
Please help me.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with test.c and CMakeLists.txt, then reproduce the arm64 link failure using the shown mimalloc-static target. Inspect how that target is built and linked for the macOS architectures in the report. Done means the supplied C project builds and links successfully on the reported Mac M1 configuration.
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