Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linker LIBSSH2和dso_dlfcn.c:。。。对“dlopen'”的未定义引用;_Linker_Openssl_Static Linking_Libgit2_Libssh2 - Fatal编程技术网

Linker LIBSSH2和dso_dlfcn.c:。。。对“dlopen'”的未定义引用;

Linker LIBSSH2和dso_dlfcn.c:。。。对“dlopen'”的未定义引用;,linker,openssl,static-linking,libgit2,libssh2,Linker,Openssl,Static Linking,Libgit2,Libssh2,我正在尝试使用静态libgit2、openssl和libssh2编译git2go。我的最终目标是能够编译一个go二进制文件,无需安装这些库即可进行部署。我在上找到了一个类似的脚本,因此我使用它来创建以下构建库的脚本 OPENSSL: #!/bin/sh set -ex INSTALL_PATH="$PWD/install" SUBMODULE_PATH="$PWD/submodules/openssl" cd $SUBMODULE_PATH && mkdir -p $INST

我正在尝试使用静态
libgit2
openssl
libssh2
编译
git2go
。我的最终目标是能够编译一个
go
二进制文件,无需安装这些库即可进行部署。我在上找到了一个类似的脚本,因此我使用它来创建以下构建库的脚本

OPENSSL:

#!/bin/sh

set -ex
INSTALL_PATH="$PWD/install"
SUBMODULE_PATH="$PWD/submodules/openssl"

cd $SUBMODULE_PATH &&
mkdir -p $INSTALL_PATH/lib &&
mkdir -p build &&

# Switch to a stable version
git checkout OpenSSL_1_0_2-stable &&
./config threads no-shared --prefix=$INSTALL_PATH -fPIC -DOPENSSL_PIC &&
make depend &&
make &&
make install
LIBSSH2:

#!/bin/sh

set -ex

INSTALL_PATH="$PWD/install"
SUBMODULE_PATH="$PWD/submodules/libssh2"

# without this, the system's openssl shared object gets linked in
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:$INSTALL_PATH/lib/pkgconfig:$INSTALL_PATH/lib64/pkgconfig"

cd $SUBMODULE_PATH &&
mkdir -p $INSTALL_PATH/lib &&
mkdir build
cd build &&
cmake -DTHREADSAFE=ON \
      -DBUILD_CLAR=OFF \
      -DBUILD_SHARED_LIBS=OFF \
      -DCMAKE_C_FLAGS=-fPIC \
      -DCMAKE_BUILD_TYPE="RelWithDebInfo" \
      -DCMAKE_INSTALL_PREFIX=$INSTALL_PATH \
      .. &&

cmake --build .
make install
我将以下补丁应用于
git2go
branch
next
中构建
libgit2
的脚本,以确保
PKG\u CONFIG\u路径
指向静态
openssl
libssh2

LIBGIT2:

--- build-libgit2-static.sh.orig    2016-04-14 22:49:53.000000000 -0700
+++ build-libgit2-static.sh 2016-04-14 22:52:04.000000000 -0700
@@ -2,10 +2,12 @@

 set -ex

-VENDORED_PATH=vendor/libgit2
+INSTALL_PATH="$PWD/install"
+VENDORED_PATH="$PWD/submodules/git2go/vendor/libgit2"
+export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:$INSTALL_PATH/lib/pkgconfig:$INSTALL_PATH/lib64/pkgconfig"

 cd $VENDORED_PATH &&
-mkdir -p install/lib &&
+mkdir -p $INSTALL_PATH/lib &&
 mkdir -p build &&
 cd build &&
 cmake -DTHREADSAFE=ON \
@@ -13,7 +15,8 @@
       -DBUILD_SHARED_LIBS=OFF \
       -DCMAKE_C_FLAGS=-fPIC \
       -DCMAKE_BUILD_TYPE="RelWithDebInfo" \
-      -DCMAKE_INSTALL_PREFIX=../install \
+      -DCMAKE_INSTALL_PREFIX=$INSTALL_PATH \
       .. &&

 cmake --build .
+make install
此安装程序最终创建一个本地
install
目录,其中安装了所有库。我使用上述脚本编译
openssl
。然后在编译
libssh2
时获得以下输出:

...
Found OpenSSL: (path to project)/install/lib/libssl.a;(path to project)/install/lib/libcrypto.a (found version "1.0.2h-dev")
...
Linking C static library libssh2.a
gmake[3]: Leaving directory `(path to project)/submodules/libssh2/build'
[ 46%] Built target libssh2
gmake[3]: Entering directory `(path to project)/submodules/libssh2/build'
Scanning dependencies of target example-direct_tcpip
gmake[3]: Leaving directory `(path to project)/submodules/libssh2/build'
gmake[3]: Entering directory `(path to project)/submodules/libssh2/build'
[ 48%] Building C object example/CMakeFiles/example-direct_tcpip.dir/direct_tcpip.c.o
Linking C executable example-direct_tcpip
(path to project)/install/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_globallookup':
dso_dlfcn.c:(.text+0x11): undefined reference to `dlopen'
dso_dlfcn.c:(.text+0x24): undefined reference to `dlsym'
dso_dlfcn.c:(.text+0x2f): undefined reference to `dlclose'
(path to project)/install/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_bind_func':
dso_dlfcn.c:(.text+0x354): undefined reference to `dlsym'
dso_dlfcn.c:(.text+0x412): undefined reference to `dlerror'
(path to project)/install/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_bind_var':
dso_dlfcn.c:(.text+0x484): undefined reference to `dlsym'
dso_dlfcn.c:(.text+0x542): undefined reference to `dlerror'
(path to project)/install/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_load':
dso_dlfcn.c:(.text+0x5a9): undefined reference to `dlopen'
dso_dlfcn.c:(.text+0x60d): undefined reference to `dlclose'
dso_dlfcn.c:(.text+0x645): undefined reference to `dlerror'
(path to project)/install/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_pathbyaddr':
dso_dlfcn.c:(.text+0x6d1): undefined reference to `dladdr'
dso_dlfcn.c:(.text+0x731): undefined reference to `dlerror'
(path to project)/install/lib/libcrypto.a(dso_dlfcn.o): In function `dlfcn_unload':
dso_dlfcn.c:(.text+0x792): undefined reference to `dlclose'
collect2: error: ld returned 1 exit status
gmake[3]: Leaving directory `(path to project)/submodules/libssh2/build'
gmake[2]: Leaving directory `(path to project)/submodules/libssh2/build'
gmake[1]: Leaving directory `(path to project)(path to project)/submodules/libssh2/build'
gmake[3]: *** [example/example-direct_tcpip] Error 1
gmake[2]: *** [example/CMakeFiles/example-direct_tcpip.dir/all] Error 2
gmake[1]: *** [all] Error 2
make: *** [build-libssh2] Error 2

您可以看到正在使用静态的
openssl
。显然,
libdl
没有链接到
libcrypto
。编译
openssl
时的输出具有
EX_LIBS=-ldl
。这包括图书馆吗?我尝试在
openssl
安装脚本中使用
LDLIBS=-ldl
,但仍然出现相同的错误。对于搜索词
libcrypto undefined引用“dlopen”
,我几乎尝试了所有答案,但都没有用。任何帮助都将不胜感激,因为我不熟悉
清管器配置
我切换到
Autoconf

#!/bin/sh

set -ex

INSTALL_PATH="$PWD/install"
SUBMODULE_PATH="$PWD/submodules/libssh2"

mkdir -p $INSTALL_PATH/lib &&
cd $SUBMODULE_PATH &&
./buildconf
./configure --prefix=$INSTALL_PATH --libdir=$INSTALL_PATH/lib64 --with-openssl CFLAGS="-fPIC" LDFLAGS="-m64 -L$INSTALL_PATH/lib -L$INSTALL_PATH/lib64" LIBS=-ldl
make
make install

这成功地编译了。

我发现将
目标链接库(libssh2${CMAKE\u DL\u LIBS})
添加到
src/CMakeLists.txt
(如上所述)可以解决问题中提到的问题。请注意,我使用的是libssh2-1.8.0和最新的OpenSSL(5de683d),但我认为OpenSSL_1_0_2-stable的情况也是如此

因此,有效的LIBSSH2构建代码是:

#在libssh2根目录中
printf'\n目标链接库(libssh2${CMAKE_DL_LIBS})>>src/CMakeLists.txt
mkdir生成和cd生成
cmake-DTHREADSAFE=ON\
-DBUILD_CLAR=OFF\
-DBUILD\u SHARED\u LIBS=OFF\
-DCMAKE_C_FLAGS=-fPIC\
-DCMAKE\u BUILD\u TYPE=“RelWithDebInfo”\
-DCMAKE_INSTALL_PREFIX=$INSTALL_路径\
.. &&
cmake——构建。
安装

注意:我还必须添加
target\u link\u库(libssh2 pthread)
,因为我在最新版本中获得了对
pthread
的未定义引用。

另请参见和注释“执行最终链接时需要添加
-ldl
”。另外,“我尝试在openssl安装中使用LDLIBS=-ldl…”-libssh遇到了问题,而不是libcrypto。@jww如果libssh正在查找引用,那么为什么错误会显示libcrypto.a。。。未定义的引用。。。?有点混乱
libcrypto.A
具有依赖性。您可以链接最终程序或
libssh2
——在这两种情况下,您都需要添加
-ldl
,因为它是一个依赖项。OpenSSL编译并与之链接,因此在构建OpenSSL时,它不是一个未满足的依赖项。您可以通过配置
无dso
来删除OpenSSL对文件控制功能的使用。