【发布时间】:2014-02-05 16:54:24
【问题描述】:
我正在尝试编译以下程序(在 C++ 中使用 GDAL API):
main.cpp:
#include "gdal_priv.h"
#include "cpl_conv.h"
int main(int argc, char *argv[])
{
GDALAllRegister();
GDALDataset* data = (GDALDataset*) GDALOpen( "heightmap.tiff", GA_ReadOnly );
}
我在 Mac 上构建它的方式:
clang main.cpp -I/Library/Frameworks/GDAL.framework/Versions/1.10/unix/include
得到了这个:
clang main.cpp -I/Library/Frameworks/GDAL.framework/Versions/1.10/unix/include/
Undefined symbols for architecture x86_64:
"_GDALOpenShared", referenced from:
_main in test_gdal-QIB6MK.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
What's wrong with this very basic case?
【问题讨论】:
-
你需要链接到图书馆。我不知道它是怎么调用的,但是如果它是
gdal,那么命令行需要-lgdal -
好的,添加 -lgdal 实际上适用于 Linux,但不适用于 Mac。谢谢你。