cmake中的zlib的设置方法----Target "xxxxx" links to target "ZLIB::ZLIB" but the target was not found
问题:
AUTOGEN: No valid Qt version found for target opencv_opencl. AUTOMOC, AUTOUIC and AUTORCC disabled. Consider adding: find_package(Qt<QTVERSION> COMPONENTS Widgets) to your CMakeLists.txt file. This warning is for project developers. Use -Wno-dev to suppress it. CMake Error at AppNLP/CMakeLists.txt:255 (add_executable): Target "xxxxxxx" links to target "ZLIB::ZLIB" but the target was not found. Perhaps a find_package() call is missing for an IMPORTED target, or an ALIAS target is missing? Generating done CMake Warning: Manually-specified variables were not used by the project: QT_QMAKE_EXECUTABLE CMake Project parsing failed.
D:\AwsOneDriver\aStudioLk\AeolusPterosaurPlat\AppNLP\CMakeLists.txt:255: error: Target "appNLP_my" links to target "ZLIB::ZLIB"
but the target was not found. Perhaps a find_package() call is missing for an IMPORTED target, or an ALIAS target is missing?
:-1: error: Failed to compute build system.
当前的makefile写法:
find_package(ZLIB ) include_directories( "D:/win10/aspDep/zlib1211/x64/include") link_directories( "D:/win10/aspDep/zlib1211/x64/lib") ADD_DEFINITIONS (${ZLIB_DEFINITIONS})
问题的解决办法:
set( ZLIB_ROOT "D:/win10/aspDep/zlib1211/x64" ) find_package(ZLIB ) include_directories( "D:/win10/aspDep/zlib1211/x64/include") link_directories( "D:/win10/aspDep/zlib1211/x64/lib") ADD_DEFINITIONS (${ZLIB_DEFINITIONS})
是的,只需要加一行代码即可。
问题总结:
出现这个问题的原因不是由于protobuf库是否静态库,也不是由于zlib库是否静态库,而仅仅是因为没有找到zlib的根目录,由此导致找不到zlib的一些定义。
附官网资料:
官网说明:https://cmake.org/cmake/help/latest/module/FindZLIB.html
FindZLIB
Find the native ZLIB includes and library.
IMPORTED Targets
This module defines IMPORTED
target ZLIB::ZLIB
, if ZLIB has been found.
Result Variables
This module defines the following variables:
ZLIB_INCLUDE_DIRS - where to find zlib.h, etc.
ZLIB_LIBRARIES - List of libraries when using zlib.
ZLIB_FOUND - True if zlib found.
ZLIB_VERSION_STRING - The version of zlib found (x.y.z)
ZLIB_VERSION_MAJOR - The major version of zlib
ZLIB_VERSION_MINOR - The minor version of zlib
ZLIB_VERSION_PATCH - The patch version of zlib
ZLIB_VERSION_TWEAK - The tweak version of zlib
Backward Compatibility
The following variable are provided for backward compatibility
ZLIB_MAJOR_VERSION - The major version of zlib
ZLIB_MINOR_VERSION - The minor version of zlib
ZLIB_PATCH_VERSION - The patch version of zlib
Hints
A user may set ZLIB_ROOT
to a zlib installation root to tell this module where to look.
_________________________________________________________________________________________________________________________________________________
每一个不曾起舞的日子,都是对生命的辜负。
But it is the same with man as with the tree. The more he seeks to rise into the height and light, the more vigorously do his roots struggle earthward, downward, into the dark, the deep - into evil.
其实人跟树是一样的,越是向往高处的阳光,它的根就越要伸向黑暗的地底。----尼采
每一个不曾起舞的日子,都是对生命的辜负。
But it is the same with man as with the tree. The more he seeks to rise into the height and light, the more vigorously do his roots struggle earthward, downward, into the dark, the deep - into evil.
其实人跟树是一样的,越是向往高处的阳光,它的根就越要伸向黑暗的地底。----尼采
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步