ISO C, sprintf and decimal conversion grouped with thousands - c

I'm trying to do a simple sprintf like this:
snprintf(dest, maxlen_dest, "%'lu", along);
Note the quote: ' in the string.
This means (according to the manual):
' For decimal conversion (i, d, u, f, F, g, G) the output is to be
grouped with thousands’ grouping characters if the locale
information indicates any. Note that many versions of gcc(1) cannot
parse this option and will issue a warning. SUSv2 does not include
%'F.
So when I compile, I get this warning:
../common/utils.c:29: warning: ISO C does not support the ''' printf flag
../common/utils.c:29: warning: ISO C does not support the ''' printf flag
So, my question is: is there a function that "supports the ''' printf flag" I could use?
I want my output to be like:
51 254 234
1 424 000
...
...
...
Here's my Makefile (in case there's some options I should modify):
CC = gcc
# -g = all debug options
CFLAGS = -g -I../common -W -Wall -pedantic -std=c99
OBJECTS = o/main.o o/opts.o o/verif_liens_bidirectionnels.o o/ecriture.o o/plugin_utils.o o/plugin_algo_groupes.o ../common/o/cell.o ../common/o/utils.o ../common/o/verif.o ../common/o/lecture.o
gen : $(OBJECTS)
$(CC) -o gen $(OBJECTS) $(CFLAGS) -lm -lgd -lz
o/main.o : main.c
$(CC) -o $# -c main.c $(CFLAGS)
o/opts.o : opts.c opts.h
$(CC) -o $# -c opts.c $(CFLAGS)
o/verif_liens_bidirectionnels.o : verif_liens_bidirectionnels.c verif_liens_bidirectionnels.h
$(CC) -o $# -c verif_liens_bidirectionnels.c $(CFLAGS)
o/ecriture.o : ecriture.c ecriture.h
$(CC) -o $# -c ecriture.c $(CFLAGS)
o/plugin_utils.o : plugin_utils.c plugin_utils.h
$(CC) -o $# -c plugin_utils.c $(CFLAGS)
o/plugin_algo_groupes.o : plugin_algo_groupes.c plugin_algo_groupes.h
$(CC) -o $# -c plugin_algo_groupes.c $(CFLAGS)
../common/o/cell.o : ../common/cell.c ../common/cell.h
$(CC) -o $# -c ../common/cell.c $(CFLAGS)
../common/o/utils.o : ../common/utils.c ../common/utils.h
$(CC) -o $# -c ../common/utils.c $(CFLAGS)
../common/o/verif.o : ../common/verif.c ../common/verif.h
$(CC) -o $# -c ../common/verif.c $(CFLAGS)
../common/o/lecture.o : ../common/lecture.c ../common/lecture.h
$(CC) -o $# -c ../common/lecture.c $(CFLAGS)
clean :
rm $(OBJECTS)

You could add
../common/o/utils.o : CFLAGS := $(filter-out -pedantic,$(CFLAGS))
to the makefile, which should suppress the warning for the specific file.
If you don't want to rely on non-standard libc extensions, you'll have to implement the functionality yourself...

Related

Makefile - Only Makes One of Two Libs

I am new to makefile and am trying to compile several files.
First is called s-chat and the others are RWT (reader-writer) and DP (dining philosopher). They both use my list library, but s-chat needs it to compile with the -m32 flags.
This is what I tried to do: I called one libMonitor.a using lib-adders.o, lib_movers.o, lib_removers.o. The other one is liblist_32 using lib_adders_32.o, lib_removers_32.o, lib_movers_32.o. For some reason, only the first of these two libraries is made, and the other says it cannot find its first dependency.
PTHREADS = /student/cmpt332/pthreads
RTT = /student/cmpt332/rtt
CC = gcc
CFLAGS = -g
CPPFLAGS = -std=c90 -Wall -pedantic
.PHONEY: all clean
ARCH = $(shell uname -sm | tr -d ' ')
ifeq ($(ARCH),SunOS)
ARCH = $(PLATFORM)
PROCESSOR = "$(shell uname -p)"
ifeq ($(PROCESSOR),i386)
ARCH = i86pc
endif
endif
all: s-chat reader-writer-test dining-philosophers-test
RWT_OBJS = reader-writer_$(ARCH).o reader-writer-monitor_$(ARCH).o Monitor_$(ARCH).o libMonitor_$(ARCH).a
reader-writer-test: CPPFLAGS += -I$(PTHREADS)
reader-writer-test: LDFLAGS += -L$(PTHREADS)/lib/$(ARCH)
reader-writer-test: LDLIBS += -lpthreads
reader-writer-test: $(RWT_OBJS)
$(CC) $(LDFLAGS) $^ $(LDLIBS) -o $#
reader-writer_$(ARCH).o: reader-writer.c reader_writer_monitor.h Monitor.h
reader-writer-monitor_$(ARCH).o: reader-writer-monitor.c reader_writer_monitor.h Monitor.h
DP_OBJS = dining-philosophers_$(ARCH).o dining-philosophers-monitor_$(ARCH).o Monitor_$(ARCH).o libMonitor_$(ARCH).a
dining-philosophers-test: CPPFLAGS += -I$(PTHREADS)
dining-philosophers-test: LDFLAGS += -L$(PTHREADS)/lib/$(ARCH)
dining-philosophers-test: LDLIBS += -lpthreads
dining-philosophers-test: $(DP_OBJS)
$(CC) $(LDFLAGS) $^ $(LDLIBS) -o $#
dining-philosophers_$(ARCH).o: dining-philosophers.c dining_philosophers_monitor.h Monitor.h
dining-philosophers-monitor_$(ARCH).o: dining-philosophers-monitor.c dining_philosophers_monitor.h Monitor.h
Monitor_$(ARCH).o: Monitor.c Monitor.h
list_adders.o: list_adders.c list.h
list_movers.o: list_movers.c list.h
list_removers.o: list_removers.c list.h
libMonitor_$(ARCH).a: list_adders.o list_movers.o list_removers.o
ar rcs $# $^
list_adders_32.o: CFLAGS += -m32
list_adders_32.o: LDFLAGS += -m32
list_adders_32.o: list_adders.c list.h
list_movers_32.o: CFLAGS += -m32
list_movers_32.o: LDFLAGS += -m32
list_movers_32.o: list_movers.c list.h
list_removers_32.o: CFLAGS += -m32
list_removers_32.o: LDFLAGS += -m32
list_removers_32.o: list_removers.c list.h
liblist_32_$(ARCH).a: list_adders_32.o list_movers_32.o list_removers_32.o
ar rcs $# $^
s-chat: CPPFLAGS += -I$(RTT)/include
s-chat: CFLAGS += -m32
s-chat: LDFLAGS += -L$(RTT)/lib/$(ARCH) -m32
s-chat: LDLIBS += -lRtt -lRttUtils
s-chat: s-chat.o liblist_32_$(ARCH).a
s-chat.o: s-chat.c
%_$(ARCH).o %_32_$(ARCH).o %.o %_32.o: %.c
$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $# $<
%: %.o
$(CC) $(LDFLAGS) $(LDLIBS) $^ -o $#
clean:
rm -rf *.o *.a reader-writer-test dining-philosophers-test s-chat
This is the error I get:
ar rcs libMonitor_Linuxx86_64.a list_adders.o list_movers.o list_removers.o
ar: list_adders.o: No such file or directory
Makefile:66: recipe for target 'libMonitor_Linuxx86_64.a' failed
make: *** [libMonitor_Linuxx86_64.a] Error 1
And if I make s-chat last, libMonitor is made, but I get the exact same error with liblist_32 and it says it can't find list_adders_32.o
Anyone know what's going on and how to fix this?
Thanks in advance!!
https://www.gnu.org/software/make/manual/make.html#Pattern-Intro
If a pattern rule has multiple targets, make knows that the rule’s recipe is responsible for making all of the targets. The recipe is executed only once to make all the targets.
%_$(ARCH).o %_32_$(ARCH).o %.o %_32.o: %.c
$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $# $<
Should be something like
%_$(ARCH).o: %.c
$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $# $<
%_32_$(ARCH).o: %.c
$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $# $<
%.o: %.c
$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $# $<
%_32.o: %.c
$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $# $<
But since it seems like all of your sources are in the same directory anyway, you could just delete these rules completely because make already has a built-in rule for %.o: %.c.

GCC symbol lookup error

I try to launch my executable but i got this error:
.dudac/stage/monkey/lib/hello.duda: undefined symbol: DDS_sequence_BoardGlobalParameters_BoardGPSoftState__alloc
Whereas link and compile work fine
Here is my makefile:
# ====================================
# Date : Tue 21, Feb 2017 at 10:15
NAME = hello
CC = /opt/windriver/wrlinux-small/7.0-xxxxxx-3543dr/sysroots/x86_64-wrlinuxsdk-linux/usr/bin/arm-wrs-linux-gnueabi/arm-wrs-linux-gnueabi-gcc
CFLAGS = -g -Wall -DDEBUG -L/opt/PrismTech/Vortex_v2/Device/VortexOpenSpliceRTE/6.7.1p2/RTS/armv7at2_vfp_neon.WRlinux7_gcc/lib -ldcpssac -ldcpsisocpp2
#-g -Wall -DDEBUG -fPIC
LDFLAGS =
DEFS =
INCDIR = -I/home/T0181049/.dudac/stage/monkey//include/ -I/home/T0181049/.dudac/stage/monkey//src/include -I/home/T0181049/.dudac/stage/monkey//plugins/duda/src -I/home/T0181049/.dudac/stage/monkey//plugins/duda/ -I/opt/PrismTech/Vortex_v2/Device/VortexOpenSpliceRTE/6.7.1p2/HDE/armv7at2_vfp_neon.WRlinux7_gcc/include -I/opt/PrismTech/Vortex_v2/Device/VortexOpenSpliceRTE/6.7.1p2/HDE/armv7at2_vfp_neon.WRlinux7_gcc/include/dcps/C/SAC -I/opt/PrismTech/Vortex_v2/Device/VortexOpenSpliceRTE/6.7.1p2/HDE/armv7at2_vfp_neon.WRlinux7_gcc/include/sys -I/opt/PrismTech/Vortex_v2/Device/VortexOpenSplice/6.7.1p1/HDE/x86_64.linux/include -I/opt/PrismTech/Vortex_v2/Device/VortexOpenSplice/6.7.1p1/HDE/x86_64.linux/include/sys -I/opt/windriver/wrlinux-small/7.0-xxxxx-3543dr/sysroots/armv7at2-vfp-neon-wrs-linux-gnueabi/usr/include -I/opt/windriver/wrlinux-small/7.0-xxxxx-3543dr/sysroots/armv7at2-vfp-neon-wrs-linux-gnueabi/usr/include/c++ -I/opt/windriver/wrlinux-small/7.0-xxxxxx-3543dr/sysroots/armv7at2-vfp-neon-wrs-linux-gnueabi/usr/include/c++/4.9.1 -I/opt/windriver/wrlinux-small/7.0-xxxxxx-3543dr/sysroots/armv7at2-vfp-neon-wrs-linux-gnueabi/usr/include/c++/4.9.1/arm-windriverv7atneon-linux-gnueabi -I/opt/windriver/wrlinux-small/7.0-xxxxx-3543dr/sysroots/armv7at2-vfp-neon-wrs-linux-gnueabi/usr/include/c++/4.9.1/backward -I/opt/windriver/wrlinux-small/7.0-xxxxx-3543dr/sysroots/armv7at2-vfp-neon-wrs-linux-gnueabi/usr/include/dtc -I/opt/windriver/wrlinux-small/7.0-xxxxxx-3543dr/sysroots/x86_64-wrlinuxsdk-linux/usr/lib/arm-wrs-linux-gnueabi/gcc/arm-wrs-linux-gnueabi/4.9.1/include -I/opt/windriver/wrlinux-small/7.0-xxxxx-3543dr/sysroots/x86_64-wrlinuxsdk-linux/usr/lib/arm-wrs-linux-gnueabi/gcc/arm-wrs-linux-gnueabi/4.9.1/include-fixed
OBJECTS = main.o
_PATH = $(patsubst /%, %, $(CURDIR))
_CC = #/bin/echo -e " [\033[33mCC\033[0m] $#"; $(CC)
_DD = #/bin/echo -e " [\033[32mDD\033[0m] $#"; $(CC)
_CC_QUIET = #/bin/echo -n; $(CC)
all: $(NAME).duda
$(NAME).duda: $(OBJECTS)
$(_DD) $(CFLAGS) $(DEFS) -shared -o $# $^ -lc $(LDFLAGS)
.c.o:
$(_CC) -c $(CFLAGS) $(DEFS) $(INCDIR) -fPIC $<
$(_CC_QUIET) -MM -MP $(CFLAGS) $(DEFS) $(INCDIR) $*.c -o $*.d > /dev/null &2>&1
clean:
rm -rf *.o *.d *~ $(NAME).duda
How do i resolve that ?
Thanks
During linking you have specified libraries that are not in the standard path
Solutions
link statically
Use LD_LIBRARY_PATH
Use LD_PRELOAD
Use rpath
I try to use rpath just like this but got the same error:
CFLAGS = -g -Wall -DDEBUG -L/opt/PrismTech/Vortex_v2/Device/VortexOpenSpliceRTE/6.7.1p2/HDE/armv7at2_vfp_neon.WRlinux7_gcc/lib -Wl,-rpath,/opt/PrismTech/Vortex_v2/Device/VortexOpenSpliceRTE/6.7.1p2/HDE/armv7at2_vfp_neon.WRlinux7_gcc/lib -ldcpssac -ldcpsisocpp2

Compiling with -g for GDB in Makefile

new to using Makefiles and was wondering how I would include the -g command (and anything else I need) in order to compile my program to be run with gdb. Here is the Makefile I was given. Thanks in advance.
include parallelDefs
COMMON = dataGen.h utils.h IO.h parseCommandLine.h graph.h graphIO.h graphUtils.h parallel.h sequence.h blockRadixSort.h deterministicHash.h transpose.h
GENERATORS = rMatGraph gridGraph powerGraph randLocalGraph addWeights randDoubleVector fromAdjIdx adjToEdgeArray adjElimSelfEdges
.PHONY: all clean
all: $(GENERATORS)
$(COMMON) :
ln -s ../../common/$# .
%.o : %.C $(COMMON)
$(PCC) $(PCFLAGS) -c $< -o $#
rMatGraph : rMatGraph.o
$(PCC) $(PLFLAGS) -o $# rMatGraph.o
gridGraph : gridGraph.o
$(PCC) $(PLFLAGS) -o $# gridGraph.o
powerGraph : powerGraph.o
$(PCC) $(PLFLAGS) -o $# powerGraph.o
randLocalGraph : randLocalGraph.o
$(PCC) $(PLFLAGS) -o $# randLocalGraph.o
addWeights : addWeights.o
$(PCC) $(PLFLAGS) -o $# addWeights.o
fromAdjIdx : fromAdjIdx.o
$(PCC) $(PLFLAGS) -o $# fromAdjIdx.o
randDoubleVector : randDoubleVector.o
$(PCC) $(PLFLAGS) -o $# randDoubleVector.o
adjToEdgeArray : adjToEdgeArray.C $(COMMON)
$(PCC) $(PCFLAGS) $(PLFLAGS) -o $# adjToEdgeArray.C
adjElimSelfEdges : adjElimSelfEdges.C $(COMMON)
$(PCC) $(PCFLAGS) $(PLFLAGS) -o $# adjElimSelfEdges.C
clean :
rm -f *.o $(GENERATORS)
make clean -s -C data
cleansrc :
make -s clean
rm -f $(COMMON)
If only randLocalGraph should be compiled with the -g option, then it will need an explicit rule:
randLocalGraph.o: randLocalGraph.C $(COMMON)
$(PCC) $(PCFLAGS) -g -c randLocalGraph.C -o $#
All the other objects will be created using the implicit rule.

Any Missing code in my Make file

i wrote a makefile with some commands.after running command make got a errors undefined reference to sqrtand undefined reference to exp
my make file :
CFILES = smLe.c iniTra.c le.c res.c uti.c smClass.c ini.c clas.c
OBJECTS = smLe.o iniTra.o le.o res.o uti.o smClass.o ini.o clas.o
OBJECTS1 = smLe.o iniTra.o le.o res.o uti.o
OBJECTS2 = smClass.o ini.o clas.o
CFLAGS = -O -lm
CC = gcc
.c .o:
$(CC) $(CFLAGS) $(OBJECTS) -c $<
p1: $(OBJECTS1)
$(CC) $(CFLAGS) $(OBJECTS1) -o $#
p2: $(OBJECTS)
$(CC) $(CFLAGS) $(OBJECTS2) -o $#
smLe.o: iniTra.h le.h res.h
iniTra.o: iniTra.h
le.o: iniTra.h uti.h le.h
res.o: iniTra.h le.h res.h
smClass.o: ini.h clas.h
ini.o: ini.h clas.h
clas.o: ini.h clas.h
Is it any thing missing in my make file.why this error occur in this make file code?please help me ..thanks
-lm is an LDLIB, you pass it to the linker
CFLAGS = -O
LDLIBS = -lm
CC = gcc
.c .o:
$(CC) $(CFLAGS) $(OBJECTS) -c $<
p1: $(OBJECTS1)
$(CC) $(OBJECTS1) -o $# $(LDLIBS)
Libraries have to appear after object files that call what is in them on the command line.

Makefile - wrong sequence of compiling

In makefile below I'm trying to compile one directory, but make against my will is trying to do it in wrong order. It's starting from compiling main.o and later it goes straight to compiling console. I have no idea why it's not trying to solve all dependences before it. I just get:
user#ubuntu:~/Dokumenty/Sysopy/cw1/zad3b$ make
gcc -c -Wall -I ./src/include src/main.c
gcc -o macierze main.o
main.o: In function `main':
main.c:(.text+0x28): undefined reference to `wczytaj'
main.c:(.text+0x31): undefined reference to `wczytaj'
main.c:(.text+0x7e): undefined reference to `suma'
...
collect2: ld returned 1 exit status make: *** [console] Błąd 1
Here's a makefile:
############ makra #############
CC = gcc
CFLAGS = -Wall -I ./src/include
LFLAGS =
VPATH = ./src/operacje: ./src/we_wy: ./src/reszta
########### pliki ##############
SRC_CONSOLE = wczytaj_konsola.c wypisz_konsola.c
SRC_FILE = wczytaj_plik.c wypisz_plik.c pliki.c
SRC_FUNCTION = suma.c roznica.c iloczyn.c macierz.c
HEADERS = suma.h roznica.h iloczyn.h wypisz.h wczytaj.h macierz.h
OBJ_SONSOLE = $(SRC_CONSOLE:.c=.o)
OBJ_FILE = $(SRC_FILE:.c=.o)
OBJ_FUNCTION = $(SRC_FUNCTIONS:.c=.o)
console: $(OBJ_CONSOLE) $(OBJ_FUNCTION) main.o
$(CC) $(LFLAGS) -o macierze $^
file: $(OBJ_FILE) $(OBJ_FUNCTION) main.o
$(CC) $(LFLAGS) -o macierze $^
console_logs: $(OBJ_CONSOLE) $(OBJ_FUNCTION) main.o
$(CC) $(LFLAGS) -o macierze $^
file_logs: $(OBJ_FILE) $(OBJ_FUNCTION) main.o
$(CC) $(LFLAGS) -o macierze $^
############# objekty ##############
main.o:
$(CC) -c $(CFLAGS) src/main.c
$(OBJ_CONSOLE): $(SRC_CONSOLE)
$(CC) -c $(CFLAGS) $^
$(OBJ_FILE): $(SRC_FILE)
$(CC) -c $(CFLAGS) $^
$(OBJ_FUNCTION): $(SRC_FUNCTION)
$(CC) -c $(CFLAGS) $^
%logs : LFLAGS += -D KOMUNIKATY
file% : LFLAGS += -D PLIKI
./PHONY: clean
clean:
rm -f *.o
rm -f ./src/include/*.gch
rm -f macierze
you write : OBJ_FUNCTION = $(SRC_FUNCTIONS:.c=.o)
instead of : OBJ_FUNCTION = $(SRC_FUNCTION:.c=.o)
and
OBJ_SONSOLE = $(SRC_CONSOLE:.c=.o)
instead of OBJ_CONSOLE = $(SRC_CONSOLE:.c=.o)

Resources