RMGDFT / rmgdft

RMG is an Open Source code for electronic structure calculations and modeling of materials and molecules. It is based on density functional theory and uses a real space basis and pseudopotentials.
GNU General Public License v2.0
47 stars 11 forks source link

Compiling RMG Ubuntu 18.04.3 #23

Closed jcklasseter closed 5 years ago

jcklasseter commented 5 years ago

Maybe a little niche, but I compiled rmg-cpu v4.0.0-beta in Ubuntu 18.04.3 LTS in a VirtualBox VM for testing. Here is what worked for me:

I started with a fresh, minimal install.

sudo apt-get install cmake libblas-dev liblapack-dev gfortran libfftw3-dev libboost-all-dev

Then I followed the README.md:

mkdir build
cd build 
cmake ../

Then the final step in make -j 2 rmg-cpu failed. The error was:

[100%] Building CXX object CMakeFiles/rmg-cpu.dir/RMG/Common/Main.cpp.o
[100%] Linking CXX executable rmg-cpu
/usr/bin/ld: Misc/libMisc.a(SharedMemory.cpp.o): undefined reference to symbol 'shm_unlink@@GLIBC_2.2.5'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/librt.so: error adding symbols: DSO missing from command line

So then I ran VERBOSE=1 make -j 2 rmg-cpu to see the actual cmake commands:

[100%] Linking CXX executable rmg-cpu
/usr/bin/cmake -E cmake_link_script CMakeFiles/rmg-cpu.dir/link.txt --verbose=1
/usr/bin/c++   -std=c++14 -fopenmp -Wall -Wno-unused-local-typedefs -Wno-write-strings -pthread -m64 -fext-numeric-literals  -fcx-limited-range -fno-trapping-math -O3 -DNDEBUG  -ldl -rdynamic CMakeFiles/rmg-cpu.dir/RMG/Common/Main.cpp.o  -o rmg-cpu -Wl,-rpath,/usr/lib/x86_64-linux-gnu/openmpi/lib: /usr/lib/x86_64-linux-gnu/openmpi/lib/libmpi_cxx.so /usr/lib/x86_64-linux-gnu/openmpi/lib/libmpi.so /usr/lib/x86_64-linux-gnu/openmpi/lib/libmpi.so -lrt -lhwloc -Wl,-Bstatic -lfftw3 RMG/Common/libRMG_Common.a -lfftw3 -lfftw3 RMG/Common/libRMG_Common.a -lfftw3 -Wl,-Bdynamic -lblas -lnuma spglib/libsymspg.a RmgLib/libRmgLib.a zfp/libzfp.a RMG/Common/libRMG_Common.a -lnuma zfp/libzfp.a InternalPseudo/libInternalPseudo.a Finite_diff/libFinite_diff.a RMG/Common/libRMG_Common.a RmgLib/libRmgLib.a -lz -Wl,-Bstatic -lfftw3 Misc/libMisc.a RMG/Common/libRMG_Common.a Finite_diff/libFinite_diff.a RmgLib/libRmgLib.a RMG/Common/libRMG_Common.a Force/libForce.a Force/libForce.a RMG/Common/libRMG_Common.a Input/libInput.a InternalPseudo/libInternalPseudo.a RMG/Common/libRMG_Common.a RmgLib/libRmgLib.a RMG/Common/libRMG_Common.a RmgLib/libRmgLib.a Finite_diff/libFinite_diff.a Misc/libMisc.a RmgLib/libRmgLib.a Misc/libMisc.a Finite_diff/libFinite_diff.a RmgLib/libRmgLib.a Input/libInput.a XC/libXC.a XC/libXC.a RMG/Spin/libRMG_Spin.a US_PP/libUS_PP.a Input/libInput.a RMG/Common/libRMG_Common.a US_PP/libUS_PP.a US_PP/libUS_PP.a RMG/Common/libRMG_Common.a Force/libForce.a Force/libForce.a US_PP/libUS_PP.a US_PP/libUS_PP.a Force/libForce.a RMG/Subdiag/libRMG_Subdiag.a Finite_diff/libFinite_diff.a RMG/Common/libRMG_Common.a RmgLib/libRmgLib.a RMG/Subdiag/libRMG_Subdiag.a Misc/libMisc.a RmgLib/libRmgLib.a -lfftw3 scalapack/lib/libscalapack.a -Wl,-Bdynamic -lboost_thread -lboost_system -lboost_iostreams -lboost_program_options -lboost_filesystem -lboost_chrono -lboost_date_time -lboost_atomic -lboost_regex -lpthread -lnuma -lz -lboost_thread -lboost_system -lboost_iostreams -lboost_program_options -lboost_filesystem -lboost_chrono -lboost_date_time -lboost_atomic -lboost_regex -lpthread -lblas -lgfortran -lquadmath 
/usr/bin/ld: Misc/libMisc.a(SharedMemory.cpp.o): undefined reference to symbol 'shm_unlink@@GLIBC_2.2.5'
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/librt.so: error adding symbols: DSO missing from command line

To fix this I decided I would just fix the linking myself, I replaced '/usr/bin/c++' in the longer line with gcc and tried again, and got a different error: /usr/bin/ld: RmgLib/libRmgLib.a(BaseThread.cpp.o): undefined reference to symbol '_ZNSt18condition_variable10notify_oneEv@@GLIBCXX_3.4.11'

I added -lstdc++ and the error changed back to: /usr/bin/ld: Misc/libMisc.a(SharedMemory.cpp.o): undefined reference to symbol 'shm_unlink@@GLIBC_2.2.5'

Then, I added -lrt and the error changed to: /usr/bin/ld: spglib/libsymspg.a(symmetry.c.o): undefined reference to symbol 'acos@@GLIBC_2.2.5'

Which thankfully was the easiest fix of all: -lm. After that, things finally worked and the diamond8 example finished in ~30 seconds (which is an overestimate since I used time mpirun) which is more than fine for some tests.

So, long story short adding -lstdc++ -lrt -lm to the generated cmake link command resulted in successful compilation on Ubuntu 18.04.3 LTS.

(I can't find the option to add the 'Build Instructions' flair, apologies)

elbriggs commented 5 years ago

Thanks. I don't have a Ubuntu 18.04.3 LTS machine handy to test on but I made a few changes that will hopefully address it. Specifically the call to shm_unlink was part of a deprecated code path and is now gone so that should not be a problem anymore. The other libs should have been linked if cmake thought it was a linux system but they should also be linked if gcc is the compiler so I made sure they are in both cases.