2012-08-01 3 views
0

편집 : GRIB 파일을 사용하여 작업 할 경우 Open Source Geospatial Foundation이 뒷받침되는 GDAL library을 권장합니다. 당신은 많은 두통을 덜어 줄 것입니다 :C++ 응용 프로그램에서 libgrib2c를 사용하면 링커 오류 "정의되지 않은 참조 ..."

저는 우분투에서 Q ++ 크리에이터를 사용하여 C++ 응용 프로그램을 만들고 있습니다. 외부 lib libgrib2c.a를 사용하려고하는데, 헤더 grib2.h가 있습니다. 모든 컴파일하지만 연결을 시도 할 때 나는 오류 얻을 : 내가 가진 헤더 파일을 포장 시도

undefined reference to 'seekgb(_IO_FILE*, long, long, long*, long*)

:

extern "C"{ 
#include "grib2.h" 
} 

을하지만 생각 그래서 아무것도 해결되지 않았다 아니었다 내 문제. .PRO 파일에서 나는 라인이 있습니다

include($${ROOT}/Shared/common/commonLibs.pri) 

및 commonLibs.pri에서 내가 가진 :

INCLUDEPATH+=$${ROOT}/external_libs/g2clib/include 
LIBS+=-L$${ROOT}/external_libs/g2clib/lib 
LIBS+=-lgrib2c 

내가 도서관을 찾는 오류가 발생하고 있지 않다.

nm libgrib2c.a | grep seekgb 
seekgb.o: 
00000000 T seekgb 

을 내가 LIBS의 추가 인수를 qmake를 실행하면 + = - W1 내지는 - 자세한 I 출력에서 ​​LIB 파일을 찾을 수 있습니다 : 나는 libgrib2c.a에 나노 명령을 할 경우 내가 얻을

attempt to open /usr/lib/libgrib2c.so failed 
attempt to open /usr/lib/libgrib2c.a failed 
attempt to open /mnt/sdb1/ESMF/App/ESMF_App/../external_libs/linux/qwt_6.0.2/lib/libgrib2c.so failed 
attempt to open /mnt/sdb1/ESMF/App/ESMF_App/../external_libs/linux/qwt_6.0.2/lib/libgrib2c.a failed 
attempt to open ..//Shared/Config/lib/libgrib2c.so failed 
attempt to open ..//Shared/Config/lib/libgrib2c.a failed 
attempt to open ..//external_libs/libssh2/lib/libgrib2c.so failed 
attempt to open ..//external_libs/libssh2/lib/libgrib2c.a failed 
attempt to open ..//external_libs/openssl/lib/libgrib2c.so failed 
attempt to open ..//external_libs/openssl/lib/libgrib2c.a failed 
attempt to open ..//external_libs/g2clib/lib/libgrib2c.so failed 
attempt to open ..//external_libs/g2clib/lib/libgrib2c.a succeeded 

내 C++ 응용 프로그램의 ac 라이브러리이기 때문에 라이브러리의 .o 파일이 보이지 않지만 어떻게됩니까?

#ifndef _grib2_H 
#define _grib2_H 
#include<stdio.h> 

#define G2_VERSION "g2clib-1.4.0" 
#ifdef __64BIT__ 
typedef int g2int; 
typedef unsigned int g2intu; 
#else 
typedef long g2int; 
typedef unsigned long g2intu; 
#endif 
typedef float g2float; 

struct gtemplate { 
    g2int type;   /* 3=Grid Defintion Template.      */ 
         /* 4=Product Defintion Template.     */ 
         /* 5=Data Representation Template.     */ 
    g2int num;   /* template number.         */ 
    g2int maplen;   /* number of entries in the static part    */ 
         /*     of the template.    */ 
    g2int *map;   /* num of octets of each entry in the    */ 
         /*   static part of the template.    */ 
    g2int needext;  /* indicates whether or not the template needs  */ 
         /*  to be extended.        */ 
    g2int extlen;   /* number of entries in the template extension.  */ 
    g2int *ext;   /* num of octets of each entry in the extension  */ 
         /*      part of the template.  */ 
}; 

typedef struct gtemplate gtemplate; 

struct gribfield { 
    g2int version,discipline; 
    g2int *idsect; 
    g2int idsectlen; 
    unsigned char *local; 
    g2int locallen; 
    g2int ifldnum; 
    g2int griddef,ngrdpts; 
    g2int numoct_opt,interp_opt,num_opt; 
    g2int *list_opt; 
    g2int igdtnum,igdtlen; 
    g2int *igdtmpl; 
    g2int ipdtnum,ipdtlen; 
    g2int *ipdtmpl; 
    g2int num_coord; 
    g2float *coord_list; 
    g2int ndpts,idrtnum,idrtlen; 
    g2int *idrtmpl; 
    g2int unpacked; 
    g2int expanded; 
    g2int ibmap; 
    g2int *bmap; 
    g2float *fld; 
}; 

typedef struct gribfield gribfield; 


/* Prototypes for unpacking API */ 
void seekgb(FILE *,g2int ,g2int ,g2int *,g2int *); 
g2int g2_info(unsigned char *,g2int *,g2int *,g2int *,g2int *); 
g2int g2_getfld(unsigned char *,g2int ,g2int ,g2int ,gribfield **); 
void g2_free(gribfield *); 

/* Prototypes for packing API */ 
g2int g2_create(unsigned char *,g2int *,g2int *); 
g2int g2_addlocal(unsigned char *,unsigned char *,g2int); 
g2int g2_addgrid(unsigned char *,g2int *,g2int *,g2int *,g2int); 
g2int g2_addfield(unsigned char *,g2int ,g2int *, 
         g2float *,g2int ,g2int ,g2int *, 
         g2float *,g2int ,g2int ,g2int *); 
g2int g2_gribend(unsigned char *); 

/* Prototypes for supporting routines */ 
extern double int_power(double, g2int); 
extern void mkieee(g2float *,g2int *,g2int); 
void rdieee(g2int *,g2float *,g2int); 
extern gtemplate *getpdstemplate(g2int); 
extern gtemplate *extpdstemplate(g2int,g2int *); 
extern gtemplate *getdrstemplate(g2int); 
extern gtemplate *extdrstemplate(g2int,g2int *); 
extern gtemplate *getgridtemplate(g2int); 
extern gtemplate *extgridtemplate(g2int,g2int *); 
extern void simpack(g2float *,g2int,g2int *,unsigned char *,g2int *); 
extern void compack(g2float *,g2int,g2int,g2int *,unsigned char *,g2int *); 
void misspack(g2float *,g2int ,g2int ,g2int *, unsigned char *, g2int *); 
void gbit(unsigned char *,g2int *,g2int ,g2int); 
void sbit(unsigned char *,g2int *,g2int ,g2int); 
void gbits(unsigned char *,g2int *,g2int ,g2int ,g2int ,g2int); 
void sbits(unsigned char *,g2int *,g2int ,g2int ,g2int ,g2int); 

int pack_gp(g2int *, g2int *, g2int *, 
      g2int *, g2int *, g2int *, g2int *, g2int *, 
      g2int *, g2int *, g2int *, g2int *, 
      g2int *, g2int *, g2int *, g2int *, g2int *, 
      g2int *, g2int *, g2int *); 

#endif /* _grib2_H */ 

것은 내 머리를 긁적있다 : 내가 가지고있는 라이브러리를 사용하는 것을 시도하고있다 .cpp 파일에

다음과 같이

#include "gribreader.h" 
#include <stdio.h> 
#include <stdlib.h> 
#include <external_libs/g2clib/include/grib2.h> 
#include <Shared/logging/Logger.hpp> 

//------------------------------------------------------------------------------ 
/// Opens a GRIB file from disk. 
/// 
/// This function opens the grib file and searches through it for how many GRIB 
/// messages are contained as well as their starting locations. 
/// 
/// \param a_filePath. The path to the file to be opened. 
/// \return True if successful, false if not. 
//------------------------------------------------------------------------------ 
bool GRIBReader::OpenGRIB(std::string a_filePath) 
{ 
    LOG(notification)<<"Attempting to open grib file: "<< a_filePath; 
    if(isOpen()) 
    { 
    CloseGRIB(); 
    } 
    m_filePath = a_filePath; 
    m_filePtr = fopen(a_filePath.c_str(), "r"); 

    if(m_filePtr == NULL) 
    { 
    LOG(error)<<"Unable to open file: " << a_filePath; 
    return false; 
    } 
    LOG(notification)<<"Successfully opened GRIB file"; 

    g2int currentMessageSize(1); 
    g2int seekPosition(0); 
    g2int lengthToBeginningOfGrib(0); 
    g2int seekLength(32000); 
    int i(0); 
    int iterationLimit(300); 
    m_GRIBMessageLocations.clear(); 
    m_GRIBMessageSizes.clear(); 
    while(i < iterationLimit) 
    { 
    seekgb(m_filePtr, seekPosition, seekLength, 
      &lengthToBeginningOfGrib, &currentMessageSize); 
    if(currentMessageSize != 0) 
    { 
     LOG(verbose) << "Adding GRIB message location " << lengthToBeginningOfGrib 
        << " with length " << currentMessageSize; 
     m_GRIBMessageLocations.push_back(lengthToBeginningOfGrib); 
     m_GRIBMessageSizes.push_back(currentMessageSize); 

     seekPosition = lengthToBeginningOfGrib + currentMessageSize; 
     LOG(verbose) << "GRIB seek position moved to " << seekPosition; 
    } 
    else 
    { 
     LOG(notification)<<"End of GRIB file found, after "<< i 
         << " GRIB messages."; 
     break; 
    } 
    } 
    if(i >= iterationLimit) 
    { 
    LOG(warning) << "The iteration limit of " << iterationLimit 
       << "was reached while searching for GRIB messages"; 
    } 
    return true; 
} 

을 그리고 헤더 grib2.h입니다 이것에 2 일 동안. 누구나 할 일에 대한 아이디어가 있거나 어떤 방향으로 나를 지적 할 수 있다면, 나는 혼란 스럽다. 또한이 게시물을 개선 할 수있는 방법에 대한 의견이 있으시면 해당 소식을 듣고 싶습니다. 대개 웹에 이미 들어있는 지식의 광대 한 매장에서 답변을 찾을 수 있습니다.

답변

1

은 헤더 파일의 상단에 다음을 넣어 명시 적으로 외부 C 결합을 지정하십시오 :

#ifdef __cplusplus 
extern "C" { 
#endif 

과 하단이 : 작동

#ifdef __cplusplus 
} 
#endif 
+0

을! 그것은 헤더 파일 주위에 extern "C"를 두는 것과 같은 이유는 모르겠지만. Meh, 나는 그것을 가져갈 것이다. – enriched

관련 문제