cmake - 通过 `add_subdirectory`添加的库遇到 “No rule to make target while compiling..”错误

标签 cmake compiler-errors msys2

我正在尝试清理legacy C-FORTRAN FLOSS code,并且遇到了一个非常奇怪的错误。通过top add_subdirectory file中的CMakeLists.txt添加了一些库/文件夹。在cmake ..文件夹中运行build命令会成功生成MakeFile(除了some minor warnings可能为假阳性)。但是,当使用make进行编译时,出现了一个奇怪的错误:

Scanning dependencies of target umfpack
mingw32-make[2]: Leaving directory '/path/to/elmerfem/build'
mingw32-make[2]: Entering directory '/path/to/elmerfem/build'
[ 46%] Building C object umfpack/src/umfpack/CMakeFiles/umfpack.dir/umfpack_timer.c.o
mingw32-make[2]: *** No rule to make target '/mingw64/include/cblas.h', needed by 'umfpack/src/umfpack/CMakeFiles/umfpack.dir/umfpack_tictoc.c.o'.  Stop.
mingw32-make[2]: Leaving directory '/path/to/elmerfem/build'
mingw32-make[1]: *** [CMakeFiles/Makefile2:265: umfpack/src/umfpack/CMakeFiles/umfpack.dir/all] Error 2
mingw32-make[1]: Leaving directory '/path/to/elmerfem/build'
mingw32-make: *** [Makefile:163: all] Error 2

which I don't know how to debug. In this case the /mingw64/include/cblas.h exists, and the prior CMake outputs:

-- Looking for Fortran sgemm
-- Looking for Fortran sgemm - found
-- Found BLAS: /mingw64/lib/libopenblas.dll.a
-- Looking for Fortran cheev
-- Looking for Fortran cheev - found
-- A library with LAPACK API found.
-- ------------------------------------------------
--   BLAS library:   /mingw64/lib/libopenblas.dll.a
--   LAPACK library: /mingw64/lib/libopenblas.dll.a

Show that BLAS and LAPACK have been successfully found.

I would appreciate it if you could help me know what is the problem and how I can fix it. Thanks for your kind support in advance.

The environment is:

  • MSYS2: MSYS_NT-10.0-18363
  • Windows Version 1909
  • cmake version 3.15.5
  • GNU Make 4.3
  • gcc.exe (Rev1, Built by MSYS2 project) 9.3.0

P.S.1. I just tested the code on macOS and it compiled with no problem. So it seems to be a Windows/MSYS2 specific problem.

P.S.2. I was told that I should install suitesparse library so I did

 pacman -S mingw64/mingw-w64-x86_64-suitesparse

它没有帮助。

P.S.3。 this Tweet之后,我还应阐明我正在使用MSYS2的CMake和GNU Make软件包,如herehere所述。

最佳答案

运行mingw64.exe(不是msys2.exe)。

确保安装以下软件包:mingw-w64-x86_64-cmakemingw-w64-x86_64-makemingw-w64-x86_64-suitesparse和C/C++,Fortran编译器。

注意:所有已安装的软件包必须在mingw64目录中。

更改CMakeLists.txt中的WITH_MPI值:

SET(WITH_MPI FALSE ...

查找cmake的路径并使用以下命令进行制作:$ where cmake.exe$ where mingw32-make.exe
为了简单起见,请使用alias命令:
alias my_cmake=/d/msys64/mingw64/bin/cmake.exe
alias my_make=/d/msys64/mingw64/bin/mingw32-make.exe

在elmer存储库中创建构建目录,然后:
my_cmake -G "MinGW Makefiles" ..

my_make

关于cmake - 通过 `add_subdirectory`添加的库遇到 “No rule to make target while compiling..”错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61164034/

相关文章:

c# - 使用非管理员组成员的用户登录时无法加载文件或程序集 'Microsoft.CSharp'

perl - 如何安装MSYS Perl的基本模块?

mingw - MSYS2 不提供 .profile

c++ - 隐藏自动生成的 CTest 目标

c++ - clang-tidy 报告未知警告

c++ - 我如何告诉编译器有一些未定义但会结构化的结构?

c# - C#System.IO.InvalidDataException zip文件

bash - 如何使用 CMake execute_process() 正确调用 MSYS2 Bash 命令?

c++ - 正确设置 bgfx(和项目结构)

c - 如何在 CLion 中添加链接器标志