Eclipse Paho MQTT C-如何获取静态库?

问题描述 投票:1回答:1

我正在尝试从Ubuntu 16.04上的repository编译代码,以便生成静态库:

cd ~/Downloads
git clone https://github.com/eclipse/paho.mqtt.c.git
mkdir /tmp/build.paho
cd /tmp/build.paho
cmake -GNinja -DPAHO_WITH_SSL=TRUE -DPAHO_BUILD_STATIC=TRUE ~/Downloads/paho.mqtt.c

该过程始终失败,并出现以下错误:

-- The C compiler identification is GNU 5.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- CMake version: 3.5.1
-- CMake system name: Linux
-- Timestamp is 2019-10-22T09:16:51Z
CMake Error at src/CMakeLists.txt:95 (ADD_LIBRARY):
  add_library cannot create target "paho-mqtt3c" because another target with the same name already exists.  The existing target is a shared library created in source directory "/home/<username>/Downloads/paho.mqtt.c/src".  See documentation for policy CMP0002 for more details.

CMake Error at src/CMakeLists.txt:96 (ADD_LIBRARY):
  add_library cannot create target "paho-mqtt3a" because another target with the same name already exists.  The existing target is a shared library created in source directory "/home/<username>/Downloads/paho.mqtt.c/src".  See documentation for policy CMP0002 for more details.

CMake Error at src/CMakeLists.txt:101 (INSTALL):
  install TARGETS given no LIBRARY DESTINATION for shared library target "paho-mqtt3c".

-- OpenSSL hints: 
-- OpenSSL headers found at /usr/include
-- OpenSSL library found at /usr/lib/aarch64-linux-gnu/libssl.so
-- OpenSSL Crypto library found at /usr/lib/aarch64-linux-gnu/libcrypto.so
CMake Error at src/CMakeLists.txt:165 (ADD_LIBRARY):
  add_library cannot create target "paho-mqtt3cs" because another target with the same name already exists.  The existing target is a shared library created in source directory "/home/<username>/Downloads/paho.mqtt.c/src".  See documentation for policy CMP0002 for more details.

CMake Error at src/CMakeLists.txt:166 (ADD_LIBRARY):
  add_library cannot create target "paho-mqtt3as" because another target with the same name already exists.  The existing target is a shared library created in source directory "/home/<username>/Downloads/paho.mqtt.c/src".  See documentation for policy CMP0002 for more details.

CMake Error at src/CMakeLists.txt:176 (INSTALL):
  install TARGETS given no LIBRARY DESTINATION for shared library target "paho-mqtt3cs".

-- OpenSSL hints: 
-- OpenSSL headers found at /usr/include
-- Configuring incomplete, errors occurred!
See also "/home/<username>/Downloads/paho.mqtt.c/build/CMakeFiles/CMakeOutput.log".

我不知道怎么了。据我了解,我完全遵循存储库文档中的步骤。

我还必须做些什么,或者我需要做些不同的事情?

cmake ubuntu-16.04 static-linking paho
1个回答
0
投票

在此存储库中,静态库目标名称与共享库目标名称冲突。 CMake不允许这样做,因为目标名称必须为unique。似乎这些不明智的更改已推送到存储库,这破坏了PAHO CMake的构建(请参见here)。由于问题已经提出,因此可以认为很快就会推出修复程序。

但是,如果您需要快速修复,则可以轻松进行此工作。您可以将-static后缀添加到paho.mqtt.c/src/CMakeLists.txt文件中的静态库名称中。有两个值得注意的部分需要进行此更改,只需在该文件中搜索PAHO_BUILD_STATIC

line 94附近(将-static添加到if语句中引用的库名称中,下面以黑体显示):

如果(PAHO_BUILD_STATIC)ADD_LIBRARY(paho-mqtt3c -static STATIC $ MQTTClient.c)ADD_LIBRARY(paho-mqtt3a -static STATIC $ MQTTAsync.c)TARGET_LINK_LIBRARIES(paho-mqtt3c -static $ {LIBS_SYSTEM})TARGET_LINK_LIBRARIES(paho-mqtt3a -static $ {LIBS_SYSTEM})安装(目标paho-mqtt3c -static paho-mqtt3a -static归档目的地$ {CMAKE_INSTALL_LIBDIR})万一()

line 164附近(将-static添加到if语句中引用的库名称中,下面以黑体显示):

如果(PAHO_BUILD_STATIC)ADD_LIBRARY(paho-mqtt3cs -static STATIC $ MQTTClient.c SSLSocket.c)ADD_LIBRARY(paho-mqtt3as -static STATIC $ MQTTAsync.c SSLSocket.c)TARGET_LINK_LIBRARIES(paho-mqtt3cs -static $ {OPENSSL_LIBRARIES} $ {LIBS_SYSTEM})TARGET_LINK_LIBRARIES(paho-mqtt3as -static $ {OPENSSL_LIBRARIES} $ {LIBS_SYSTEM})SET_TARGET_PROPERTIES(paho-mqtt3cs -static paho-mqtt3as -static属性版本$ {CLIENT_VERSION}SOVERSION $ {PAHO_VERSION_MAJOR}COMPILE_DEFINITIONS“ OPENSSL = 1”)安装(目标paho-mqtt3cs -static paho-mqtt3as -static归档目的地$ {CMAKE_INSTALL_LIBDIR})万一()

进行更改后,清除您的CMake缓存(或删除您的构建文件夹中的CMakeCache.txt文件),然后重新运行CMake。这应该可以解决问题。

© www.soinside.com 2019 - 2024. All rights reserved.