首页 > 解决方案 > 如何在 Qt 中使用 GeographicLib

问题描述

嗨,我是 qt 和 CMake 的新手,这可能是一个简单的解决方法,但我整天都在努力解决它。

我正在尝试在 Qt 项目中使用GeographicLib 。我安装了 CMake 并从https://geographiclib.sourceforge.io/html/intro.html下载了文件。在 Geographiclib 网站上,有一个构建用于 Qt 的库的指南。您必须运行几个命令:

 export PATH="`cygpath -m c:/QtSDK/mingw/bin`:$PATH"
 mkdir BUILD
 cd BUILD
 cmake -G "MinGW Makefiles" -D CMAKE_INSTALL_PREFIX="C:/Program Files/GeographicLib" ..
 mingw32-make
 mingw32-make install

运行上述内容后,我得到以下信息:

C:\Users\koos>  export PATH="`cygpath -m c:/QtSDK/mingw/bin`:$PATH"
'export' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\koos>  mkdir BUILD
A subdirectory or file BUILD already exists.

C:\Users\koos>  cd BUILD

C:\Users\koos\BUILD>  cmake -G "MinGW Makefiles" -D CMAKE_INSTALL_PREFIX="C:/Program 
Files/GeographicLib" ..
CMake Error: The source directory "C:/Users/koos" does not appear to contain CMakeLists.txt.
Specify --help for usage, or press the help button on the CMake GUI.

该网站说,如果 cmake 抱怨你必须运行以下命令:

env PATH="$( echo $PATH | tr : '\n' |
while read d; do test -f "$d/sh.exe" || echo -n "$d:"; done |
sed 's/:$//' )" \
cmake -G "MinGW Makefiles" -D CMAKE_INSTALL_PREFIX="C:/Program Files/GeographicLib" ..

然后我得到:

C:\Users\koos\BUILD>  env PATH="$( echo $PATH | tr : '\n' |
'env' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\koos\BUILD>  while read d; do test -f "$d/sh.exe" || echo -n "$d:"; done |
The syntax of the command is incorrect.

C:\Users\koos\BUILD>  sed 's/:$//' )" \
'sed' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\koos\BUILD>  cmake -G "MinGW Makefiles" -D CMAKE_INSTALL_PREFIX="C:/Program 
Files/GeographicLib" ..

我正在使用 Desktop Qt 13.0 MinGw 64 位。我认为以下内容存在问题:“mingw32-make”(是 32 而不是 64,但我尝试更改它但没有找到)。有人可以向我解释一下我应该如何在 Qt 中安装 Geographic lib 库(也许如何使用 cmake qui 来完成任务,因为我对 cmake 不太了解)

编辑 :

所以我安装了cygwin,现在它给了我以下信息:

koos@computer ~
$   mkdir BUILD
export PATH="`cygpath -m C:\Qt\Tools\mingw730_64\bin`:$PATH"
  cd BUILD
  cmake -G "MinGW Makefiles" -D CMAKE_INSTALL_PREFIX="C:/Program 
Files/GeographicLib" ..
 mingw32-make
mingw32-make install
koos@computer ~
$   mkdir BUILD

koos@computer ~
$   cd BUILD

koos@computer ~/BUILD
$   cmake -G "MinGW Makefiles" -D CMAKE_INSTALL_PREFIX="C:/Program 
Files/GeographicLib" ..
CMake Error: The source directory "C:/cygwin64/home/koos" does not appear 
to contain CMakeLists.txt.
Specify --help for usage, or press the help button on the CMake GUI.

koos@computer ~/BUILD
$   mingw32-make
-bash: mingw32-make: command not found

koos@computer ~/BUILD
$   mingw32-make install
-bash: mingw32-make: command not found

从 GeographicLib 的顶级目录运行后,出现以下错误:

CMake Error: CMake was unable to find a build program corresponding to 
"MinGW Makefiles".  CMAKE_MAKE_PROGRAM is not set.  You probably need to 
select a different build tool.
CMake Error: CMake was unable to find a build program corresponding to 
"MinGW Makefiles".  CMAKE_MAKE_PROGRAM is not set.  You probably need to 
select a different build tool.
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!

该路径C:\Qt\Tools\mingw730_64\bin确实包含 mingw32-make。

谢谢你的耐心!

问候库斯

标签: c++qtcmakegeographic-lib

解决方案


GeographicLib 站点的说明说要使用 Cygwin 运行命令:

如果您在 Windows 上为 Qt 使用 mingw 编译器,那么您需要使用 mingw 构建 GeographicLib。您可以在 cygwin 下使用 cmake 完成此操作,例如...

exportenv和等命令sed不是 Windows 原生的,而是 Linux 命令。这些必须在 Cygwin 命令提示符下运行。你的问题没有在你的设置中提到 Cygwin,所以我猜你要么没有安装它,要么没有使用它。尝试为您的机器安装Cygwin并从 Cygwin 命令提示符中运行列出的命令。

这些说明假定您正在从GeographicLib 包的顶级目录运行命令,因此您必须先导航到该目录。更新后的命令如下所示:

 cd C:/path/to/your/GeographicLib
 export PATH="`cygpath -m c:/QtSDK/mingw/bin`:$PATH"
 mkdir BUILD
 cd BUILD
 cmake -G "MinGW Makefiles" -D CMAKE_INSTALL_PREFIX="C:/Program Files/GeographicLib" ..
 mingw32-make
 mingw32-make install

推荐阅读