如何正确链接libssh? [英] How do I properly link libssh?

查看:343
本文介绍了如何正确链接libssh?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试在我的代码(libssh)中包含一个lib,但没有任何效果...
此时我不确定该怎么办,因为搜索结果中没有错误提示我我正在接收。

I'm trying to include a lib into my code (libssh) but nothing works... At this point I'm unsure what to do as no results are popping up in search engines for the errors i'm recieving.

我在这里下载了libssh:
https://github.com/substack/libssh

I downloaded libssh here: https://github.com/substack/libssh

我安装了这些文件:

yum install cmake zlib-devel libpng-devel openssl-devel -y;

作为libssh的父目录创建一个 build目录,移至该目录,键入:

Created a "build" directory as parent of libssh, moved there, typed this:

cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Debug ..
make


[root@ build]# cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Debug LD_DEBUG=all ..
-- Could NOT find NaCl (missing:  NACL_LIBRARIES NACL_INCLUDE_DIRS)
-- ********************************************
-- ********** libssh build options : **********
-- zlib support: ON
-- libgcrypt support: OFF
-- libnacl support: OFF
-- SSH-1 support: OFF
-- SFTP support: ON
-- Server support : ON
-- GSSAPI support : ON
-- Pcap debugging support : ON
-- With static library: OFF
-- Unit testing: OFF
-- Client code Unit testing: OFF
-- Public API documentation generation
-- Benchmarks: OFF
-- ********************************************
-- Configuring done
-- Generating done
-- Build files have been written to: /root/libssh/build

然后失败...

Scanning dependencies of target exec
[  2%] Building C object examples/CMakeFiles/exec.dir/exec.c.o
[  5%] Building C object examples/CMakeFiles/exec.dir/authentication.c.o
[  8%] Building C object examples/CMakeFiles/exec.dir/knownhosts.c.o
[ 11%] Building C object examples/CMakeFiles/exec.dir/connect_ssh.c.o
Linking C executable exec
/usr/bin/ld: cannot find -lssh_shared
collect2: ld a retourné 1 code d'état d'exécution
make[2]: *** [examples/exec] Erreur 1
make[1]: *** [examples/CMakeFiles/exec.dir/all] Erreur 2
make: *** [all] Erreur 2

有人知道是什么问题吗? 找不到-lssh_shared显示与Google无关。

Anyone know what the problem is? "cannot find -lssh_shared" showed me nothing related on google.

推荐答案

错误消息是由链接器<$ c $引起的c> / usr / bin / ld 在编译时无法链接到库 ssh_shared.so

The error message is resulted from the linker /usr/bin/ld is failed to link to the library ssh_shared.so while compiling.

我检查了文件 libssh / build / src / CMakeFiles / ssh_shared.dir / build.make ,在内部链接消息:

I checked the file libssh/build/src/CMakeFiles/ssh_shared.dir/build.make, there's some linking messages inside:

ssh_shared_EXTERNAL_OBJECTS =
src/libssh.so.4.2.0: /usr/lib/x86_64-linux-gnu/libz.so
src/libssh.so.4.2.0: /usr/lib/x86_64-linux-gnu/libssl.so
src/libssh.so.4.2.0: /usr/lib/x86_64-linux-gnu/libcrypto.so

... (snippet here) ...
src/libssh.so.4.2.0: src/CMakeFiles/ssh_shared.dir/bind.c.o
src/libssh.so.4.2.0: /usr/lib/x86_64-linux-gnu/libz.so
src/libssh.so.4.2.0: /usr/lib/x86_64-linux-gnu/libssl.so
src/libssh.so.4.2.0: /usr/lib/x86_64-linux-gnu/libcrypto.so
src/libssh.so.4.2.0: src/CMakeFiles/ssh_shared.dir/build.make
src/libssh.so.4.2.0: src/CMakeFiles/ssh_shared.dir/link.txt

@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --red --bold "Linking C shared library libssh.so"

您会注意到在构建过程中s, cmake 会尝试在我的系统路径 / usr / lib / x86_64-linux-gnu / 下链接某些库。然后去检查你的。

You can notice that during the build process, cmake would try to link some libraries under my system path /usr/lib/x86_64-linux-gnu/. And go to check yours.

这篇关于如何正确链接libssh?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆