Cannot build C project using mimalloc on mac m1

Đang mở
#1,130 5 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
c, cmake
Lĩnh vực
build-system

Hướng nghiên cứu

Bắt đầu với test.c và CMakeLists.txt, sau đó tái hiện lỗi liên kết arm64 bằng target mimalloc-static được nêu. Kiểm tra cách target đó được build và liên kết cho các kiến trúc macOS trong báo cáo. Hoàn thành khi dự án C được cung cấp build và liên kết thành công trên cấu hình Mac M1 được nêu.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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:

#include <stdio.h>
#include <mimalloc.h>

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 $<IF:$<TARGET_EXISTS:mimalloc-static>,mimalloc-static,mimalloc>)

Please help me.

Ngôn ngữ chính
C
Star
13.6k
Fork
1.2k
Merge trung bình
18 giờ 12 phút
Pull request đã merge (30 ngày)
20

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của microsoft/mimalloc

Tất cả issue của microsoft/mimalloc

Issue tương tự

Thêm issue về C

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.