The Meaning of DCP2K_LINKER_FLAGS during installation of GROMACS with CP2K

GROMACS version: 2022-beta1-dev
GROMACS modification: No

Hello, I am writing to you because I cannot understand what the meaning of “-DCP2K_LINKER_FLAGS” is in this link, manual for the installation of GROMACS with CP2K.

Is there anyone who can kindly explain or designate what that is?

Thank you very much in advance.


When building gromacs with CP2K support, Gromacs is statically linked with the libcp2k.a library, such that it is able to call into cp2k code for the QM part of the simulation.

However, libcp2k in turn depends on other libraries to work, like BLAS or libxc. The CP2K_LINKER_FLAGS CMake variable must be set to the linker flags (ie, linker command line arguments) that allow linking with these libraries.

When you compiled cp2k, you specified an ARCH argument to make (e.g make -j4 ARCH=Linux-x86-64-gfortran), corresponding to an file in the arch directory of the cp2k source distribution (for instance arch/Linux-x86-64-gfortran-generic.ssmp). Open this file, and look for the content of the LDFLAGS and LIBS variable, and put it space separated into the CP2K_LINKER_FLAGS variable. You might have to manually resolve or modify the values: for instance change ‘$(FFTW_LIB)/libfftw3.a’ into /usr/lib64/libfftw3.a (or elsewhere depending on your fftw installation location)

This also might require some trial and error: if the linker flags are incorrect, you can expect either cmake failing, or the build step failing due to undefined symbols. Googling the undefined symbol name (after possibly demangling it) will indicate which library is missing.

I really appreciate your answer, ebriand :)

However, even after adding all the strings from flags (e.g., $LDFLAGS, $LIBS and so on) in my arch file, I still encounter this kind of error with a myriad of undefined reference to mpi_*.

/usr/bin/ld: /usr/bin/ld: DWARF error: can’t find .debug_ranges section.

So, could I ask you advice about what I should do for this situation?

Thank you very much again.


These are two different issues.

First you have to resolve the missing symbols: undefined reference to mpi_* means that your MPI library is not being linked. You must add the corresponding linker flag for that.

If you are using openMPI, mpicc -showme:link will show you the linker flags to add. For other implementations, you might try -link_info or -show, or consult the documentation regarding how to link with that MPI library.

Once you do not have any undefined reference error left, if the can’t find .debug_ranges section error persist, please post the complete output, as well as the result of running ld --version.