使用 make install 安装 libssh build 时出错

Error when installing libssh build with make install

OS 和 CMake 史前史

我正在尝试在 Debian GNU/Linux 9.5 上安装libssh。我已经使用 cmake 成功构建了 libssh 源代码,并将所有内容放入我按照安装手册中的建议创建的 build 目录中。 (请注意,我没有使用 zlib 构建源,因为它只是可选的)注意:使用 cmake 构建源时没有错误。

Install Manual of libssh

问题:安装错误

安装手册现在提示您通过 运行

安装 libssh

make install

build 目录中。现在,如果我这样做,我会收到以下错误消息:

[ 84%] Linking CXX executable libsshpp_noexcept
CMakeFiles/libsshpp_noexcept.dir/libsshpp_noexcept.cpp.o: In function `main':
libsshpp_noexcept.cpp:(.text+0xb2): undefined reference to `std::cout'
libsshpp_noexcept.cpp:(.text+0xb7): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
libsshpp_noexcept.cpp:(.text+0xcd): undefined reference to `std::cout'
libsshpp_noexcept.cpp:(.text+0xd2): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
libsshpp_noexcept.cpp:(.text+0xdc): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
libsshpp_noexcept.cpp:(.text+0xe7): undefined reference to `std::ostream::operator<<(std::ostream& (*)(std::ostream&))'
CMakeFiles/libsshpp_noexcept.dir/libsshpp_noexcept.cpp.o: In function `__static_initialization_and_destruction_0(int, int)':
libsshpp_noexcept.cpp:(.text+0x163): undefined reference to `std::ios_base::Init::Init()'
 libsshpp_noexcept.cpp:(.text+0x178): undefined reference to `std::ios_base::Init::~Init()'
 CMakeFiles/libsshpp_noexcept.dir/libsshpp_noexcept.cpp.o:(.data.DW.ref.__gxx_personality_v0[DW.ref.__gxx_personality_v0]+0x0): undefined reference to `__gxx_personality_v0'
collect2: error: ld returned 1 exit status
examples/CMakeFiles/libsshpp_noexcept.dir/build.make:96: recipe for target 'examples/libsshpp_noexcept' failed
make[2]: *** [examples/libsshpp_noexcept] Error 1
CMakeFiles/Makefile2:431: recipe for target 'examples/CMakeFiles/libsshpp_noexcept.dir/all' failed
make[1]: *** [examples/CMakeFiles/libsshpp_noexcept.dir/all] Error 2
Makefile:149: recipe for target 'all' failed
make: *** [all] Error 2

是什么导致了这个问题,我该如何解决?

libssh 构建在 ../libssh/build/examples 中有一些关于如何使用该库的示例文件。如果您想使用 make install 安装 libssh,../libssh/build/CMakeFiles 中的 Makefile2 已指定示例文件也与您的安装一起编译。现在的问题是这些示例文件内部有一些错误,这就是为什么 libssh 的 compilation/installation 解决了上述问题中所述的错误。

现在要解决此问题,您必须删除 ../libssh/build/examples/CMakeFiles 文件夹中的 libsshpp_noexcept.dirlibsshpp.dir。为了安装成功,您还必须删除 Makefile2(在 ../libssh/build/CMakeFiles 内)中负责编译这两个示例文件的相应代码行。在您首选的文本编辑器中打开 Makefile2 并在文件中搜索 examples/CMakeFiles/libsshpp_noexcept.dir/buildexamples/CMakeFiles/libsshpp.dir/build。您现在必须删除检查和 installs/compiles 这两个 files/dirs 的所有内容。我删除了以下部分:

#==================================================

delete everything inside here

...

#==================================================

通过删除分隔符中的内容,您删除了 libssh 提供的两个(不是必需的)示例文件的 installing/compilation 过程。

现在 运行 make install 进入 ../libssh/build,你应该可以开始了。