find_library选择静态库而不是共享库 [英] find_library chooses the static library instead of the shared library
问题描述
This 已在之前的SO上被询问,甚至相关错误在这个CMAKE中。但是,我的问题是一个变化,答案不清楚。
我的皱纹是,我在Linux上使用MinGW交叉编译Windows。静态库被命名为这个 libGLESv2.dll.a
和 libiconv.dll.a
的DLLs libGLESv2.dll
和 iconv.dll
示例: p>
find_library(FOUND_LIB_X NAMESzlib1.dllPATHS $ {CMAKE_FIND_ROOT_PATH} / bin /)
找到这个:zlib1.dll
find_library(FOUND_LIB_Y NAMESlibGLESv2.dllPATHS $ {CMAKE_FIND_ROOT_PATH} / bin /)
找到这个:libGLESv2.dll.a
find_library(FOUND_LIB_Y NAMES iconv.dllPATHS $ {CMAKE_FIND_ROOT_PATH} / bin /)
找到这个:libiconv.dll.a
CMAKE错误似乎是指传统的情况,静态lib命名为blah.lib(Windows)或blah.a(Linux)。在这个交叉编译器的情况下,mingw在Linux上,它们被命名为blah.dll.a
我需要它来查找文件,字面上称为 iconv .dll
,没有别的。如果没有字面上找到,那么中止。我使用错误的CMAKE功能吗? (不要使用 find_library()
?)
在搜索库时迭代库名称和目录之间的确定顺序。例如,根据文档,
当NAMES选项提供多个值时,默认情况下,此命令将一次考虑一个名称,并搜索每个目录。
也就是说,库位于 dir1 / name2
和 dir2 / name1
find_library(MYLIB NAMES name1 name2 PATHS dir1 dir2)
message($ {MYLIB} )
将打印 dir2 / name1
。 / p>
指定 NAMES_PER_DIR 选项反转选项:
find_library(MYLIB NAMES name1 name2 NAMES_PER_DIR PATHS dir1 dir2)
message($ {MYLIB})
将打印 dir1 / name2
。
尝试库的前缀和后缀时,事情是不同的:
每个库nam给予NAMES选项的e被首先考虑为库文件名,然后考虑与平台特定的前缀(例如, lib)和后缀(例如.so)。
似乎检查 也就是说,图书馆位于 将打印 这就是为什么 找到你想要的最简单的方法是使用 NO_DEFAULT_PATH 选项,所以在 This has been asked on SO before and there's even a related bug on this in CMAKE. However, my issue is a variation and the answer is not clear. My wrinkle is that I'm cross-compiling for Windows on Linux using MinGW. Static libs are named like this Examples: The CMAKE bug seems to be referring to traditional situations where the static lib is named blah.lib (Windows) or blah.a (Linux). In this cross-compiler situation with mingw on Linux, they are named blah.dll.a I need it to find the file literally called CMake uses definite order between iterating library names and directories when search the library. E.g., according to documentation, When more than one value is given to the NAMES option this command by default will consider one name at a time and search every directory for it. That is, with libraries at will print Specifying NAMES_PER_DIR option reverse the choice: will print Things are different with trying library's prefix and suffix: Each library name given to the NAMES option is first considered as a library file name and then considered with platform-specific prefixes (e.g. lib) and suffixes (e.g. .so). It seems that checking for That is, with libraries at will print That is why The simplest way to find what you want is to use NO_DEFAULT_PATH option, so searching in
这篇关于find_library选择静态库而不是共享库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! lib< name> .so
在< name>
之后立即执行$>
dir1 / libname.so
和 dir2 / name
find_library(MYLIB NAMES名称PATHS dir1 dir2)
消息($ {MYLIB})
dir1 / libname.so
。
libiconv.dll.a
在你的情况下找到: lib /
目录被搜索为搜索算法在 find_library
的步骤5中的系统特定路径,但仅被搜索的目录 bin /
指定为PATH选项在步骤6。
lib中搜索/
将不会执行:
find_library(FOUND_ LIB_Y
NAMESiconv.dll
PATHS $ {CMAKE_FIND_ROOT_PATH} / bin /
NO_DEFAULT_PATH
)
libGLESv2.dll.a
and libiconv.dll.a
for the DLLs libGLESv2.dll
and iconv.dll
respectively.find_library(FOUND_LIB_X NAMES "zlib1.dll" PATHS ${CMAKE_FIND_ROOT_PATH}/bin/)
finds this: zlib1.dll
find_library(FOUND_LIB_Y NAMES "libGLESv2.dll" PATHS ${CMAKE_FIND_ROOT_PATH}/bin/)
finds this: libGLESv2.dll.a
find_library(FOUND_LIB_Y NAMES "iconv.dll" PATHS ${CMAKE_FIND_ROOT_PATH}/bin/)
finds this: libiconv.dll.a
iconv.dll
and nothing else. If it doesn't literally find that, then abort. Am I using the wrong CMAKE function? (don't use find_library()
?)
dir1/name2
and dir2/name1
find_library(MYLIB NAMES name1 name2 PATHS dir1 dir2)
message(${MYLIB})
dir2/name1
.find_library(MYLIB NAMES name1 name2 NAMES_PER_DIR PATHS dir1 dir2)
message(${MYLIB})
dir1/name2
.
lib<name>.so
is performed immediately after <name>
when iterating directories.dir1/libname.so
and dir2/name
find_library(MYLIB NAMES name PATHS dir1 dir2)
message(${MYLIB})
dir1/libname.so
.libiconv.dll.a
is found in your case: lib/
directory is searched as system specific path at step 5 of find_library
search algorithm, but directory bin/
, specified as PATH option, is searched only at step 6.lib/
will not be performed at all:find_library(FOUND_LIB_Y
NAMES "iconv.dll"
PATHS ${CMAKE_FIND_ROOT_PATH}/bin/
NO_DEFAULT_PATH
)