I want to do makefile as the following, but I received this error:
gcc frparse.o frtags.o frscan.o frinit.o frstop.o frfoot.o frio.o -L/usr/local/image/lib/sgi -lioutil -lutil -o frparse
/usr/bin/ld: cannot find -lioutil
collect2: error: ld returned 1 exit status
Makefile:17: recipe for target 'frparse' failed
make: *** [frparse] Error 1
I would appreciate it if you guide me.
IMLIB = /usr/local/image/lib/sgi
LLIBS = -lioutil -lutil
it: frparse frcheck pgrep
OBJ = frparse.o frtags.o frscan.o frinit.o frstop.o frfoot.o frio.o
frparse.o: Makefile frparse.h frio.h frproto.h frstop.h frparse.c
frinit.o: Makefile frparse.h frproto.h frinit.c
frscan.o: Makefile frio.h frstop.h frscan.c
frfoot.o: Makefile frparse.h frproto.h frstop.h frfoot.c
frtags.o: Makefile frparse.h frio.h frproto.h frstop.h frtags.c
frstop.o: Makefile frstop.h frstop.c
frio.o: Makefile frio.c
frparse: $(OBJ)
gcc $(OBJ) -L$(IMLIB) $(LLIBS) -o $#
frcheck: frcheck.o
gcc frcheck.o -L$(IMLIB) $(LLIBS) -o $#
pgrep: pgrep.o
gcc pgrep.o -L$(IMLIB) $(LLIBS) -o $#
.c.o:
# cc -c -O2 -mips2 $<
gcc -c -g $<
regarding:
.c.o:
# cc -c -O2 -mips2 $<
gcc -c -g $<
The comment # must ALSO be indented via a <tab> otherwise the recipe never performs the third line
Also, the syntax is a bit obsolete suggest:
%.o:%.c
for the first line of the recipe
However, regarding your question:
Is there actually a library file named libioutil.so in the directory:
/usr/local/image/lib/sgi
Related
I am trying to create a makefile in C but i am facing some issues.
I have my main .c, one .c which keeps the functions implementations and one .h which keeps the functions declarations.
When i try to run the makefile, i get a fatal error.
here is my makefile:
INCL = prog.h
SRC = prog.c prog_fun.c
OBJ = $(SRC:.c=.o)
EXE = prog
CC = gcc
CFLAGS = -c
RM = rm -rf
all: prog
prog: prog.o prog_fun.o
gcc -o prog prog.o prog_fun.o
prog.o: prog.c
gcc -c prog.c
prog_fun.o: prog_fun.c prog.h
gcc -c prog.c
clean:
$(RM) $(OBJ) $(EXE)
The error i get is this:
gcc -c prog.c
prog.c:11:19: fatal error: prog.h: No such file or directory
compilation terminated.
Makefile:17: recipe for target 'prog.o' failed
make: *** [prog.o] Error 1
Can anyone please help me with this?
What you are trying to do by using this
prog_fun.o: prog_fun.c header.h
It should be only
prog_fun.o: prog_fun.c
Modify your make file as
xyz#xyz-PC:~$ vi makefile
INCL = header.h
SRC = prog.c prog_fun.c
OBJ = $(SRC:.c=.o)
EXE = prog
CC = gcc
CFLAGS = -c
RM = rm -rf
all: prog
prog: prog.o prog_fun.o
gcc -o prog prog.o prog_fun.o
prog.o: prog.c
gcc -c prog.c header.h
prog_fun.o: prog_fun.c
gcc -c prog_fun.c header.h
clean:
$(RM) $(OBJ) $(EXE)
next run it
xxyz#xyz-PC:~$ make
gcc -c prog.c header.h
gcc -c prog_fun.c header.h
gcc -o prog prog.o prog_fun.o
I hope it will work now and make sure indention is correct(not manual spaces, it should be tab key)
I am trying to compile a program and I have to set the paths to the NETCDF inc and lib directories in the Makefile as well as set the gfortran and c compiler settings. The variables were already named as shown below, it just told me to edit the paths/options which I have tried to do. Here is what I have for my netcdf inc and lib, as well as the hdf5:
NETCDFINC = -I$(NETCDFF_INCDIR) -I$(NETCDFC_INCDIR)
NETCDFLIB = -Wl,-rpath=$(NETCDFF_LIBDIR) -L$(NETCDFF_LIBDIR) -Wl,-
rpath=$(NETCDFC_LIBDIR) -L$(NETCDFC_LIBDIR) -Wl,-rpath=$(HDF5_LIBDIR) -
L$(HDF5_LIBDIR) -lhdf5_hl -lhdf5 -lz
Note that the NETCDFLIB is on one line on my file, and the paths of the variables are correct, but the syntax may not be.
Next for the fortran and c compiler information I have the following:
FC = gfortran -m64 -g -O0 -ffixed-line-length-132 -Wunused -Wuninitialized
CC = gcc
CFLAGS = -m64 -c -g -I. -DLONG32 -DUNDERSCORE -DLITTLE -Wunused -
Wuninitialized
Finally, when I run the program I first get a bunch of warnings such as:
oban_namelist.f90:495.29:
real :: flt
1
Warning: Unused variable 'flt' declared at (1)
Followed by a bunch of undefined reference errors such as:
oban.o: In function `check':
/uufs/chpc.utah.edu/common/home/zpu-
group3/dhodges/DART/data/radar/opaws/oban.f90:1902: undefined reference to
`__netcdf_MOD_nf90_strerror'
The error shouldn't be in this oban.o function since I didn't write it. The only things I have edited in the program I listed above for the netcdf path and gfortran/c information and so I think the error lies there. This is my first question on here, so if I missed anything you need feel free to ask. What can I try?
Edit: By request, this is the entire makefile I am using. Also, I just type 'make' to compile it per the instructions in the README file.
# Makefile for creating the OPAWS analysis software
#
# Rev: 02/05/10 LJW
# 12/05/10 DCD
# 02/11/11 LJW
#
# netCDF4 libs - you need to fill in the blanks
NETCDFINC = -I$(NETCDFF_INCDIR) -I$(NETCDFC_INCDIR)
NETCDFLIB = -Wl,-rpath=$(NETCDFF_LIBDIR) -L$(NETCDFF_LIBDIR) -Wl,-rpath=$(NETCDFC_LIBDIR) -L$(NETCDFC_LIBDIR) -Wl,-rpath=$(HDF5_LIBDIR) -
L$(HDF5_LIBDIR) -lhdf5_hl -lhdf5 -lz
# Fortran and C compiler information - various configurations are setup, try and find one close
#=====>> Gfortran
#
FC = gfortran -m64 -g -O0 -ffixed-line-length-132 -Wunused -Wuninitialized
CC = gcc
CFLAGS = -m64 -c -g -I. -DLONG32 -DUNDERSCORE -DLITTLE -Wunused -Wuninitialized
# Leave this stuff alone
EXEC = x.oban
EXECcs = x.clutter_stats
EXECmd = mosaic_2_dart
OBJS = DART.o oban_module.o dict_module.o oban_namelist.o derived_types.o util.o fileio.o read_dorade.o binio.o v5d.o
OBJScs = DART.o dict_module.o oban_namelist.o derived_types.o fileio.o util.o read_dorade.o binio.o v5d.o
OBJSmd = DART.o dict_module.o oban_namelist.o derived_types.o fileio.o util.o read_dorade.o binio.o v5d.o
default: $(EXEC) $(EXECcs) $(EXECmd)
$(EXEC): $(OBJS) oban.o
$(FC) $(OPT) -o $(EXEC) oban.o $(OBJS) $(NETCDFLIB)
$(EXECcs): $(OBJScs) clutter_stats.o
$(FC) $(OPT) -o $(EXECcs) clutter_stats.o $(OBJScs) $(NETCDFLIB)
$(EXECmd): $(OBJSmd) mosaic_2_dart.o
$(FC) $(OPT) -o $(EXECmd) mosaic_2_dart.o $(OBJSmd) $(NETCDFLIB)
clean:
rm $(EXEC) oban.o $(OBJS) $(EXECcs) clutter_stats.o $(OBJScs) $(EXECmd) mosaic_2_dart.o $(OBJSmd) *.mod ncgen.input *.pyc sweep_file_list.txt
# Individual compilation instructions
oban.o: oban.f90 structures.inc opaws.inc DART.o
$(FC) $(OPT) -c $(NETCDFINC) oban.f90
clutter_stats.o: clutter_stats.f90 opaws.inc
$(FC) $(OPT) -c $(NETCDFINC) clutter_stats.f90
mosaic_2_dart.o: mosaic_2_dart.f90 opaws.inc
$(FC) $(OPT) -c $(NETCDFINC) mosaic_2_dart.f90
oban_module.o: oban_module.f90 derived_types.o opaws.inc
$(FC) $(OPT) -c oban_module.f90
read_dorade.o: read_dorade.c read_dorade.h
$(CC) $(CFLAGS) -c read_dorade.c
fileio.o: fileio.f90
$(FC) $(OPT) $(NETCDFINC) -c fileio.f90
util.o: util.f opaws.inc structures.inc
$(FC) $(OPT) -c util.f
DART.o: DART.f
$(FC) $(OPT) -c DART.f
derived_types.o: derived_types.f90
$(FC) $(OPT) -c derived_types.f90
oban_namelist.o: oban_namelist.f90 opaws.inc
$(FC) $(OPT) -c oban_namelist.f90
dict_module.o: dict_module.f90
$(FC) $(OPT) -c dict_module.f90
binio.o: binio.c
$(CC) $(CFLAGS) binio.c -o binio.o
v5d.o: v5d.c
$(CC) $(CFLAGS) v5d.c -o v5d.o
The problem was solved by editing the NETCDFLIB line as follows:
I edited the NETCDFLIB line as follows and it works: NETCDFLIB = -Wl,-
rpath=$(NETCDFF_LIBDIR) -L$(NETCDFF_LIBDIR) -Wl,-rpath=$(NETCDFC_LIBDIR) -
L$(NETCDFC_LIBDIR) -lnetcdff -lnetcdf -lm -Wl,-rpath=$(HDF5_LIBDIR) -
L$(HDF5_LIBDIR) -lhdf5_hl -lhdf5 -lz
Basically I just needed to add:
-lnetcdff -lnetcdf -lm
This allowed for the compiler to get access to the libraries it needed that were originally undefined.
I am trying to use matlab libmat.dll in a C application. To compile my C application I use MinGW, for now I use matlab exemple "matcreate.c" and try to compile it, so the projects consist of only one file : main.c .
Here is the makefile I use :
MATINCLUDE = "C:\Program Files\MATLAB\R2010a\extern\include"
MATLIBRARY = "C:\Program Files\MATLAB\R2010a\bin\win64"
#
CC = gcc
LD = gcc
CFLAGS = -O3 -Wall
LFLAGS = -Wall -O3
LIBS = -I$(MATINCLUDE) -L$(MATLIBRARY)
#
PROG = matTest
LISTEOBJ = \
main.o
.c.o :
$(CC) -c $(CFLAGS) $(LIBS) -o $# $<
all : $(PROG)
$(PROG) : $(LISTEOBJ)
$(LD) -o $(PROG) $(LFLAGS) $(LISTEOBJ) $(LIBS)
clean :
rm -f *.obj
Here is what I get in the console
E:\Users\Desk\Dropbox\matTest>make
gcc -c -O3 -Wall -I"C:\Program Files\MATLAB\R2010a\extern\include" -L"C:\Pr
ogram Files\MATLAB\R2010a\bin\win64" -o main.o main.c
gcc -o Hello_world -Wall -O3 main.o -I"C:\Program Files\MATLAB\R2010a\extern\i
nclude" -L"C:\Program Files\MATLAB\R2010a\bin\win64"
main.o:main.c:(.text.startup+0x48): undefined reference to `matOpen'
main.o:main.c:(.text.startup+0x6e): undefined reference to `mxCreateDoubleMatrix
_730'
e:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: main.o: ba
d reloc address 0x6e in section `.text.startup'
e:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: final link
failed: Invalid operation
collect2.exe: error: ld returned 1 exit status
make: *** [Hello_world] Error 1
Why do I have "undefined reference to matOpen'" and "undefined reference to mxCreateDoubleMatrix" ?? those function are declared in mat.h. and I added #include "mat.h" to the begining of main.c
thank you
Looks like you have included the path to the matlab library, but not the library itself. You need to add a -l<libraryname> to your link line.
I have a directory called reliability:
ls reliability
analyze.c appl.sh constr.c creer.c greedys.c Makefile
Now I want to install and compile it:
First of all the content of Makefile is:
CC = gcc
CFLAGS = -g -Wall -pthread
SRCS = constr.c creer.c analyze.c greedys.c
PROG = constr creer analyze greedys
all: $(PROG)
constr: constr.c
$(CC) $(CFLAGS) -o constr constr.c
creer: creer.c
$(CC) $(CFLAGS) -o creer creer.c
analyze: analyze.c
$(CC) $(CFLAGS) -o analyze analyze.c
greedys: greedys.c
$(CC) $(CFLAGS) -o greedys greedys.c
clean:
rm -f $(PROG)
When I start compiling it:
make -f Makefile
The error occurs:
gcc -g -Wall -pthread -o constr constr.c
/tmp/cca4NKQl.o: In function `main':
/home/t1/Desktop/reliability/constr.c:89: undefined reference to `exp'
/home/t1/Desktop/reliability/constr.c:89: undefined reference to `exp'
/home/t1/Desktop/reliability/constr.c:89: undefined reference to `pow'
/home/t1/Desktop/reliability/constr.c:89: undefined reference to `log'
collect2: ld returned 1 exit status
make: *** [constr] Error 1
I pass these errors by adding -lm to gcc,
Even when I change CFLAGS from Makefile to CFLAGS = -g -Wall -pthread -lm there is also that error.
My question:
Should I compile all .c programs separately now?
Thank you I really need help,
UPDATE
When I compile creer.c there is an error:
creer.c:39:10: warning: unused variable ‘val2’ [-Wunused-variable] creer.c:38:7:
warning: unused variable ‘val’ [-Wunused-variable]
Part of creer.c is:
void values(){
int val;
double val2;
FILE *fp;
fp = fopen("instances","r");
fseek(fp,0,SEEK_SET);
if(fscanf(fp,"%d",&p)==EOF){printf("EOF\n");}
if(fscanf(fp,"%d",&m)==EOF){printf("EOF\n");}
if(fscanf(fp,"%d",&K)==EOF){printf("EOF\n");}
if(fscanf(fp,"%lf",&lambda_com)==EOF){printf("EOF\n");}
if(fscanf(fp,"%d",&num_inst)==EOF){printf("EOF\n");}
if(fscanf(fp,"%d",&boundl)==EOF){printf("EOF\n");}
if(fscanf(fp,"%d",&boundp)==EOF){printf("EOF\n");}
fclose(fp);
}
You need to add that linker option -lm to the end of your command line.
Do something like this:
LDFLAGS=-lm
...
constr: constr.c
$(CC) $(CFLAGS) -o constr constr.c $(LDFLAGS)
Or you could define a pattern rule:
%: %.c
$(CC) $(CFLAGS) -o $# $< $(LDFLAGS)
and use it to replace all those rules for constr, creer, and so on.
#include<stdio.h>
#include "flite.h"
cst_voice *register_cmu_us_kal();
int main()
{
cst_voice *v;
cst_wave *w;
char *text = "Hello world programming";
//Initialising the flite variables used
flite_init();
w = new_wave();
v = register_cmu_us_kal(NULL);
flite_text_to_speech(text,v,"hello_wave");
if(cst_wave_load_riff(w,"hello_wave")!=CST_OK_FORMAT){
printf("\nCompare_wave:Can read file or wrong format!\n");
}
else{
play_wave(w);
}
return 0;
}
Makefile
all:compile \
./compile
compile:eg1.o
gcc -o $# eg1.o
eg1.o:eg1.c $(LIBS_DIR) $(INC_DIR) $(LIBS)
gcc -c $<
LIBS_DIR = -L /home/b/flite-1.4-release/build/i386-linux-gnu/lib
INC_DIR = -I /home/b/flite-1.4-relase/include
LIBS = -lflite_cmu_us_slt -lflite -lflite_cmulex -lflite_cmu_time_awb -lflite_cmu_us_kal16 -lflite_cmu_us_kal -lflite_cmu_usenglish
INCLUDE:
clean:
rm -f *.o
I tried by giving he library and header file paths as LIBS_DIR = ../build/i386-linux-gnu/lib and INC_DIR = ../include
I tried the folowing c program by including a third party library. This program an a makefile is located in b\flite-1.4-release\Learnin_though_example folder. Th flite libraries are located in b\flite-1.4-release\build\i386-linux-gnu\lib and the header files are in b\flite-1.4-release\include .
I assume that i have given the makefile th correct path to search for the files. But its not identifyin it and i'm gettin an error as,
make clean all
rm -f *.o
gcc -c eg1.c
eg1.c:2:19: error: flite.h: No such file or directory
eg1.c:3: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token
eg1.c: In function ‘main’:
eg1.c:6: error: ‘cst_voice’ undeclared (first use in this function)
eg1.c:6: error: (Each undeclared identifier is reported only once
eg1.c:6: error: for each function it appears in.)
eg1.c:6: error: ‘v’ undeclared (first use in this function)
eg1.c:7: error: ‘cst_wave’ undeclared (first use in this function)
eg1.c:7: error: ‘w’ undeclared (first use in this function)
eg1.c:17: error: ‘CST_OK_FORMAT’ undeclared (first use in this function)
make: *** [eg1.o] Error 1
Please help me understand what is the mistake i'm doing
EDITED:
I modiied th makefile as per matt's guidance:
all:compile
compile:eg1.o
gcc $(INC_DIR) $(LIB_DIR) -o $# $^ $(LIBS)
eg1.o:eg1.c
gcc $(INC_DIR) -o $# -c $^
LIBS_DIR = -L../build/i386-linux-gnu/lib
INC_DIR = -I../include
LIBS = -lflite -lflite_cmulex -lflite_cmu_time_awb -lflite_cmu_us_kal16 -lflite_cmu_us_kal -lflite_cmu_usenglish -lflite_cmu_us_slt
clean:
rm -f *.o
but i'm getting ifferent error whn compiled with the command "make clean all" as,
rm -f *.o
gcc -I../include -o eg1.o -c eg1.c
gcc -I../include -o compile eg1.o -lflite -lflite_cmulex -lflite_cmu_time_awb -lflite_cmu_us_kal16 -lflite_cmu_us_kal -lflite_cmu_usenglish -lflite_cmu_us_slt
/usr/bin/ld: cannot find -lflite
collect2: ld returned 1 exit status
make: *** [compile] Error 1
EDITED:
rm -f *.o
gcc -I../include -o eg1.o -c eg1.c
gcc -I../include -L../build/i386-linux-gnu/lib -o compile eg1.o -lflite -lflite_cmulex -lflite_cmu_time_awb -lflite_cmu_us_kal16 -lflite_cmu_us_kal -lflite_usenglish -lflite_cmu_us_slt -lflite_cmu_us_rms
../build/i386-linux-gnu/lib/libflite.so: undefined reference to `sin'
../build/i386-linux-gnu/lib/libflite.so: undefined reference to `exp'
../build/i386-linux-gnu/lib/libflite.so: undefined reference to `sqrt'
../build/i386-linux-gnu/lib/libflite.so: undefined reference to `log'
../build/i386-linux-gnu/lib/libflite.so: undefined reference to `fmod'
../build/i386-linux-gnu/lib/libflite.so: undefined reference to `pow'
Your makefile is, I'm afraid to say, completely broken.
The basic Makefile syntax is:
target: pre-requisite(s)
<tab>Stuff to do to build target from pre-reqs (if required)
So this is wrong, eg1.o can't be a pre-requisite for building itself.
compile:eg1.o
gcc -o eg1.o
You should have:
eg1.o: eg1.c
gcc $(INC_DIR) -o $# -c $^
($# is the target, $^ all the pre-reqs.)
Then you can:
myexe: eg1.o
gcc $(INC_DIR) $(LIBS_DIR) -o $# $^ $(LIBS)
This will produce myexe from eg1.o. And your all rule should be all: myexe, with no recipe (no commands), and at the top as you have it.
Then you've got your include directories and library directories mixed up. -I is for include paths, -L for library paths.
Place your variable definitions before the rules, that's more common/usual. And don't put a space between -L/-I and the path that follows it.
The include directories to search is specified by -I flag, not -L.
Change:
LIBS_DIR = -I /home/b/flite-1.4-release/build/i386-linux-gnu/lib
INC_DIR = -L /home/b/flite-1.4-relase/include
to:
LIBS_DIR = -L /home/b/flite-1.4-release/build/i386-linux-gnu/lib
INC_DIR = -I /home/b/flite-1.4-relase/include