Skip to content

cmake: fix FindLAPACKE picking openblas.pc over lapacke.pc - #7421

Merged
petrasovaa merged 1 commit into
OSGeo:mainfrom
petrasovaa:cmake-lapack
Jun 1, 2026
Merged

petrasovaa merged 1 commit into
OSGeo:mainfrom
petrasovaa:cmake-lapack

Conversation

@petrasovaa

Copy link
Copy Markdown
Contributor

I had trouble configuring GRASS with cmake and this PR is what my AI suggested. It solved the problem for me.

AI summary

When both lapacke.pc and openblas.pc are present, _search_lapacke_pkgs overwrites LAPACKE_PKGCONFIG on every iteration, so openblas (last in the list) always wins. On Debian/Ubuntu the openblas-pthread variant doesn't ship LAPACKE symbols, so the LAPACKE_dgesv check links only libopenblas.so and fails:

Could NOT find LAPACKE (missing: HAVE_LAPACKE_DGESV) (found version "0.3.26")

Add break() so the first match wins, matching the documented "lapacke and openblas... in that order" priority.

@petrasovaa
petrasovaa requested a review from nilason May 20, 2026 19:27
@github-actions github-actions Bot added the CMake label May 20, 2026
Comment thread cmake/find_scripts/FindLAPACKE.cmake Resolved

@echoix echoix left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense with the intention written out in the header of the file

@nilason nilason left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for late reaction, been travelling. Make sense, thanks!

@petrasovaa
petrasovaa merged commit 1bf8590 into OSGeo:main Jun 1, 2026
26 checks passed
@petrasovaa
petrasovaa deleted the cmake-lapack branch June 1, 2026 20:52
@github-actions github-actions Bot added this to the 8.6.0 milestone Jun 1, 2026
@tmszi

tmszi commented Jun 2, 2026

Copy link
Copy Markdown
Member

With your changes, I get compilation error message under Gentoo GNU/Linux (with enabled lapack USE flag)

-- Found CBLAS: TRUE (found version "0.3.32")
-- Looking for LAPACKE_dgesv
-- Looking for LAPACKE_dgesv - not found
CMake Error at /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:290 (message):
  Could NOT find LAPACKE (missing: HAVE_LAPACKE_DGESV) (found version
  "3.12.0")
Call Stack (most recent call first):
  /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:654 (_FPHSA_FAILURE_MESSAGE)
  cmake/find_scripts/FindLAPACKE.cmake:108 (find_package_handle_standard_args)
  cmake/modules/CheckDependentLibraries.cmake:224 (find_package)
  CMakeLists.txt:155 (include)

Successful compilation log without your changes:

-- Found CBLAS: TRUE (found version "0.3.32")
-- Looking for LAPACKE_dgesv
-- Looking for LAPACKE_dgesv - found
-- Found LAPACKE: TRUE (found version "0.3.32")
-- Found OpenMP_C: -fopenmp (found version "4.5")

@nilason

nilason commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

With your changes, I get compilation error message under Gentoo GNU/Linux (with enabled lapack USE flag)

Do you have openblas installed?

@tmszi

tmszi commented Jun 2, 2026

Copy link
Copy Markdown
Member

With your changes, I get compilation error message under Gentoo GNU/Linux (with enabled lapack USE flag)

Do you have openblas installed?

Yes I have.

tomas@gentoo-gnu-linux:~$ eix openblas
[I] sci-libs/openblas
     Available versions:  0.3.30-r5^td 0.3.31^td 0.3.32^td ~0.3.33^td {cpudetection eselect-ldso index64 openmp pthread relapack test}
     Installed versions:  0.3.32^td(01:21:49 PM 05/22/2026)(openmp -cpudetection -index64 -pthread -relapack -test)
     Homepage:            https://github.com/OpenMathLib/OpenBLAS
     Description:         Optimized BLAS library based on GotoBLAS2

@nilason

nilason commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

With your changes, I get compilation error message under Gentoo GNU/Linux (with enabled lapack USE flag)

Do you have openblas installed?

Yes I have.

That explains why it used to work, because it ended up using openblas, even though the lapacke package was found (but obviously didn't have LAPACKE_dgesv). Each package found must also be checked, as soon as I find the time I'll make a PR for this. The FindCBLAS, has the same issues. Meanwhile, you should be able to set it manually with -D LAPACKE_PKGCONFIG=openblas.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants