I am trying to compile using gfortran using the following:
$ gfortran -I/usr/local/include -O3 -Wall -Wno-uninitialized -fbounds-check -g alignparts_lmbfgs.f90 /home/vincent/test/lmbfgs/Lbfgsb.3.0/lbfgsb.f /home/vincent/test/lmbfgs/Lbfgsb.3.0/linpack.f /home/vincent/test/lmbfgs/Lbfgsb.3.0/blas.f /home/vincent/test/lmbfgs/Lbfgsb.3.0/timer.f /home/vincent/test/lmbfgs/minimal_libraries/imlib2010.a /home/vincent/test/lmbfgs/minimal_libraries/genlib.a -o alignparts_lmbfgs.exe -lfftw3 -lm
but it gave me the error
alignparts_lmbfgs.f90:105: Error: Can't open included file '/usr/include/fftw3.f'
even though I specified the -I opitions where the fftw3.f resides.
What am I doing wrong? I don't have root privileges so I can't just move the files from /usr/local/include to /usr/inlcude
I am a noob in compiling. I am only compiling because this is the only way I am getting the executable. Please be as noob-proof as possible when explaining. Thank you so much!
The compiler reports:
alignparts_lmbfgs.f90:105: Error: Can't open included file '/usr/include/fftw3.f'
This means that your source file alignparts_lmbfgs.f90 contains
a line #105 like:
INCLUDE '/usr/include/fftw3.f'
which tells the compiler to copy the file /usr/include/fftw3.f in place
of that line #105. But there is no such file.
You have passed the compiler option -I/usr/local/include which
tells the compiler to search for included files in /usr/local/include,
and you say:
I specified the -I options where the fftw3.f resides.
So probably there is such a file as /usr/local/include/fftw3.f?
In that case, can change:
INCLUDE '/usr/include/fftw3.f'
to:
INCLUDE '/usr/local/include/fftw3.f'
However, if you do that, then the compiler option:
-I/usr/local/include
is pointless, because /usr/local/include/fftw3.f is an absolute filename:
it either exists or it doesn't.
If you want the program to be compilable independently of the absolute location
of fftw3.f - which is emphatically the best practice - then replace line #105 with:
INCLUDE 'fftw3.f'
Then, if fftw3.f is in fact located in /usr/local/include, you can compile
the program with the option -I/usr/local/include, and in general if the file
is located in directory /look/here/for/headers, you can compile the program
with the option -I/look/here/for/headers.
Related
I am trying to compile main.c with a static library and header files on an Ubuntu server using gcc and ssh using Terminal on Mac. I uploaded the library file and specified it with -L option and specified the header files using the -I option.
I tried using:
gcc main.c -L/Libraries/lib/libRNA.a -lRNA -ILibraries/include/ViennaRNA
It comes out with:
/usr/bin/ld: cannot find -lRNA
collect2: error: ld returned 1 exit status
-L expects a directory as argument. You're passing the name of the library.
Just do:
gcc main.c -L/Libraries/lib -lRNA -ILibraries/include/ViennaRNA
or link with the absolute path of the .a file directly:
gcc main.c /Libraries/lib/libRNA.a -ILibraries/include/ViennaRNA
The -L option specifies a directory where the library file is.
The -L option to gcc (which gets actually passed to ld) is expecting a directory (in which further -l options are seeked).
The -I option is expecting a directory containing included header files.
So you want
gcc -Wall -g main.c -L/Libraries/lib/ -lRNA -ILibraries/include/ViennaRNA
You really want all warnings (-Wall) and debug information (-g) to be able to use the gdb debugger.
I have made some header files and placed them in the same folder as the main program, but the compilation command gcc -ansi -Wall *.c cannot find those files. Do I have to include the full directory path of the header files or am I doing something else wrong?
First of all you have to include the header files into the relevant C-files if you haven't already done so as such:
#include "path/to/file.h"
You also have to tell the compiler to compile the .h-files so if your .h-files are in the same foder as you .c-files and you want to include all the present .h-files your compiler command would look like this:
gcc -ansi -Wall *.h *.c
I'm trying to get BLAS working with in a FORTRAN 77 program, but so far I've been unsuccesful and I can't figure out how to get going with this. For reference I'm doing this under Ubuntu 12.10.
This is the code of the program I'm trying to compile:
program blastest
implicit none
include 'cblas_f77.h'
end
The file cblas_f77.h resides in /usr/include, and there are both libblas.a and libblas.so (and a bunch of other BLAS related files) in /usr/lib.
How do you configure this to work properly?
So far, I've tried the following:
Note: adding -lblas to either of the options make no difference at all...
Just f77, no options (didn't really expect this to work, but what the heck...):
$ f77 blastest.f -o blastest
MAIN blastest:
Cannot open file cblas_f77.h
/usr/bin/f77: aborting compilation
f77 with include option to find the header file. Now, instead it fails on (despite the file name) not being coded with FORTRAN 77 in mind, so the first six columns are nonempty...
$ f77 blastest.f -o blastest -I/usr/include
MAIN blastest:
Error on line 1 of /usr/include/cblas_f77.h: nondigit in statement label field "/* "
Error on line 2 of /usr/include/cblas_f77.h: labeled continuation line (starts " * cbl")
Error on line 3 of /usr/include/cblas_f77.h: labeled continuation line (starts " * Wri")
...
Full output: http://pastebin.com/eZBzh9N5
Switched to gfortran, to be more flexible with the spacing in the header file:
$ gfortran blastest.f -o blastest -I/usr/include
Warning: cblas_f77.h:9: Illegal preprocessor directive
Warning: cblas_f77.h:10: Illegal preprocessor directive
Warning: cblas_f77.h:12: Illegal preprocessor directive
...
Full output: http://pastebin.com/P71Di9pR
OK, so I guessed I need -cpp to get the preprocessor working. That gave exactly the same output as above. Also, if you keep reading you see that the full output, the compiler is still complaining about labelled continuation lines further down...
I believe that you are using the C library "cblas". I would recompile with this command:
gfortran blastest.f -o blastest -L/usr/lib -lblas
and this should sort it all out. I do not believe (though i am not sure) that you need to make use of the "include" statement.
in my homework i must use this command to compile my program:
gcc -o mtm_rentals -std=c99 -Wall -pedantic-errors -Werror -DNDEBUG mtm_ex2.c rentals.c list.c -L -lmtm
what i can change in that line are the files im writing after -DNDEBUG. when i do this the gcc says that there are undefined references to specific functions. now those functions are declared in an .h file and are implemented in a given file called libmtm.a
i concluded that it doesnt recognize libmtm.a, but our homework task says that the -lmtm flag(which is not declared anywhere) is supposed to link libmtm.a to the program.
what am i missing here? am i supposed to implement somehow the -lmtm flag?
thank you!
You are missing a . (single dot) behind the -L.
-lmtm will link against a libmtm library, this is correct. It's not an -lmtm flag, it's a -l flag concatenated with mtm, the library you want to link against. This library is searched in some predefined paths (like /usr/lib/) and additionally in the paths given by -L. Assuming libmtm lives in your current directory, you need to add that to -L, which is done with a ..
Happy New Year Everybody,
I am struggling with a rather stupid gcc include problem. I tried to change my working relative include paths (using -I) to absolute paths, so that I could move the source files and it would still compile.
Relative path (working):
-I../../../NVIDIA_GPU_Computing_SDK/OpenCL/common/inc -lOpenCL
Absolute path (not working):
-I~/NVIDIA_GPU_Computing_SDK/OpenCL/common/inc -lOpenCL
So how do you inlcude header files with absolute paths from the home directory?
Thanks
[update]
I tried the $HOME idea with -I$HOME/NVIDIA_GPU_Computing_SDK/OpenCL/common/inc
but the output of the make file says:
gccIOME/NVIDIA_GPU_Computing_SDK/OpenCL/common/inc-lOpenCL -O3 -fno-strict-aliasing -fopenmp -std=c99 -lm -D_GNU_SOURCE -Wall -pedantic foo.c
foo.c:14: fatal error: CL/cl.h: No such file or directory
compilation terminated.
Does it make a difference that I use a make file for these parameters?
Specify the full path or $HOME instead of using ~ for the home directory
Try using $HOME instead of ~.