linux中的编译理解

探序基因肿瘤研究院  整理


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

一般指定库路径就行

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容