小编hba*_*osa的帖子

如何在ubuntu中静态链接netcdf程序

我正在尝试使用netcdf库和g ++静态链接一个非常简单的程序。该程序如下所示:

#include "netcdf.h"
int main(void)
{
  int ncid, ok;
  ok=nc_create("testing.nc", NC_NOCLOBBER, &ncid);
  ok=nc_close(ncid);
  return(0);
}
Run Code Online (Sandbox Code Playgroud)

如果我像这样编译它,效果很好:

> g++ test.cpp -lnetcdf
Run Code Online (Sandbox Code Playgroud)

但是,如果我尝试静态编译它,那么一切都会中断:

> g++ -static test.cpp -lnetcdf
/usr/lib64/libnetcdf.a(nc4file.o): In function `sync_netcdf4_file':
(.text+0x5a): undefined reference to `H5Fflush'
/usr/lib64/libnetcdf.a(nc4file.o): In function `close_netcdf4_file':
(.text+0x11b): undefined reference to `H5Fclose'
/usr/lib64/libnetcdf.a(nc4file.o): In function `get_netcdf_type':
(.text+0x18b): undefined reference to `H5Tget_class'
/usr/lib64/libnetcdf.a(nc4file.o): In function `get_netcdf_type':
(.text+0x1e9): undefined reference to `H5Tis_variable_str'
(...)
Run Code Online (Sandbox Code Playgroud)

许多抱怨,但第一个是针对hdf5。在寻找答案时,我 unidata上找到了该页面该页面解释了应该与hdf5和其他库链接的地方。所以我尝试了:

> g++ -static test.cpp -lnetcdf -lhdf5_hl -lhdf5 -lz -lm 
/usr/lib64/libnetcdf.a(liboc_la-ocinternal.o): In …
Run Code Online (Sandbox Code Playgroud)

ubuntu static g++ build netcdf

5
推荐指数
0
解决办法
1189
查看次数

标签 统计

build ×1

g++ ×1

netcdf ×1

static ×1

ubuntu ×1