【发布时间】:2018-11-19 21:03:51
【问题描述】:
我在将 CURL 库添加到 CMake 项目时遇到问题。在我的 CMakeList.txt 中,我有以下几行用于添加 CURL:
#option(CURL_STATICLIB "Set to ON to build libcurl with static linking." ON)
if(WIN32)
add_definitions("-DCURL_STATICLIB")
endif()
option(LIBCURL_ENABLE "Enable or disable the requirement of libcurl" ON)
if(LIBCURL_ENABLE)
find_path(LCURL_INCLUDE_DIR
NAMES
curl.h
PATHS
/usr/include/curl
ENV "PROGRAMFILES(X86)"
ENV "LIBCURL_ROOT"
PATH_SUFFIXES
include)
find_library(LCURL
NAMES
libcurl.a
libcurl.lib
PATHS
/usr/lib/x86_64-linux-gnu
/usr
PATH_SUFFIXES
lib
lib/x86_64-linux-gnu)
if(LCURL STREQUAL "LCURL-NOTFOUND")
message(FATAL_ERROR "libcurl NOT found: use `-DLIBCURL_ENABLE=OFF` to build without libcurl support")
else()
set(LIBS ${LIBS} ${LCURL})
include_directories(AFTER ${LCURL_INCLUDE_DIR})
endif()
else()
add_definitions("-DCONF_NO_LIBCURL")
endif()
...
if(LIBCURL_ENABLE)
target_link_libraries(app ${ZLIB_LIBRARIES} ${LCURL})
endif()
在 Windows 上一切正常。但在 Linux 上,我从 make install 命令收到了这条消息:
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/libcurl.a(libcurl_la-content_encoding.o): undefined reference to symbol 'inflateInit2_'
/usr/lib/x86_64-linux-gnu/libz.so: error adding symbols: DSO missing from command line
【问题讨论】:
-
尝试颠倒
${ZLIB_LIBRARIES}和${LCURL}的顺序。 -
没有帮助变量反转。