美文网首页
linux中的编译理解

linux中的编译理解

作者: expgene | 来源:发表于2024-05-14 11:17 被阅读0次

    探序基因肿瘤研究院  整理

    1. 编辑一个test3.c文件,如下

    #include <stdio.h>

    #include <math.h>

    double ddot_(int *,double *,int *,double *,int *);

    int main()

    {

        int N=2, INCX=1, INCY=1;

        double X[2]={1.0,1.0};

        double Y[2]={2.0,2.0};

        double re;

        re=ddot_(&N, X, &INCX, Y, &INCY);

        printf("the result is:%f\n", re);

        return 0;

    }

    linux命令行运行:

    gcc -c test3.c -o test3.o

    gcc -o test3 test3.o -lblas -lgfortran

    2. test2.c

    #include <stdio.h>

    #include <lapacke.h>

    int main (int argc, const char * argv[])

    {

      double a[5][3] = {1,1,1,2,3,4,3,5,2,4,2,5,5,4,3};

      double b[5][2] = {-10,-3,12,14,14,12,16,16,18,16};

      lapack_int info,m,n,lda,ldb,nrhs;

      int i,j;

      m = 5;

      n = 3;

      nrhs = 2;

      lda = 3;

      ldb = 2;

      info = LAPACKE_dgels(LAPACK_ROW_MAJOR,'N',m,n,nrhs,*a,lda,*b,ldb);

      for(i=0;i<n;i++)

      {

          for(j=0;j<nrhs;j++)

          {

            printf("%lf ",b[i][j]);

          }

          printf("\n");

      }

      return(info);

    }

    gcc -c test2.c -o test2.o

    gcc test2.c -o test -llapacke -llapack -lcblas -lrefblas -lm -lgfortran

    编译遇到的问题:

    /usr/bin/ld: /datadisk1/liblocal/libblas.a(dtrsm.o): relocation

    R_X86_64_32 against `.rodata' can not be used when making a shared

    object; recompile with -fPIC

    一般指定库路径就行

    相关文章

      网友评论

          本文标题:linux中的编译理解

          本文链接:https://www.haomeiwen.com/subject/nsvpfjtx.html