You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MacBook Ventura下C程序调用ATL_dgemm的编译与安装问题求助

MacBook Ventura下ATLAS库调用失败及安装问题

我是一名大学生,正在学习矩阵乘法,尝试在C语言中测试不同实现方式,其中包括ATLAS库。但在运行Ventura 13.5.2的MacBook上,无论是在CLion中还是直接用gcc编译调用ATL_dgemm函数的代码时,均出现“ATL_dgemm函数隐式声明”的错误。该代码在学校提供的Linux环境中可正常运行,但我无法查看其配置细节。我尝试用sudo port install atlas +nofortran手动安装ATLAS,却遇到编译失败的问题。现寻求明确的配置指导,以让MacBook识别并运行该代码。


测试代码

#include <stdio.h>
#include <stdlib.h>
#include <cblas.h>
#include "sys/time.h"

void initMat( int M, int N, double mat[], double val )
{
    int i, j;
    for (i= 0; i< M; i++)
        for (j= 0; j< N; j++)
            mat[i*N+j] = val;
}

int main(void)
{
    int dimensions[] = {1, 5, 10, 100, 200, 400, 500, 1000, 1500, 1600, 1700, 1800, 1900, 2000};
    for (int dimension_index = 0; dimension_index < 14; dimension_index++) {
        int dimension = dimensions[dimension_index];
        double ALPHA = 1.0, BETA = 1.0;
        int n = 1000;
        double *A;
        double *B;
        double *C;
        int numreps = 5;

        int i = 0;
        int j = 0;

        struct timeval tv1, tv2;
        struct timezone tz;

        // allocate memory for the matrices
        A = malloc(dimension * dimension * sizeof(double));
        B = malloc(dimension * dimension * sizeof(double));
        C = malloc(dimension * dimension * sizeof(double));
        if (!A || !B || !C) {
            printf("Out of memory, reduce N value.\n");
            exit(-1);
        }

        // initialise matrices A and B
        initMat(dimension, dimension, A, rand());
        initMat(dimension, dimension, B, rand());

        //multiply matrices
        printf("Multiply matrices %d times using ATLAS for %d dimensions...\n", numreps, dimension);

        gettimeofday(&tv1, &tz);
        for (i = 0; i < numreps; i++) {
            ATL_dgemm(CblasNoTrans, CblasNoTrans, dimension, dimension, dimension, 1.0, A, dimension, B, dimension, 0.0, C, dimension);
        }
        gettimeofday(&tv2, &tz);
        double elapsed = (double) (tv2.tv_sec - tv1.tv_sec) + (double) (tv2.tv_usec - tv1.tv_usec) * 1.e-6;
        printf("Done ...: time taken for %d dimensions: %fs\n", dimension, elapsed);
        //deallocate memory
        free(A);
        free(B);
        free(C);
    }

    return 0;
}

CMakeLists.txt内容

cmake_minimum_required(VERSION 3.26)
project(atlas C)

set(CMAKE_C_STANDARD 90)

include_directories(
    /usr/local/Cellar/openblas/0.3.24/include
)

add_executable(atlas main.c)

CLion编译错误信息

error: implicit declaration of function 'ATL_dgemm' [-Werror,-Wimplicit-function-declaration]
ATL_dgemm(CblasNoTrans, CblasNoTrans, dimension, dimension, dimension, 1.0, A, dimension, B, dimension, 0.0, C, dimension);

直接gcc编译命令及错误

编译命令:

gcc -O3 -I/usr/local/Cellar/openblas/0.3.24/include -o atlas main.c -latlas -lblas -lm

错误信息:

main.c:51:13: error: call to undeclared function 'ATL_dgemm'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
            ATL_dgemm(CblasNoTrans, CblasNoTrans, dimension, dimension, dimension, 1.0, A, dimension, B, dimension, 0.0, C, dimension);
            ^
1 error generated.

ATLAS安装失败错误摘要

...
/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_math_atlas/atlas/work/ATLAS/build/..//CONFIG/src/probe_comp.c:1165:17: error: call to undeclared function 'CompIsMinGW'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
            if (CompIsMinGW(gccs[i]) || CompIsAppleGcc(gccs[i]))
                ^
1 error generated.
...
make[1]: *** No rule to make target `Make.inc'.  Stop.
make: *** [build] Error 2

内容的提问来源于stack exchange,提问作者Lorcan O'Neill

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.08 02:29:56