Open jlconlin opened 7 years ago
You probably need to add -static-libgfortran
and -static-libgcc
on the link line. Don't know if you can get libquadmath statically linked though.
You actually need to use an additional CMAKE flag to add "-static" to the linker flags:
-D CMAKE_EXE_LINKER_FLAGS="-static"
I had to do this when I was compiling njoy at IRSN.
@whaeck this seems to do the trick—at least on Linux. On my Mac, I get:
$ cmake -D static_libraries=TRUE -D CMAKE_EXE_LINKER_FLAGS="-static" ../
-- The Fortran compiler identification is GNU 7.2.0
-- Checking whether Fortran compiler has -isysroot
-- Checking whether Fortran compiler has -isysroot - yes
-- Checking whether Fortran compiler supports OSX deployment target flag
-- Checking whether Fortran compiler supports OSX deployment target flag - yes
-- Check for working Fortran compiler: /usr/local/bin/gfortran
-- Check for working Fortran compiler: /usr/local/bin/gfortran -- broken
CMake Error at /usr/local/Cellar/cmake/3.7.2/share/cmake/Modules/CMakeTestFortranCompiler.cmake:44 (message):
The Fortran compiler "/usr/local/bin/gfortran" is not able to compile a
simple test program.
It fails with the following output:
Change Dir: /Users/jlconlin/NJOY21/Code/NJOY2016/bin/CMakeFiles/CMakeTmp
Run Build Command:"/usr/bin/make" "cmTC_9dcd7/fast"
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f
CMakeFiles/cmTC_9dcd7.dir/build.make CMakeFiles/cmTC_9dcd7.dir/build
Building Fortran object CMakeFiles/cmTC_9dcd7.dir/testFortranCompiler.f.o
/usr/local/bin/gfortran -isysroot
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk
-mmacosx-version-min=10.12 -c
/Users/jlconlin/NJOY21/Code/NJOY2016/bin/CMakeFiles/CMakeTmp/testFortranCompiler.f
-o CMakeFiles/cmTC_9dcd7.dir/testFortranCompiler.f.o
Linking Fortran executable cmTC_9dcd7
/usr/local/Cellar/cmake/3.7.2/bin/cmake -E cmake_link_script
CMakeFiles/cmTC_9dcd7.dir/link.txt --verbose=1
/usr/local/bin/gfortran -static -isysroot
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk
-mmacosx-version-min=10.12
CMakeFiles/cmTC_9dcd7.dir/testFortranCompiler.f.o -o cmTC_9dcd7
ld: library not found for -lcrt0.o
collect2: error: ld returned 1 exit status
make[1]: *** [cmTC_9dcd7] Error 1
make: *** [cmTC_9dcd7/fast] Error 2
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:5 (project)
-- Configuring incomplete, errors occurred!
See also "/Users/jlconlin/NJOY21/Code/NJOY2016/bin/CMakeFiles/CMakeOutput.log".
See also "/Users/jlconlin/NJOY21/Code/NJOY2016/bin/CMakeFiles/CMakeError.log".
I have a similar problem on my linux. I will try adjust the LD_LIBRARY_PATH to see if that fixes it. I will update as required.
I just tried the following on snow and it allows me to build a static executable (i.e. ldd njoy will tell me that it is not a dynamic executable): cmake -Dstatic_libraries=ON -Dstatic_njoy=ON -DCMAKE_EXE_LINKER_FLAGS=-static ../
If I invoke CMake with this command:
then I don't get statically linked libraries as I would think. The command
ldd
(otool -L
on Mac) lists the libraries that are statically linked and includes (on Linux gcc 6.3):On my Mac (gcc 7.2) I get: