我在使用 gdal 时遇到了问题。我目前正在使用 Ubuntu,IDE 是 Eclipse CDT,我在下面给出了我的代码,并且还安装了 gdal 包,但它给出了构建错误
#include <stdio.h>
#include<unistd.h>
#include "gdal/gdal_priv.h"
#include "gdal/cpl_conv.h"
#include<gdal/gdal.h>
int main(int argc,char* argv[])
{
void *hLib_Comm;
char exePath[800];
if(getcwd(exePath,sizeof(exePath))== NULL) {
printf("Exe path access error\n");
}
GDALDataset *poDataset;
GDALAllRegister();
poDataset = (GDALDataset *) GDALOpen( exePath, GA_ReadOnly );
if( poDataset == NULL )
{
printf("Exe path access error\n");
}
}
////////////构建结果/////////////////////////////////////////
14:51:47 **** Build of configuration Debug for project ReadFrmSoFile ****
make all
Building file: ../main.cpp
Invoking: GCC C++ Compiler
g++ -lm -I/usr/include/gdal -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"main.d" -MT"main.d" -o "main.o" "../main.cpp"
../main.cpp: In function ‘int main(int, char**)’:
../main.cpp:17:8: warning: unused variable ‘hLib_Comm’ [-Wunused-variable]
Finished building: ../main.cpp
Building target: ReadFrmSoFile
Invoking: GCC C++ Linker
g++ -lm -L/usr/lib -L/usr/lib/ogdi -o "ReadFrmSoFile" ./main.o -lgdal
./main.o: In function `main':
/media/Local Disk/workspace2/ReadFrmSoFile/Debug/../main.cpp:24: undefined reference to `GDALAllRegister'
/media/Local Disk/workspace2/ReadFrmSoFile/Debug/../main.cpp:26: undefined reference to `GDALOpen'
collect2: ld returned 1 exit status
make: *** [ReadFrmSoFile] Error 1
帮我.....
答案1
根据这你没有build-essentials
安装该软件包。只需运行以下命令即可解决此问题:
sudo apt-get install build-essential
我尝试运行你的代码,但是由于一些标题依赖关系而遇到了另一个问题:
gcc gdal.c
In file included from gdal.c:3:0:
/usr/include/gdal/gdal_priv.h:38:1: error: unknown type name ‘class’
class GDALMajorObject;
^
/usr/include/gdal/gdal_priv.h:39:1: error: unknown type name ‘class’
class GDALDataset;
^
/usr/include/gdal/gdal_priv.h:40:1: error: unknown type name ‘class’
class GDALRasterBand;
^
/usr/include/gdal/gdal_priv.h:41:1: error: unknown type name ‘class’
class GDALDriver;
^
/usr/include/gdal/gdal_priv.h:42:1: error: unknown type name ‘class’
class GDALRasterAttributeTable;
^
/usr/include/gdal/gdal_priv.h:43:1: error: unknown type name ‘class’
class GDALProxyDataset;
^
/usr/include/gdal/gdal_priv.h:44:1: error: unknown type name ‘class’
class GDALProxyRasterBand;
^
/usr/include/gdal/gdal_priv.h:45:1: error: unknown type name ‘class’
class GDALAsyncReader;
^
In file included from gdal.c:3:0:
/usr/include/gdal/gdal_priv.h:59:18: fatal error: vector: No such file or directory
#include <vector>
^
compilation terminated.