我已经安装了 Proj 6.3.1,并尝试从 https://proj.org/development/quickstart.html 运行 Proj 示例。我在 Ubuntu 20.04 上使用 CLion 实现了它。我得到了许多未定义的参考错误,如下所示,
cd "/path_to_the_file/" && g++ transformation.cpp -o transformation && "/path_to_the_file/"transformation
/usr/bin/ld: /tmp/cckO2X58.o: in function `main':
transformation.cpp:(.text+0x1f): undefined reference to `proj_context_create'
/usr/bin/ld: transformation.cpp:(.text+0x42): undefined reference to `proj_create_crs_to_crs'
/usr/bin/ld: transformation.cpp:(.text+0x8a): undefined reference to `proj_normalize_for_visualization'
/usr/bin/ld: transformation.cpp:(.text+0xcb): undefined reference to `proj_destroy'
/usr/bin/ld: transformation.cpp:(.text+0x102): undefined reference to `proj_coord'
/usr/bin/ld: transformation.cpp:(.text+0x14f): undefined reference to `proj_trans'
/usr/bin/ld: transformation.cpp:(.text+0x1c3): undefined reference to `proj_trans'
/usr/bin/ld: transformation.cpp:(.text+0x21c): undefined reference to `proj_destroy'
/usr/bin/ld: transformation.cpp:(.text+0x228): undefined reference to `proj_context_destroy'
collect2: error: ld returned 1 exit status
这个问题类似于https://gis.stackexchange.com/questions/370771/unable-to-run-proj-c-example,但我找不到相应的解决方案。
执行你的建议后我仍然遇到一些错误:
$ g++ try_proj.cpp -lproj /usr/bin/ld: /tmp/ccmz7Q0R.o: 在函数
main': try_proj.cpp:(.text+0x2ed): undefined reference to
osgeo::proj::operation::CooperativeOperation::coordinateTransformer(pj_ctx*) const' 中
/usr/bin/ld: try_proj.cpp:(.text+0x37c): 对 osgeo::proj::operation::CoordinateTransformer::transform(PJ_COORD)' /usr/bin/ld: /tmp/ccmz7Q0R.o: in function
std::default_deleteosgeo::proj::operation::CooperativeTransformer::operator()(osgeo::proj::operation 的未定义引用::坐标转换器*) const':
try_proj.cpp:(.text.ZNKSt14default_deleteIN5osgeo4proj9operation21CooperativeTransformerEEclEPS3[ZNKSt14default_deleteIN5osgeo4proj9operation21CooperativeTransformerEEclEPS3]+0x22):对`osgeo::proj::操作::CooperativeTransformer::~CooperativeTrans的未定义引用前()'
收集2:错误:ld返回1退出状态
我通过命令安装了 proj 8.2 :sudo apt-get install proj-bin 我还从源代码安装了版本 9.3.1。这会产生问题吗?