I am trying to compile a library with autotools. The library compiles fine with the following Makefile.am in its source directory library/src
lib_LTLIBRARIES = libgtkchart.la
libgtkchart_la_CFLAGS = $(CFLAGS) -fPIC -Wall $(gtk_CFLAGS)
libgtkchart_la_LIBADD = $(gtk_LIBS) $(glib_LIBS)
libgtkchart_la_LDFLAGS = -fPIC -shared -version-info 1:0:0
libgtkchart_la_SOURCES = gtkchart.c gtkaxis.c gtkbarchart.c gtkchartdata.c gtkchart.h gtkaxis.h gtkbarchart.h gtkbarchartdata.h
but if I add the following line to that file:
include_HEADERS = gtkaxis.h gtkbarchart.h gtkbarchartdata.h gtkchart.h
I get the following error:
make[2]: *** No rule to make target 'gtkbarchartdata.h', needed by 'all-am'. Stop.
My main MAkefile.am in library/ is
SUBDIRS = src
ACLOCAL_AMFLAGS= -I m4
and my configure.ac is
AC_CONFIG_MACRO_DIRS([m4])
AC_INIT([library], [1.0], [me])
AM_PROG_AR
AM_INIT_AUTOMAKE([-Wall -Werror foreign])
AC_PROG_CC
AC_DISABLE_STATIC
AC_PROG_LIBTOOL
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_FILES([
Makefile
src/Makefile
])
LT_INIT
AC_OUTPUT
I can't figure out why the need for a target for that header file.
When you assign header files to the include_HEADERS, automake must
be able to locate the header.
For example, if you have the following directory structure:
src
Makefile.am
GTKBarCharDataDirectory
SomeOtherDirectory
gtkaxis.h
gtkbarchart.h
gtkchart.h
And gtkbarchartdata.h is located in the GTKBarCharDataDirectory directory, then you need to change your include_Headers to be:
include_HEADERS = gtkaxis.h gtkbarchart.h GTKBarCharDataDirectory/gtkbarchartdata.h gtkchart.h
make must know the relative path of the header file, when using the include_Headers variable. This is due to the fact that the HEADER family of variables works differently than the SOURCES family of variables.
automake won't fail if you list a non-existent/not-found header file
in the libgtkchart_la_SOURCES variable, since Header files listed in
a _SOURCES definition will be included in the distribution but
otherwise ignored.
Check here and here for a reference
Related
I'm trying to organize the files of my project, as all of them are in the root directory, and change the Makefile, as it is too long and very repetitive. So I make the following 3 directories:
include : Contains all of the .h files
src : Contains all of the .c files
obj : It is empty for the moment but after compilation, it will contain all of the .o files
So my first goal was to make the .o files and put them in the /obj directory and the Makefile I made is the following :
#paths
INCLUDE = include
SOURCE = src
OBJS = obj
# compiler
CC = gcc
#flags
CFLAGS = -Wall -g -pedantic -I$(INCLUDE)
VFLAGS = --leak-check=full -v
OB = $(OBJS)/space.o $(OBJS)/command.o $(OBJS)/screen.o $(OBJS)/graphic_engine.o $(OBJS)/game.o $(OBJS)/object.o $(OBJS)/player.o $(OBJS)/game_reader.o $(OBJS)/die.o $(OBJS)/set.o $(OBJS)/inventory.o $(OBJS)/link.o $(OBJS)/game_loop.o
build: $(OB)
$(OBJS)/%.o: $(SOURCE)/%.c $(INCLUDE)/%.h
$(CC) -c $< $(CFLAGS) -o $#
When I run it, all the .o files are made and placed in the obj directory but the last and I get the folloing error :
make: *** No rule to make target 'obj/game_loop.o', needed by 'build'. Stop.
In the OB variable, I changed the position of the game_loop and noticed that the previous .o files were made and the compilation stopped again at the game_loop file.
I want help to overcome this error and help to continue making the
Makefile
I am having an issue with this makefile giving the fatal error: "Don't know how to make target calc.o". The naming is correct along with being in the working directory, and the other issue is that when I switch the order of the object files for default target file it will say it does not know how to make that target either, so the order does not seem to change anything or be one specific file. I am running the make command on a sun sparc unix server as well. The makefile is pasted below:
#The following rule tells make about possible suffixes
#(extensions) of file names.
.SUFFIXES: .c .o
#The following definition of CC ensures that
#gcc will be used to compile the C source files.
CC = gcc
#The following definition of CFLAGS ensures that
#the debugger can be used with the executable file (p1)
#created by running make.
CFLAGS = -g
#The following rule tells make how a ".o" file should
#be created from the corresponding ".c" file.
#Note that the "-c" option must be used here since we are
#compiling source files separately. (Note that the line
#following the ".c.o:" line begins with the "tab" character.)
.c.o:
$(CC) $(CFLAGS) -c $<
#Dependency rule for the default target and how the
#default target is to be created. (Note that the line
#following the dependency rule begins with the "tab"
#character.)
p2: main.o textToBin.o binToText.o calc.o
gcc main.o textToBin.o binToText.o calc.o -o p2
#Dependency rules for other targets. (We don't need to
#specify how these targets are created since we have already
#given a general rule for creating a ".o" file from the
#corresponding ".c" file.)
#NO HEADER FILES
#Target for removing unnecessary files.
clean:
rm -f *.o core
I am having a 1.c 2.c....n.c files and having its dependencies .h file also... i know to create make file for multiple c files.But i don't how to create make file for which the c files are linking to .h files. If i try the makefile which i know it will give error like
make: *** No rule to make target '2.h', needed by '2.o' .Stop.
and I don't need this type of makefile also.
program: main.o dbAdapter.o
gcc -o program main.o dbAdapter.o
main.o: main.c dbAdapter.h
gcc -c main.c
dbAdapter.o dbAdapter.c dbAdapter.h
gcc -c dbAdapter.c
This will be good for 4 or 5 files. But if I have a large number of files, what is the best solution?
You can link all your .h in the Makefile by this way :
Put all the .h in a same file (that we called "Include" for the exemple)
Add this in your Makefile : gcc *.c -I/path/Include -iInclude
Ps: Your way to compile your .c file is a bit strange.
Usually we use this:
SRC = 1.c
2.c
n.c
OBJ = $(SRC:.c=.o)
all: $(OBJ)
gcc $(SRC) -I/path/Include -iInclude (where path is the location of your file called "Include")
As long as I'm working with C, I never wrote make files that includes header files (.h) the header files are here to expose some of the data structure and methods, constants that are needed in other C modules.
You don't need to create rules for header files, all you have to do is build the .o objects then the liker will do the magic for you when you create the executable file.
If you need some help crating a make file you can explain here what you wanna build and I'll send you a hint.
Cheers.
If your header files are not in current directory and you included it in Makefile, Make starts looking for header files in default location but it is not able to find them in your case.
you should put 2.h header files in current directory to avoid this search.
I'm trying to include the generation of the cmdline.c file (from gengetopt's defaults) in my Makefile.am file.
The file currently reads like these:
bin_PROGRAMS = myprog
myprog_SOURCES = main.c cmdline.c
myprog_DEPENDENCIES = gen_cmdline $(myprog_SOURCES) # somewhere I read that setting DEPENDENCIES inhibits automake from calculating those
gen_cmdline:
gengetopt < myprog.ggo
However, if I modify just myprog.ggo, the cmdline.c and all its dependents won't get recompiled. What am I missing here?
Is gen_cmdline a .PHONY target? If gengetopt creates a file named cmdline.c, then your Makefile.am should probably look like:
bin_PROGRAMS = myprog
myprog_SOURCES = main.c cmdline.c
BUILT_SOURCES = cmdline.c
cmdline.c: myprog.ggo
gengetopt < $(srcdir)/myprog.ggo
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Linking apache libraries
gcc 4.4.2 c89
I am trying to link some headers and libraries in my header file. But for some reason my program doesn't seem to link.
I have in my directory src/include/apr src/libs
I have compiled the libraries and placed them in my libs and I have put the headers in the include directory.
My executable is in the src directory.
In my makefile I have specified this:
LIBS_PATH -L./lib
INC_PATH -I./include
LIBS = -libapr-1
So the current directory to where the executable is executed from.
In my lib folder I have the following library called:
libapr-1.so
And in my include/apr folder I have the following header file:
apr.h
The program is getting the header files. But I don't think it is linking the library as I don't get any errors saying that it can't find the header file.
In the file where I include the header I have done this
#include <apr/apr.h>
I do get this following error message:
In file included from include/apr.h:17,
./include/apr/apr.h:285: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘apr_int32_t’
Many thanks for any suggestions and advice,
EDIT:
LIBS_PATH -L./lib
INC_PATH -I./include
LIBS = -lapr
Error:
/usr/bin/ld: cannot find -lapr
Makefile:
OBJECT_FILES = dlg_fsm.o
CFLAGS = -ggdb -Wall
FLATFORM = -DLINUX
CC = gcc
LIBS_PATH = -L./lib
INC_PATH = -I./include
LIBS = -lapr
dlg: $(OBJECT_FILES)
$(CC) $(CFLAGS) $(LDFLAGS) $(OBJECT_FILES) $(FLATFORM) $(INC_PATH) $(LIBS_PATH) $(LIBS) -o dlg
This has nothing to do with libraries, and may have nothing to do with paths. The compiler thinks there is a syntax error at the line indicated - please post that line, and the ones surrounding it, using copy and paste.
Once you've fixed the syntax error in your code, you'll want to change LIBS to contain -lapr-1, since the linker adds the "lib" prefix itself.
Either there is a syntax error in apr.h or probably apr.h expects something to be included before itself.
For example:
you write header file abc.h which uses strlen(...), but do not include string.h inside abc.h . If you want to include abc.h in file xxx.c, you have to include string.h in xxx.c before abc.h manually to make sure that abc.h has access to the declaration of strlen(...)
Most likely the compiler doesn't know what apr_int32_t means, whereas it should. You should post line 285 of apr.h.
Edit: I think when you say:
And in my include/apr folder I have the following header file: apr.h
that might be what's wrong. You should not have an apr.h file in your local directory—it's a file from APR. So, try renaming the file include/apr/apr.h to something else (unless by include/apr you meant your system include directory).
Edit 2:
LIBS_PATH -L./lib
INC_PATH -I./include
From the above, looks like you're in the apr source directory. Please install apr by typing make install in the apr directory, and then use the installed files in /usr/include/apr and /usr/lib/libapr* to build your program. You should not have your local source and include directories in the apr directory.