Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
HDF-EOS:编译/链接错误c/c++;_C_Hdf - Fatal编程技术网

HDF-EOS:编译/链接错误c/c++;

HDF-EOS:编译/链接错误c/c++;,c,hdf,C,Hdf,我正在尝试编译一个使用HDF-EOS的示例程序。示例代码取自HDF-EOS(因此,我将仅发布顶部部分): 当然,我不止一次定义了main。在第二个抛出相同链接错误的示例程序中,我没有得到这个错误 因此,如果有人对第一个问题,即链接有想法,我会非常高兴 解决方案: 在中的compile语句末尾添加-lm,可删除链接问题 删除导致多个main问题的compile语句中的read_hdf_eos.c 感谢您的评论和提示。您检查过read_grid.c是否定义了另一个主功能吗?@MarcColl我检查过

我正在尝试编译一个使用HDF-EOS的示例程序。示例代码取自HDF-EOS(因此,我将仅发布顶部部分):

当然,我不止一次定义了
main
。在第二个抛出相同链接错误的示例程序中,我没有得到这个错误

因此,如果有人对第一个问题,即链接有想法,我会非常高兴

解决方案:

  • 在中的compile语句末尾添加-lm,可删除链接问题
  • 删除导致多个
    main
    问题的compile语句中的read_hdf_eos.c

  • 感谢您的评论和提示。

    您检查过read_grid.c是否定义了另一个主功能吗?@MarcColl我检查过了,没有。您可以在提供的链接中看到整个代码,我没有发布的部分是一些开场白和阅读语句,但不是另一个主要部分当您试图查找“未定义的sin引用”时,您得到了多少web搜索结果?你已经复习了多少呢?@n.m.好的,添加-lm解决了
    sin
    问题,现在只剩下main的多重定义了。谢谢。
    $(CC)阅读\u hdf\u eos.cpp$(CFLAGS).
    这个.cpp源代码在这里做什么?它也有main()吗?
    /* This example shows how to read a data field in HDF-EOS2 grid data. */
    
    #include <mfhdf.h>
    #include <hdf.h>
    #include <HdfEosDef.h>
    #include <stdio.h>
    #include <stdlib.h>
    
    int main(int argc, char **argv)
    {
        int32 gridfile1;
        int32 grid1;
        int32 datafield1rank;
        int32 datafield1dimsize[32];
        int32 datafield1type;
        char datafield1dimname[512];
        float32 *datafield1data;
        int32 i, j;
    
        /* Open 'AMSR_E_L3_RainGrid_B05_200707.hdf' using grid API */
        if ((gridfile1 = GDopen("AMSR_E_L3_RainGrid_B05_200707.hdf", DFACC_RDONLY)) == -1) {
            fprintf(stderr, "error: cannot open grid 'AMSR_E_L3_RainGrid_B05_200707.hdf'\n");
            return -1;
        }
    
    return 0;
    
    HDF4_DIR=<hdf4_path>
    HDFEOS2_DIR=<hdfeos2_path>
    
    CC=$(HDF4_DIR)/bin/h4cc
    
    CFLAGS=-I$(HDFEOS2_DIR)/include
    LDFLAGS=-L$(HDFEOS2_DIR)/lib
    LIBS=-lhdfeos -lGctp
    
    read_grid: read_grid.c
    $(CC) $(CFLAGS) $(LDFLAGS) $< $(LIBS) -o $@
    
    HDF4_DIR=<hdf4_path>
    HDFEOS2_DIR=<hdfeos2_path>
    HDF5_DIR=<hdf5_path>
    
    CC=$(HDF4_DIR)/bin/h4cc
    
    CFLAGS=-I$(HDFEOS2_DIR)/include -I$(HDF4_DIR)/include -I$(HDF5_DIR)/include
    LDFLAGS=-L$(HDFEOS2_DIR)/lib64 -L$(HDF4_DIR)/lib64 -L$(HDF5_DIR)/lib64
    LIBS=-lhdfeos -lGctp
    
    read_grid: read_grid.c
        $(CC) read_hdf_eos.c $(CFLAGS) $(LDFLAGS) $(LIBS) -o $@
    
    <hdfeos2_path>/lib64/libhdfeos.a(GDapi.o): In function `lamazDxDtheta':
    <hdfeos2_path>/src/GDapi.c:9579: undefined reference to `sin'
    <hdfeos2_path>/src/GDapi.c:9580: undefined reference to `sin'
    ...
    collect2: error: ld returned 1 exit status
    
    read_grid.o: In function `main':
    read_grid.c:(.text.startup+0x0): multiple definition of `main'
    read_grid.o:read_grid.c:(.text.startup+0x0): first defined here