Installing netcdf on Ubuntu 12.04 - fortran

I have to use a recent version of gfortran and use netcdf. So I have to complie the netcdf libraries with this new version of gfortran, which is 4.8.2
Before configuration and installing of netcdf, I had to set the following environment variables:
#!/bin/bash
export CC="$HOME/gcc-trunk/bin/gcc"
export LDFLAGS="-L$HOME/gcc-trunk/lib -L$HOME/gcc-trunk/lib64"
export CPP="$HOME/gcc-trunk/bin/cpp"
export FC="$HOME/gcc-trunk/bin/gfortran"
export F77="$HOME/gcc-trunk/bin/gfortran -x f77"
export CXX="$HOME/gcc-trunk/bin/c++"
export CXXPP="$HOME/gcc-trunk/bin/cpp"
export LD_LIBRARY_PATH=$PWD/netcdf/lib:${LD_LIBRARY_PATH}
export CPPFLAGS="-DgFortran -cpp -I$PWD/netcdf/include"
export LDFLAGS="-L$PWD/netcdf/lib"
Everything goes ok when I run configure, but when I make "make check". I get the following error:
libtool: link: /home/antonio/gcc-trunk/bin/gfortran -x f77 -I../fortran -I../f90 -g -o .libs/nf_test test_get.o test_put.o nf_error.o nf_test.o test_read.o test_write.o util.o fortlib.o -L/media/022f8e40-437e-4c37-a8b0-538c07b842a3/home/antonio/DATOS/seas_pred/Fortran_code/netcdf/netcdf-fortran-4.2/netcdf/lib ../fortran/.libs/libnetcdff.so -lnetcdf -rpath /media/022f8e40-437e-4c37-a8b0-538c07b842a3/home/antonio/DATOS/seas_pred/Fortran_code/netcdf/netcdf/lib
gfortran: error: unrecognized command line option '-rpath'
make[2]: *** [nf_test] Error 1
make[2]: se sale del directorio «/media/022f8e40-437e-4c37-a8b0-538c07b842a3/home/antonio/DATOS/seas_pred/Fortran_code/netcdf/netcdf-fortran-4.2/nf_test»
make[1]: *** [check-am] Error 2
make[1]: se sale del directorio «/media/022f8e40-437e-4c37-a8b0-538c07b842a3/home/antonio/DATOS/seas_pred/Fortran_code/netcdf/netcdf-fortran-4.2/nf_test»
make: *** [check-recursive] Error 1
It seems -rpath is an option to be passed to the linker, so it should add a -Wl, before, but it doesn't.
Perhaps I should add this option in an environmental variable, but don't know which.
Can anybody help?
Thanks a lot.

I think you are compiling from the wrong directory. You have $PWD in the value field of LD_LIBRARY_PATH, CPPFLAGS & LDFLAGS. Easiest way to fix is to replace $PWD with the absolute path where your netcdf directory is located.

The problem was caused by the environmental variable F77.
It seems that configure, sets the appropriate values when this variable is not set, but get into trouble when we set it.
I solved it deleting the line in the script that sets the F77 variable.
Thaks to everybody who tired to find a solution, specially to Sadiq Huq.

Related

Unable to Change Default Linker in CMake

I am trying to change my linker to ld.gold so that I can build LLVM and
CLANG faster. I have changed my environment variable with:
export LD=ld.gold
and I have changed CMAKE_LINKER in ccmake to /usr/bin/ld.gold. However,
when I generate the files, my linker is detected as GNU ld. Running top
during compilation confirms that ld is running rather than gold.
When editing the CMake Link Executable variable to:
cmake -DCMAKE_LINKER=/usr/bin/ld.gold -DCMAKE_CXX_LINK_EXECUTABLE="<CMAKE_LINKER> <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>" -G "Unix Makefiles" ../llvm
I receive the following error:
/usr/bin/ld.gold: -Werror=date-time: unknown option
/usr/bin/ld.gold: use the --help option for usage information
utils/PerfectShuffle/CMakeFiles/llvm-PerfectShuffle.dir/build.make:94: recipe for target 'bin/llvm-PerfectShuffle' failed
make[2]: *** [bin/llvm-PerfectShuffle] Error 1
CMakeFiles/Makefile2:13983: recipe for target 'utils/PerfectShuffle/CMakeFiles/llvm-PerfectShuffle.dir/all' failed
I'm on Ubuntu 16.04, but I have had the same problem on Arch Linux.
Thank You.
CMAKE_EXE_LINKER_FLAGS=-fuse-ld=gold will pass -fuse-ld=gold to the compiler, which will properly use the gold linker.

make: g++: error: CreateProcess: No such file or directory

I see that this issue has been posted many many times but none of solutions worked for me and my problem is a bit different.
The problem:
When a use a makefile and mingw32-make, I get the error:
g++: error: CreateProcess: No such file or directory
However, if I copy/paste the SAME command that the makefile tried to do and paste it in the SAME command prompt it works. This problem only occurs when I try to build with a makefile.
Here's more info:
g++ ./src/main.cpp ./src/application.cpp -I C:\Code\infographie\Labs\inc -L C:\Code\infographie\Labs\lib -I C:\Code\infographie\Labs\inc -g -Dmain=SDL_main -L C:\Code\infographie\Labs\lib -lmingw32 -lSDL2main -lSDL2 -o bin/debug/labs.exe
g++: error: CreateProcess: No such file or directory
makefile:23: recipe for target 'all' failed
mingw32-make: *** [all] Error 1
As I said, If I copy/paste the first line it will work.
What can I try?
UPDATE: I've installed cygwin, adjusted SDL libs and recompiled. Now I get this error when I try to use make. If I copy/paste the command, it works.
g++ ./src/main.cpp ./src/application.cpp -I C:\Code\infographie\Labs\inc -L C:\Code\infographie\Labs\lib -I C:\Code\infographie\Labs\inc -g -Dmain=SDL_main -L C:\Code\infographie\Labs\lib -lcygwin -lSDL2main -lSDL2 - mwindows -o bin/debug/labs.exe
make: g++: Command not found
make: *** [makefile:23: all] Error 127
FIXED IT, don't declare a variable named PATH...
Stop using MinGW.
MinGW has not been updated since 2013. It has been replaced by Cygwin and
MSYS2. The MinGW project doesn’t even offer a 64-bit compiler.
Cygwin can be installed in about 3 minutes, I would give it a try.

How to properly configure Clang?

I've just compiled latest reps of LLVM, Clang and libc++. Now however I have no idea how to configure the environment to use them. I've added in $PATH the one to compiled binaries and have set the
$D_LIBRARY_PATH=$(llvm-config --libdir)
but anyway when I test run 'clang' with example file it uses some '/usr/bin/ld' linker which I have no idea what is it (as I've uninstalled 'g++' because thought it was the problem (before 'clang' used some linker from it) and I don't have any other C++ compilers).
So now how do I point out the right 'llvm-ld', libc++ include and library paths? I don't want to pass some complex arguments every-time. Perhaps I should set some environment variables.
I'm also using KDevelop with the same effect.
Don't judge me if this sounds stupid but it's my first time with Linux (have always used Windows before). I'm using latest 'OpenSUSE' dist.
Update - here is the output window of CodeLite using clang compiler:
/bin/sh -c 'make -j 2 -e -f Makefile'
----------Building project:[ ClangTest - Debug ]---------- make[1]: Entering directory
'/run/media/bs_ld/8688602a-296d-40e1-bd37-c90e69f45769/Workspace/CL_C++_WP/ClangTest'
clang++ -c
"/run/media/bs_ld/8688602a-296d-40e1-bd37-c90e69f45769/Workspace/CL_C++_WP/ClangTest/main.cpp"
-stdlib=libc++ -o ./Debug/main.cpp.o -I. -I/run/media/bs_ld/8688602a-296d-40e1-bd37-c90e69f45769/Build/include/c++/v1/
clang++ -o ./Debug/ClangTest #"ClangTest.txt" -L.
-L/run/media/bs_ld/8688602a-296d-40e1-bd37-c90e69f45769/Build/lib/ /usr/bin/ld: cannot find crtbegin.o: No such file or directory
/usr/bin/ld: cannot find -lstdc++ /usr/bin/ld: cannot find -lgcc_s
/usr/bin/ld: cannot find -lgcc clang-3.7: error: linker command failed
with exit code 1 (use -v to see invocation) ClangTest.mk:76: recipe
for target 'Debug/ClangTest' failed make[1]: * [Debug/ClangTest]
Error 1 make[1]: Leaving directory
'/run/media/bs_ld/8688602a-296d-40e1-bd37-c90e69f45769/Workspace/CL_C++_WP/ClangTest'
Makefile:4: recipe for target 'All' failed make: * [All] Error 2 0
errors, 0 warnings
You should be able to run make install with perhaps an optional DESTDIR=/...... so that it doesn't clobber your system files.
Since you're on OpenSUSE, you might as well use your distribution's build services, and install the SVN version of LLVM-Clang from here. You should be able to find libc++ and LLVM itself as well.
Otherwise, make install DESTDIR=/opt/llvm should work, and then you can add /opt/llvm/bin/ to PATH and use libc++ by adding this compile and link option: -stdlib=libc++. You'll need something like /opt/llvm/lib in LD_LIBRARY_PATH as well to find the libc++ so.
This should work pretty much out of the box, but I have only ever used my distribution's packages, not a self-built Clang to do this.
Note that Clang still uses your system linker, ld, and this is fine. Currently, LLVM does not yet provide a fully functional alternative to this program, but they are working on it.
EDIT: It seems you uninstalled too much: Clang also uses the GCC crtbegin and crtend object files. So just install GCC again along with glibc and its dev package.

CMake: how to select a different shell

Using CMake, how to choose the shell to be used? Mine seems to be set to sh by default, but I need some environment vars loaded from my .bashrc, and I guess changing the shell is the way to go.
I'm actually trying to set clang++ as the C++ compiler, with the following directive:
set (CMAKE_CXX_COMPILER "clang++")
But when I try to compile the code, the shell being used is sh, and it does not find clang++, as I make the binary visible via the following export, in my .bashrc:
export PATH="${PATH}:~/llvm/Debug+Asserts/bin/"
Here is the error, confirming sh cannot find the clang++ binary:
$ make
[100%] Building CXX object CMakeFiles/floyd-warshall.dir/main.cpp.o
/bin/sh: 1: clang++: not found
make[2]: *** [CMakeFiles/floyd-warshall.dir/main.cpp.o] Error 127
make[1]: *** [CMakeFiles/floyd-warshall.dir/all] Error 2
make: *** [all] Error 2
You should not force the c++ compiler this way in your cmake file (at first I thought you were using a toolchain file). Remove that line and let CMake finds the compiler by itself. To use clang++ set some environment variables before calling cmake. Something like:
export CC=clang
export CXX=clang++
cmake /path/to/your/project
make

makefile error for c++

What is this error
:!make
g++ -g -I../direc1 -I./ -c final.cpp
make: g++: Command not found
make: *** [final.o] Error 127
?
You don't have g++ installed (or it's not in your $PATH variable).
The error message says it all.
You don't have g++ installed or
You have it installed but it is not in your PATH environment variable.
g++ not found indicates that your system can not find the executable file g++.
Ensure that your system knows where to search for g++.
On windows, this is done via the environment variable "path".
Add the g++ path in $PATH export PATH=$PATH:g++Path