I have a problem with Makefile. It should compile a .c file to an object file only if the .c file has been modified.
But I have an error when I use all rule:
make: *** No rule to make target `obj/main.o', needed by `ft_ls'. Stop.
When I use manually it works:
clang -Wall -Wextra -Werror -Iinclude -o obj/main.o -c src/main.c
My work directory:
Makefile include/*.h libft/libft.a src/*.c
Makefile content:
NAME = ft_ls
SRC_PATH = src
OBJ_PATH = obj
CPPFLAGS = -Iinclude
LDFLAGS = -Llibft
LDLIBS = -lft
CFLAGS = -Werror -Wall -Wextra
CC = clang
SRC_NAME = main.c\
ft_type.c\
ft_right.c\
ft_putright.c\
ft_date_converter.c
OBJ_NAME = $(SRC_NAME:.c=.o)
SRC = $(addprefix $(SRC_PATH)/,$(SRC_NAME))
OBJ = $(addprefix $(OBJ_PATH)/,$(OBJ_NAME))
all: $(NAME)
$(NAME): $(OBJ)
$(CC) $(LDFLAGS) $(LDLIBS) $^ -o $#
make -C libft
$(OBJ_PATH)%.o: $(SRC_PATH)%.c
#mkdir $(OBJ_PATH) 2> /dev/null || true
$(CC) $(CFLAGS) $(CPPFLAGS) -o $# -c $<
clean:
rm -fv $(OBJ)
make -C libft clean
#rmdir $(OBJ_PATH) 2> /dev/null || true
fclean: clean
rm -fv $(NAME)
make -C libft fclean
re: fclean all
.PHONY: all, clean, fclean, re
this dependency line:
$(OBJ_PATH)%.o: $(SRC_PATH)%.c
concatenates $(OBJ_PATH) with the object name, but there's a / missing, should be
$(OBJ_PATH)/%.o: $(SRC_PATH)/%.c
else it expands (ex: for main) to:
objmain.o : srcmain.c
Related
I'm on 6.18 of LFS.
https://linuxfromscratch.org/lfs/view/stable-systemd/chapter06/gcc-pass2.html
But I keep getting the error below.
g++ -fno-PIE -c -g -O2 -DIN_GCC -fno-exceptions -fno-rtti -fasynchronous-unwind-tables -W -Wall -Wno-narrowing -Wwrite-strings -Wcast-qual -Wmissing-format-attribute -Woverloaded-virtual -pedantic -Wno-long-long -Wno-variadic-macros -Wno-overlength-strings -DHAVE_CONFIG_H -I. -I. -I../.././gcc -I../.././gcc/. -I../.././gcc/../include -I../.././gcc/../libcpp/include -I../.././gcc/../libcody -I/mnt/lfs/sources/gcc-12.2.0/host-x86_64-lfs-linux-gnu/gmp -I/mnt/lfs/sources/gcc-12.2.0/gmp -I/mnt/lfs/sources/gcc-12.2.0/host-x86_64-lfs-linux-gnu/mpfr/src -I/mnt/lfs/sources/gcc-12.2.0/mpfr/src -I/mnt/lfs/sources/gcc-12.2.0/mpc/src -I../.././gcc/../libdecnumber -I../.././gcc/../libdecnumber/dpd -I../libdecnumber -I../.././gcc/../libbacktrace -o insn-recog.o -MT insn-recog.o -MMD -MP -MF ./.deps/insn-recog.TPo insn-recog.cc
x86_64-lfs-linux-gnu-gcc -dumpspecs > tmp-specs
/bin/sh: line 1: x86_64-lfs-linux-gnu-gcc: command not found
make[2]: *** [Makefile:2185: specs] Error 127
make[2]: *** Waiting for unfinished jobs....
rm gcc.pod
make[2]: Leaving directory '/mnt/lfs/sources/gcc-12.2.0/host-x86_64-lfs-linux-gnu/gcc'
make[1]: *** [Makefile:4621: all-gcc] Error 2
make[1]: Leaving directory '/mnt/lfs/sources/gcc-12.2.0'
make: *** [Makefile:1036: all] Error 2
Im using this function to build:
function gcc2() {
export BUILD_DIR=/mnt/lfs/sources ## This si usualy at top of file but added it for this examples sake.
#https://linuxfromscratch.org/lfs/view/stable-systemd/chapter06/gzip.html
cd $BUILD_DIR && tar -vxkf gcc-12.2.0.tar.xz && cd gcc-12.2.0
$BUILD_DIR/gcc-12.2.0/contrib/download_prerequisites
rm -rf $BUILD_DIR/gcc-12.2.0/isl*
case $(uname -m) in
x86_64)
sed -e '/m64=/s/lib64/lib/' -i.orig $BUILD_DIR/gcc-12.2.0/gcc/config/i386/t-linux64
;;
esac
sed '/thread_header =/s/#.*#/gthr-posix.h/' -i $BUILD_DIR/gcc-12.2.0/libgcc/Makefile.in libstdc++-v3/include/Makefile.in
if ! [[ -d "$BUILD_DIR/gcc-12.2.0/build" ]]; then
mkdir $BUILD_DIR/gcc-12.2.0/build && cd $BUILD_DIR/gcc-12.2.0/build
fi
$BUILD_DIR/gcc-12.2.0/build/../configure --build=$(../config.guess) --host=$LFS_TGT --target=$LFS_TGT LDFLAGS_FOR_TARGET=-L$PWD/$LFS_TGT/libgcc --prefix=/usr --with-build-sysroot=$LFS --enable-initfini-array --disable-nls --disable-multilib --disable-decimal-float --disable-libatomic --disable-libgomp --disable-libquadmath --disable-libssp --disable-libvtv --enable-languages=c,c++
make && make DESTDIR=$LFS install && ln -sv gcc $LFS/usr/bin/cc
}
My env looks like this:
lfs:/mnt/lfs/sources/gcc-12.2.0$ env
PWD=/mnt/lfs/sources/gcc-12.2.0
HOME=/home/lfs
MAKEFLAGS=-j8
TERM=screen
SHLVL=1
PS1=\u:\w\$
LFS_TGT=x86_64-lfs-linux-gnu
LC_ALL=POSIX
LFS=/mnt/lfs
CONFIG_SITE=/mnt/lfs/usr/share/config.site
PATH=/mnt/lfs/tools/bin:/usr/bin
_=/usr/bin/env
OLDPWD=/mnt/lfs/sources/gcc-12.2.0/build
lfs:/mnt/lfs/sources/gcc-12.2.0$
I don't understand why its failing. Where have I gone wrong?
I have written a make file as following:
COMPFLAGS = -O3 -autodouble
CFLAGS = $(COMPFLAGS)
PFLAGS = $(COMPFLAGS)
FFLAGS = $(COMPFLAGS)
CCFLAGS = $(COMPFLAGS)
CXXFLAGS = $(COMPFLAGS)
LD = ifort
LDFLAGS = $(COMPFLAGS)
MAKEFILE = Makefile
OBJS = f1.o \
f2.o \
f3.o \
PROGRAM = f1
all: $(PROGRAM)
%.o: %.f90
#$(LD) $(COMPFLAGS) -c $<
$(PROGRAM): $(OBJS) $(MAKEFILE)
#$(LD) $(LDFLAGS) $(OBJS) -o $(PROGRAM)
#echo "done"
clean:
#rm -f $(OBJS) core
when I execute make I get the following error:
f77 -O3 -autodouble -c -o f1.o f1.f
/usr/bin/f77: Illegal option: -autodouble
make: *** [f1.o] Error 255
I should note that there is no *.f file, all files are *.f90.
Could you please advise me where I have made mistake?
Thanks a lot.
This looks unusual:
LD = ifort
...
%.o: %.f90
#$(LD) $(COMPFLAGS) -c $<
LD is the linker, not the compiler. Perhaps something like:
CC = ifort
...
%.o: %.f90
#$(CC) -std=f90 $(COMPFLAGS) -c $<
You might also need the -x option to tell the machinery is Fortran 90 and not something to be preprocessed:
%.o: %.f90
#$(CC) -x f90 -std=f90 $(COMPFLAGS) -c $<
I have a C program that I want to compile it for RISCV ISA. I have followed their instruction for installing the tools. Their tools work correctly and I can compile a "Hello world!" C program and run it. But right now I want to compile another C program that contains multiple files. I tried to change the makefile and instead of using gcc, I replace it with their compiler name riscv64-unknown-linux-gnu-gcc but I got:
Relocations in generic ELF (EM: 62)
error, then I tried to set CC = riscv64-unknown-linux-gnu-gcc but I got another error about pthread
unrecognized command line option '-pthread'
My question is that should I change the make file to use their compiler?
Thanks for your help in advance.
DEBUG := 0
PROFILE := 0
MRSFAST_VERSION := "3.3.1"
BUILD_DATE := "$(shell date)"
all: OPTIMIZE_FLAGS build
debug: DEBUG_FLAGS build
profile: PROFILE_FLAGS build
build: clean-executable SSE_FLAGS compile mrsfast snp_indexer clean
LDFLAGS=#-static
LIBS=-lz -lm -pthread -lpthread
CFLAGS=-fno-pic -DMRSFAST_VERSION=\"$(MRSFAST_VERSION)\" -DBUILD_DATE=\"$(BUILD_DATE)\"
objects=baseFAST.o Sort.o MrsFAST.o Common.o CommandLineParser.o RefGenome.o HashTable.o Reads.o Output.o SNPReader.o HELP.o
compile: $(objects)
mrsfast:
ifeq ($(shell uname -s),Linux)
gcc -w $(objects) -o $# ${LDFLAGS} ${LIBS}
else
gcc -Wl,-no_pie -fno-pic -w $(objects) -o $# ${LDFLAGS} ${LIBS}
endif
snp_indexer: SNPIndexer.o
gcc $^ -o $# ${LDFLAGS} ${LIBS}
clean:
#rm -f $(objects)
#rm -f SNPIndexer.o
#rm -f HELPstub.c
#rm -f HELPstub.o
clean-executable:
#rm -f mrsfast
HELP.o:
#groff -Tascii -man ./HELP.man > HELP
ifeq ($(shell uname -s),Linux)
#ld -r -b binary -o HELP.o HELP
else
#touch HELPstub.c
gcc -o HELPstub.o -c HELPstub.c
ld -r -o HELP.o -sectcreate binary HELP HELP HELPstub.o
endif
DEBUG_FLAGS:
$(eval CFLAGS = $(CFLAGS) -ggdb)
$(eval LIBS = $(LIBS) -ggdb)
OPTIMIZE_FLAGS:
$(eval CFLAGS = $(CFLAGS) -O2)
PROFILE_FLAGS:
$(eval CFLAGS = $(CFLAGS) -pg -g)
$(eval LIBS = $(LIBS) -pg -g)
SSE_FLAGS:
ifeq ($(shell uname -s),Linux)
ifeq ($(with-sse4),no)
$(shell echo "-DSSE4=0")
else
$(eval CFLAGS = $(CFLAGS) \
$(shell gv=`gcc -dumpversion`; \
sc=`grep -c "sse4" /proc/cpuinfo`; \
echo $$sc.$$gv | awk -F. '{if($$1>0 && $$2>=4 && $$3>=4) print "-DSSE4=1 -msse4.2"; else print "-DSSE4=0"}'))
endif
else
ifeq ($(with-sse4),no)
$(shell echo "-DSSE4=0")
else
$(eval CFLAGS = $(CFLAGS) \
$(shell gv=`gcc -dumpversion`; \
sc=`sysctl -n machdep.cpu.features | grep -c "SSE4"` ;\
echo $$sc.$$gv | awk -F. '{if($$1>0 && $$2>=4 && $$3>=4) print "-DSSE4=1 -msse4.2"; else print "-DSSE4=0"}'))
endif
endif
I'm using the cross compiler (arm-none-linux-gnueabi) and I wanna build a libs3-2.0 source, but I get the following error when I try to compile.
libs3-2.0$ sudo make
make: *** No rule to make target `libxml/parser.h', needed by `build/obj/simplexml.do'. Stop.
What can I do to solve this issue? Below is the (GNU) Makefile.
working directory: /home/usrname/prj/app/framework/camera/cdma_manage/<br>
///////////////////////////////////////////////////////////////////////////////////////////
LIBS3_VER_MAJOR ?= 2
LIBS3_VER_MINOR ?= 0
LIBS3_VER := $(LIBS3_VER_MAJOR).$(LIBS3_VER_MINOR)
ifdef VERBOSE
VERBOSE = true
VERBOSE_ECHO = # echo
VERBOSE_SHOW =
QUIET_ECHO = # echo > /dev/null
else
VERBOSE = false
VERBOSE_ECHO = # echo > /dev/null
VERBOSE_SHOW = #
QUIET_ECHO = # echo
endif
ifndef BUILD
ifdef DEBUG
BUILD := build-debug
else
BUILD := build
endif
endif
ifndef DESTDIR
DESTDIR := /usr
endif
ifndef CURL_LIBS
CURL_LIBS := $(shell curl-config --libs)
endif
ifndef CURL_CFLAGS
CURL_CFLAGS := $(shell curl-config --cflags)
endif
ifndef LIBXML2_LIBS
LIBXML2_LIBS := $(shell xml2-config --libs)
endif
ifndef LIBXML2_CFLAGS
LIBXML2_CFLAGS := $(shell xml2-config --cflags)
endif
ifndef LIBXML2_LIBS
LIBXML2_LIBS := -L../libxml2-2.7.2/.libs -lxml2 -lm
endif
ifndef LIBXML2_CFLAGS
LIBXML2_CFLAGS := -I/home/usrname/prj/app/framework/camera/cdma_manage/libxml2-2.7.2/include
endif
ifndef CFLAGS
ifdef DEBUG
CFLAGS := -g
else
CFLAGS := -O3
endif
endif
CFLAGS += -Wall -Werror -Wshadow -Wextra -Iinc \
$(CURL_CFLAGS) $(LIBXML2_CFLAGS) \
-DLIBS3_VER_MAJOR=\"$(LIBS3_VER_MAJOR)\" \
-DLIBS3_VER_MINOR=\"$(LIBS3_VER_MINOR)\" \
-DLIBS3_VER=\"$(LIBS3_VER)\" \
-D__STRICT_ANSI__ \
-D_ISOC99_SOURCE \
-D_POSIX_C_SOURCE=200112L
LDFLAGS = $(CURL_LIBS) $(LIBXML2_LIBS) -lpthread
.PHONY: all
all: exported test
.PHONY: exported
exported: libs3 s3 headers
.PHONY: install
install: exported
$(QUIET_ECHO) $(DESTDIR)/bin/s3: Installing executable
$(VERBOSE_SHOW) install -Dps -m u+rwx,go+rx $(BUILD)/bin/s3 \
$(DESTDIR)/bin/s3
$(QUIET_ECHO) \
$(DESTDIR)/lib/libs3.so.$(LIBS3_VER): Installing shared library
$(VERBOSE_SHOW) install -Dps -m u+rw,go+r \
$(BUILD)/lib/libs3.so.$(LIBS3_VER_MAJOR) \
$(DESTDIR)/lib/libs3.so.$(LIBS3_VER)
$(QUIET_ECHO) \
$(DESTDIR)/lib/libs3.so.$(LIBS3_VER_MAJOR): Linking shared library
$(VERBOSE_SHOW) ln -sf libs3.so.$(LIBS3_VER) \
$(DESTDIR)/lib/libs3.so.$(LIBS3_VER_MAJOR)
$(QUIET_ECHO) $(DESTDIR)/lib/libs3.so: Linking shared library
$(VERBOSE_SHOW) ln -sf libs3.so.$(LIBS3_VER_MAJOR) $(DESTDIR)/lib/libs3.so
$(QUIET_ECHO) $(DESTDIR)/lib/libs3.a: Installing static library
$(VERBOSE_SHOW) install -Dp -m u+rw,go+r $(BUILD)/lib/libs3.a \
$(DESTDIR)/lib/libs3.a
$(QUIET_ECHO) $(DESTDIR)/include/libs3.h: Installing header
$(VERBOSE_SHOW) install -Dp -m u+rw,go+r $(BUILD)/include/libs3.h \
$(DESTDIR)/include/libs3.h
.PHONY: uninstall
uninstall:
$(QUIET_ECHO) Installed files: Uninstalling
$(VERBOSE_SHOW) \
rm -f $(DESTDIR)/bin/s3 \
$(DESTDIR)/include/libs3.h \
$(DESTDIR)/lib/libs3.a \
$(DESTDIR)/lib/libs3.so \
$(DESTDIR)/lib/libs3.so.$(LIBS3_VER_MAJOR) \
$(DESTDIR)/lib/libs3.so.$(LIBS3_VER)
$(BUILD)/obj/%.o: src/%.c
$(QUIET_ECHO) $#: Compiling object
# mkdir -p $(dir $(BUILD)/dep/$<)
# /opt/armv7/codesourcery/bin/arm-none-linux-gnueabi-gcc $(CFLAGS) -M -MG -MQ $# -DCOMPILINGDEPENDENCIES \
-o $(BUILD)/dep/$(<:%.c=%.d) -c $<
# mkdir -p $(dir $#)
$(VERBOSE_SHOW) /opt/armv7/codesourcery/bin/arm-none-linux-gnueabi-gcc $(CFLAGS) -o $# -c $<
$(BUILD)/obj/%.do: src/%.c
$(QUIET_ECHO) $#: Compiling dynamic object
# mkdir -p $(dir $(BUILD)/dep/$<)
# /opt/armv7/codesourcery/bin/arm-none-linux-gnueabi-gcc $(CFLAGS) -M -MG -MQ $# -DCOMPILINGDEPENDENCIES \
-o $(BUILD)/dep/$(<:%.c=%.dd) -c $<
# mkdir -p $(dir $#)
$(VERBOSE_SHOW) /opt/armv7/codesourcery/bin/arm-none-linux-gnueabi-gcc $(CFLAGS) -fpic -fPIC -o $# -c $<
LIBS3_SHARED = $(BUILD)/lib/libs3.so.$(LIBS3_VER_MAJOR)
LIBS3_STATIC = $(BUILD)/lib/libs3.a
.PHONY: libs3
libs3: $(LIBS3_SHARED) $(LIBS3_STATIC)
LIBS3_SOURCES := acl.c bucket.c error_parser.c general.c \
object.c request.c request_context.c \
response_headers_handler.c service_access_logging.c \
service.c simplexml.c util.c
$(LIBS3_SHARED): $(LIBS3_SOURCES:%.c=$(BUILD)/obj/%.do)
$(QUIET_ECHO) $#: Building shared library
# mkdir -p $(dir $#)
$(VERBOSE_SHOW) /opt/armv7/codesourcery/bin/arm-none-linux-gnueabi-gcc -shared -Wl,-soname,libs3.so.$(LIBS3_VER_MAJOR) \
-o $# $^ $(LDFLAGS)
$(LIBS3_STATIC): $(LIBS3_SOURCES:%.c=$(BUILD)/obj/%.o)
$(QUIET_ECHO) $#: Building static library
# mkdir -p $(dir $#)
$(VERBOSE_SHOW) $(AR) cr $# $^
... abbriviated.
//////////////////////////////////////////////////////////////////////////////////////////////
The issue seems to be that libxml/parser.h isn't found by make, but it's needed to build something else. Have you checked that this file is in the include paths?
ifndef LIBXML2_CFLAGS
LIBXML2_CFLAGS := -I/home/usrname/prj/app/framework/camera/cdma_manage/libxml2-2.7.2/include
endif
should added before
ifndef LIBXML2_CFLAGS
LIBXML2_CFLAGS := $(shell xml2-config --cflags)
endif
I am using following makefile
SHELL = /bin/sh
CXXFLAGS += -fPIC
TARGET = product_bridge.so
MYPRODUCT = /tmp/product
JAVASDK = /x86.linux/include/
CXXFLAGS += -I$(JAVASDK) -I$(JAVASDK)/linux -I$(GFCPP)/include -Wl,-rpath, -L$(MYPRODUCT)/lib -lmyproduct
SOURCES = $(shell echo *.cpp)
HEADERS = $(shell echo *.h)
OBJECTS = $(SOURCES:.cpp=.o)
all: $(TARGET)
$(TARGET): $(OBJECTS)
$(CXX) -shared $(CXXFLAGS) -o $(TARGET) $(OBJECTS)
clean:
rm -rf *.so *.o
When I build this on ubuntu i do not see myproduct in ldd. But I am doing the same on RHEL I see myproduct in ldd
My Shared library i.e. product_bridge.so is build on RHEL