使用CMake链接到犰狳库 [英] Linking to Armadillo libraries with CMake
问题描述
我在Windows 8上安装MLPack。
我用CMakeLists.txt文件配置:
I am trying to install MLPack on windows 8. I configure the CMakeLists.txt file with:
set(ARMADILLO_LIBRARY "C:\\Program Files (x86)\\armadillo\\lib")
set(ARMADILLO_INCLUDE_DIR "C:\\Program Files (x86)\\armadillo\\include")
然后当我运行CMake时,我有一系列的警告这些:
Then when I ran CMake I had a whole series of warning like these ones:
WARNING: Target "mlpack" requests linking to directory "C:\Program Files (x86)\armadillo\lib". Targets may link only to libraries. CMake is dropping the item.
在\ mlpack-1.0.4 \src\mlpack目录中,我找到了另一个CMakeLists文件:
In \mlpack-1.0.4\src\mlpack directory I found another CMakeLists file with:
target_link_libraries(mlpack
${ARMADILLO_LIBRARIES}
${Boost_LIBRARIES}
${LIBXML2_LIBRARIES}
)
我不知道这是不是一个好主意) :
that I changed to (not sure if that was a good idea):
target_link_libraries(mlpack
${Boost_LIBRARIES}
)
link_directories(mlpack
${ARMADILLO_LIBRARIES}
${LIBXML2_LIBRARIES}
)
似乎运行顺利:
-- Found Armadillo: C:\Program Files (x86)\armadillo\lib (found suitable version "3.800.2", minimum required is "2.4.2")
-- Found LibXml2: C:\cpp\libraries\libxml2-2.7.8.win32\lib (found suitable version "2.7.8", minimum required is "2.6.0")
-- Boost version: 1.53.0
-- Found the following Boost libraries:
-- program_options
-- unit_test_framework
-- Boost version: 1.53.0
-- Found the following Boost libraries:
-- random
-- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE)
-- Configuring done
-- Generating done
-- Build files have been written to: C:/cpp/libraries/mlpack-1.0.4
但是现在当我运行make我有很多这样的错误:
but now when running make I have tons of such errors :
Linking CXX executable ..\..\..\..\gmm.exe
CMakeFiles\gmm.dir/objects.a(gmm_main.cpp.obj):gmm_main.cpp:(.text+0xb9): undefined reference to `wrapper_dgemv_'
CMakeFiles\gmm.dir/objects.a(gmm_main.cpp.obj):gmm_main.cpp:(.text$_ZN4arma6auxlib10det_lapackIdEET_RKNS_3MatIS2_EEb[__ZN4arma6auxlib10det_lapackIdEET_RKNS_3MatIS2_EEb]+0x115): undefined reference to `wrapper_dgetrf_'
后调查似乎与Armadillo 。
which after investigation seems to be related to Armadillo.
任何想法发生了什么?我想我应该使用target_link_libraries为犰狳,但我不知道如何。
Any idea what is happening ? I guess I should use target_link_libraries for Armadillo but I am not sure how.
推荐答案
这个问题希望很容易解决。当你这样做...
The issue is hopefully pretty easy to resolve. When you do this...
set(ARMADILLO_LIBRARY "C:\\Program Files (x86)\\armadillo\\lib")
set(ARMADILLO_INCLUDE_DIR "C:\\Program Files (x86)\\armadillo\\include")
它期望必须做的工作找到这些路径。然而,当 find_package
执行工作时,变量 ARMADILLO_LIBRARY
设置为库本身的路径 - 而不是路径
you're effectively short-circuiting the find_package(Armadillo 2.4.2 REQUIRED)
call, since it expects to have to do the work to find these paths. However, when find_package
does the work, the variable ARMADILLO_LIBRARY
gets set to the path to the library itself - not the path to the lib's directory.
因此,问题归结为将 ARMADILLO_LIBRARY
设置为lib目录的路径,而不是lib本身。这最终会导致链接器错误,因为目标 gmm
(在src \mlpack\methods\gmm\CMakeLists.txt中添加)链接到 mlpack
,并且 mlpack
已设置为链接到 $ {ARMADILLO_LIBRARIES}
So the problem boils down to setting ARMADILLO_LIBRARY
to the path to the lib's directory rather than the lib itself. This ultimately yields a linker error since the target gmm
(added in src\mlpack\methods\gmm\CMakeLists.txt) links to mlpack
, and mlpack
has been set to link to ${ARMADILLO_LIBRARIES}
, which isn't set correctly.
结果是 find_package(Armadillo ...)
已经检入$ ENV {ProgramFiles} / Armadillo / lib
和$ ENV {ProgramFiles} / Armadillo / include
这些解析为C:\\Program Files(x86)\\armadillo\\lib
和C: \\\Program Files(x86)\\armadillo\\include
。
It turns out that find_package(Armadillo ...)
already checks in "$ENV{ProgramFiles}/Armadillo/lib"
and "$ENV{ProgramFiles}/Armadillo/include"
, and I expect these resolve to "C:\\Program Files (x86)\\armadillo\\lib"
and "C:\\Program Files (x86)\\armadillo\\include"
on your machine.
您应该删除 ARMADILLO_LIBRARY
和 ARMADILLO_INCLUDE_DIR
的行并还原您在src\mlpack\CMakeLists.txt中的更改(使用 link_directories
通常是一个坏主意。)
So to fix this, you should delete the lines setting ARMADILLO_LIBRARY
and ARMADILLO_INCLUDE_DIR
, and revert your change in src\mlpack\CMakeLists.txt (using link_directories
is generally a bad idea anyway).
应该在重新运行CMake之前至少删除CMakeCache.txt(在构建树的根目录中),甚至删除整个构建树,以避免使用先前失败尝试中使用的不良缓存值的可能性。
After making these changes, you should delete at least your CMakeCache.txt (in the root of your build tree), or even your entire build tree before re-running CMake to avoid the possibility of using bad cached values from previous failed attempts.
这篇关于使用CMake链接到犰狳库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!