2017-04-01 17 views
1

HDF5 종속성이있는 코드를 컴파일하고 실행하려는 특정 요구 사항이 있습니다. hdf5 compiler을 사용하고 싶지 않지만 HDF5 소스 코드를 컴파일하고 싶습니다.HDF5 소스 코드로 C 프로그램을 컴파일하는 방법은 무엇입니까?

저는 C 프로그램에 HDF5를 연결하는 방법이 매우 새롭습니다. 어떻게하면 C 컴파일러를 사용하여이 프로그램을 실행하고 here에서 다운로드 한 소스 파일을 링크 할 수 있는지 자세히 설명해주십시오.

샘플 C 프로그램 - 컴파일

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
* Copyright by The HDF Group.            * 
* Copyright by the Board of Trustees of the University of Illinois.   * 
* All rights reserved.              * 
*                   * 
* This file is part of HDF5. The full HDF5 copyright notice, including  * 
* terms governing use, modification, and redistribution, is contained in * 
* the files COPYING and Copyright.html. COPYING can be found at the root * 
* of the source code distribution tree; Copyright.html can be found at the * 
* root level of an installed copy of the electronic HDF5 document set and * 
* is linked from the top-level documents page. It can also be found at  * 
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have   * 
* access to either file, you may request a copy from [email protected]  * 
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 

/* 
* This example illustrates how to create a dataset that is a 4 x 6 
* array. It is used in the HDF5 Tutorial. 
*/ 

#include "hdf5.h" 
#define FILE "dset.h5" 

int main() { 

    hid_t  file_id, dataset_id, dataspace_id; /* identifiers */ 
    hsize_t  dims[2]; 
    herr_t  status; 

    /* Create a new file using default properties. */ 
    file_id = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); 

    /* Create the data space for the dataset. */ 
    dims[0] = 4; 
    dims[1] = 6; 
    dataspace_id = H5Screate_simple(2, dims, NULL); 

    /* Create the dataset. */ 
    dataset_id = H5Dcreate2(file_id, "/dset", H5T_STD_I32BE, dataspace_id, 
          H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); 

    /* End access to the dataset and release resources used by it. */ 
    status = H5Dclose(dataset_id); 

    /* Terminate access to the data space. */ 
    status = H5Sclose(dataspace_id); 

    /* Close the file. */ 
    status = H5Fclose(file_id); 
} 

답변

2

, HDF5의 include 디렉토리에 -I 플래그 지점이 필요하다. 시스템 설치의 경우 일반적으로 /usr/include이지만 HDF5가 직렬 또는 병렬, 32/64 비트 등으로 설치되는지 여부에 따라 많은 변형이 있습니다. -L-l 플래그를 연결하는 것이 중요합니다. -L이 HDF5 라이브러리의 .so, .dll 또는 .dylib 파일을 보유하는 디렉토리를 지정해야합니다 (다시, 변동이있을 수있다)와 -l는 단순히 라이브러리 이름, -lhdf5 등 (나는 -lz-lm 거의 항상 사용 있다고 생각) 제공합니다. 상위 라이브러리를 사용하는 경우 -lhdf5_hl이 필요합니다.

그 플래그를 확인하는 가장 간단한 방법은 그들 모두를 나열합니다 그

h5cc -show 

를 호출하는 것입니다.

PS : 컴파일하고 (실행 파일 .c에서) 하나의 단계에 링크하거나 먼저 컴파일 (.o-.c) (실행 파일 .o) 링크. 첫 번째 경우에는 모두 -I, -L-l 플래그가 필요합니다.