Have linker remove unused object files for avr/gcc - c

I'm using avr-gcc for an atmega-328p micro controller.
The code is built with:
avr-gcc -g -Wall -Os -mmcu=atmega328p -D__AVR_ATmega3280__ -DARCH_AVR -I/usr/avr/include -DF_CPU=16000000 -c -o heap.o heap.c
avr-gcc -g -Wall -Os -mmcu=atmega328p -D__AVR_ATmega3280__ -DARCH_AVR -I/usr/avr/include -DF_CPU=16000000 -c -o kerneltimer.o kerneltimer.c
avr-gcc -g -Wall -Os -mmcu=atmega328p -D__AVR_ATmega3280__ -DARCH_AVR -I/usr/avr/include -DF_CPU=16000000 -c -o message.o message.c
avr-gcc -g -Wall -Os -mmcu=atmega328p -D__AVR_ATmega3280__ -DARCH_AVR -I/usr/avr/include -DF_CPU=16000000 -c -o driver.o driver.c
avr-gcc -g -Wall -Os -mmcu=atmega328p -D__AVR_ATmega3280__ -DARCH_AVR -I/usr/avr/include -DF_CPU=16000000 -c -o watchdog.o watchdog.c
avr-gcc -g -Wall -Os -mmcu=atmega328p -D__AVR_ATmega3280__ -DARCH_AVR -I/usr/avr/include -DF_CPU=16000000 -c -o mutex.o mutex.c
avr-gcc -g -Wall -Os -mmcu=atmega328p -D__AVR_ATmega3280__ -DARCH_AVR -I/usr/avr/include -DF_CPU=16000000 -c -o semaphore.o semaphore.c
avr-gcc -g -Wall -Os -mmcu=atmega328p -D__AVR_ATmega3280__ -DARCH_AVR -I/usr/avr/include -DF_CPU=16000000 -c -o kernelswi.o kernelswi.c
avr-gcc -g -Wall -Os -mmcu=atmega328p -D__AVR_ATmega3280__ -DARCH_AVR -I/usr/avr/include -DF_CPU=16000000 -c -o task.o task.c
avr-gcc -g -Wall -Os -mmcu=atmega328p -D__AVR_ATmega3280__ -DARCH_AVR -I/usr/avr/include -DF_CPU=16000000 -c -o kernelwdt.o kernelwdt.c
avr-gcc -g -Wall -Os -mmcu=atmega328p -D__AVR_ATmega3280__ -DARCH_AVR -I/usr/avr/include -DF_CPU=16000000 -c -o myfirstapp.o myfirstapp.c
avr-gcc -g -Wall -Os -mmcu=atmega328p -D__AVR_ATmega3280__ -DARCH_AVR -I/usr/avr/include -DF_CPU=16000000 -c -o taskport.o taskport.c
avr-gcc -g -Wall -Os -mmcu=atmega328p -D__AVR_ATmega3280__ -DARCH_AVR -I/usr/avr/include -DF_CPU=16000000 -c -o timer.o timer.c
And linked with:
avr-gcc -g -Wall -Os -mmcu=atmega328p -D__AVR_ATmega3280__ -DARCH_AVR -I/usr/avr/include -DF_CPU=16000000 -Wl,-Map,myfirstapp.map -L/usr/avr/lib -Os -o myfirstapp.elf heap.o kerneltimer.o message.o driver.o watchdog.o mutex.o semaphore.o kernelswi.o task.o kernelwdt.o myfirstapp.o taskport.o timer.o
Now- as it turns out for this particular program, nothing in heap.o is used. Yet the code is included in the final binary. Is there anyway I can get the linker to atleast elide complete .o files if nothing in them are used anywhere ?
And while this is just a fun project for learning purposes,
I'd rather learn if the tools can figure this out than tracking down such things myself.

Yes, this is possible. Passing --gc-sections to the linker will direct it to omit sections which are not referenced. Additionally, passing the -ffunction-sections and -fdata-sections flags to the compiler will direct it to generate a section for each function and variable, allowing these to be left out on an individual basis, rather than just at a file level.

Adding --gc-sections to the linker didn't help for me. However adding
-Wl,-gc-sections did work

Related

Trying to compile TPC-H Benchmark and is returned this error ld: library not found for -lgcc

I'm trying to compile the TPC-H Benchmark and when I made make, is returned the following error:
gcc -g -DDBNAME=\"dss\" -DLINUX -DORACLE -DTPCH -DRNG_TEST -D_FILE_OFFSET_BITS=64 -c -o build.o build.c
gcc -g -DDBNAME=\"dss\" -DLINUX -DORACLE -DTPCH -DRNG_TEST -D_FILE_OFFSET_BITS=64 -c -o driver.o driver.c
gcc -g -DDBNAME=\"dss\" -DLINUX -DORACLE -DTPCH -DRNG_TEST -D_FILE_OFFSET_BITS=64 -c -o bm_utils.o bm_utils.c
gcc -g -DDBNAME=\"dss\" -DLINUX -DORACLE -DTPCH -DRNG_TEST -D_FILE_OFFSET_BITS=64 -c -o rnd.o rnd.c
gcc -g -DDBNAME=\"dss\" -DLINUX -DORACLE -DTPCH -DRNG_TEST -D_FILE_OFFSET_BITS=64 -c -o print.o print.c
gcc -g -DDBNAME=\"dss\" -DLINUX -DORACLE -DTPCH -DRNG_TEST -D_FILE_OFFSET_BITS=64 -c -o load_stub.o load_stub.c
gcc -g -DDBNAME=\"dss\" -DLINUX -DORACLE -DTPCH -DRNG_TEST -D_FILE_OFFSET_BITS=64 -c -o bcd2.o bcd2.c
gcc -g -DDBNAME=\"dss\" -DLINUX -DORACLE -DTPCH -DRNG_TEST -D_FILE_OFFSET_BITS=64 -c -o speed_seed.o speed_seed.c
gcc -g -DDBNAME=\"dss\" -DLINUX -DORACLE -DTPCH -DRNG_TEST -D_FILE_OFFSET_BITS=64 -c -o text.o text.c
gcc -g -DDBNAME=\"dss\" -DLINUX -DORACLE -DTPCH -DRNG_TEST -D_FILE_OFFSET_BITS=64 -c -o permute.o permute.c
gcc -g -DDBNAME=\"dss\" -DLINUX -DORACLE -DTPCH -DRNG_TEST -D_FILE_OFFSET_BITS=64 -c -o rng64.o rng64.c
gcc -g -DDBNAME=\"dss\" -DLINUX -DORACLE -DTPCH -DRNG_TEST -D_FILE_OFFSET_BITS=64 -O -o dbgen build.o driver.o bm_utils.o rnd.o print.o load_stub.o bcd2.o speed_seed.o text.o permute.o rng64.o -lm
ld: library not found for -lgcc
collect2: error: ld returned 1 exit status
make: *** [dbgen] Error 1
I made a search for trying to fix this and I don't found it any help yet. Somebody can help me please?
try using gcc-5 on your makefile. i had the same problem with tpc-h.

Linux shared object compilation issue

My Makefile was like this earlier.
export SOURCE1 = source1.c \
1.c \
2.c \
3.c
export SOURCE2 = source2.c \
1.c
all:
gcc -Wall -W -g -O2 ${SOURCE1} -lm -lipc -o source1
gcc -Wall -W -g -O2 ${SOURCE2} -lm -lipc -o source2
This one works fine. And, I wanted to create a shared object which comprises 1.c, 2.c and 3.c. Consequently I changed my Makefile to
export LIB_SOURCE 1.c 2.c 3.c
export SOURCE1 = source1.c
export SOURCE2 = source2.c
all:
gcc -Wall -W -g -O2 ${LIB_SOURCE} -o libsrc.so.1
ln -sf libsrc.so.1 libsrc.so.0
ln -sf libsrc.so.0 libsrc.so
gcc -Wall -W -g -O2 ${SOURCE1} -lm -lipc -lsrc -o source1
gcc -Wall -W -g -O2 ${SOURCE2} -lm -lipc -lsrc -o source2
The make failed while compiling source2, saying it
src.so: undefined reference to 'var1'
The var1 is defined in 3.c which is not needed by source2. Since it's included in the library it's failing looking at it. How to move on with this error.
Thanks,
I was able to get your makefile to work with a couple of small adjustments:
all:
gcc -Wall -W -g -O2 -shared ${LIB_SOURCE} -o libcsrc.so
gcc -Wall -W -g -O2 -L. ${SOURCE1} -lm -lsrc -o source1
gcc -Wall -W -g -O2 -L. ${SOURCE2} -lm -lsrc -o source2
(I removed -lipc because I don't have that library handy.) But I suggest a slightly different approach once the above is working perfectly for you. Since you are constructing the library libsrc.so, make a separate rule for it, and a separate rule for each of the executables, and use prerequisite lists:
all: source1 source2
source1: source1.c libcsrc.so
gcc -Wall -W -g -O2 -L. source1.c -lm -lsrc -o source1
source1: source2.c libcsrc.so
gcc -Wall -W -g -O2 -L. source2.c -lm -lsrc -o source2
libcsrc.so: ${LIB_SOURCE}
gcc -Wall -W -g -O2 -shared ${LIB_SOURCE} -o libcsrc.so
Then you can put in automatic variables, and combine the source1 and source2 rules:
all: source1 source2
source1 source2: % : %.c libcsrc.so
gcc -Wall -W -g -O2 -L. $< -lm -lsrc -o $#
libcsrc.so: ${LIB_SOURCE}
gcc -Wall -W -g -O2 -shared $^ -o $#

ignoring file lib.a, file was built for archive which is not the architecture being linked (x86_64)

I'm trying to code a printf clone. I've built a library file called "libftprintf.a" but when I try to use it, I get the following error, on Mac OSX 10.8.5:
ld: warning: ignoring file ./libftprintf.a, file was built for archive which is not the architecture being linked (x86_64): ./libftprintf.a
Strangely this works fine (but I need only one lib called libftprintf, so this is not acceptable):
gcc -Wall -Wextra -Werror -I libft/includes/ -o ft_printf_test.bin -L libft -lft -L. -lftprintf ft_printf_test.c
I suspect I have misused the ar command to link both libs together. But I don't se my mistake yet.
What could be the cause of that?
Everything seems to compile just fine until I try to use the libftprintf.a file with the make test command. I've searched for a solution on Google, but most answers relate to XCode only. According to lipo -info, the files are x86_64.
My GCC version:
$> gcc --version
Configured with: --prefix=/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin12.5.0
Thread model: posix
Below is the full output of my makefile, for reference.
$> make re
make -C libft clean
rm -f src/ft_arrdel.o src/ft_atoi.o src/ft_bzero.o src/ft_isalnum.o src/ft_isalpha.o src/ft_isascii.o src/ft_isdigit.o src/ft_islower.o src/ft_isprint.o src/ft_isupper.o src/ft_itoa.o src/ft_lstadd.o src/ft_lstdel.o src/ft_lstdelone.o src/ft_lstiter.o src/ft_lstmap.o src/ft_lstnew.o src/ft_lstpush.o src/ft_malloc.o src/ft_memalloc.o src/ft_memccpy.o src/ft_memchr.o src/ft_memcmp.o src/ft_memcpy.o src/ft_memdel.o src/ft_memmove.o src/ft_memset.o src/ft_putchar.o src/ft_putchar_fd.o src/ft_putendl.o src/ft_putendl_fd.o src/ft_putnbr.o src/ft_putnbr_fd.o src/ft_putstr.o src/ft_putstr_fd.o src/ft_strcat.o src/ft_strchr.o src/ft_strclr.o src/ft_strcmp.o src/ft_strcpy.o src/ft_strdel.o src/ft_strdup.o src/ft_strequ.o src/ft_striter.o src/ft_striteri.o src/ft_strjoin.o src/ft_strlcat.o src/ft_strlen.o src/ft_strmap.o src/ft_strmapi.o src/ft_strncat.o src/ft_strncmp.o src/ft_strncpy.o src/ft_strnequ.o src/ft_strnew.o src/ft_strnstr.o src/ft_strrchr.o src/ft_strrev.o src/ft_strsplit.o src/ft_strstr.o src/ft_strsub.o src/ft_strtrim.o src/ft_tolower.o src/ft_toupper.o src/get_next_line.o
rm -f ft_printf.o
make -C libft fclean
rm -f src/ft_arrdel.o src/ft_atoi.o src/ft_bzero.o src/ft_isalnum.o src/ft_isalpha.o src/ft_isascii.o src/ft_isdigit.o src/ft_islower.o src/ft_isprint.o src/ft_isupper.o src/ft_itoa.o src/ft_lstadd.o src/ft_lstdel.o src/ft_lstdelone.o src/ft_lstiter.o src/ft_lstmap.o src/ft_lstnew.o src/ft_lstpush.o src/ft_malloc.o src/ft_memalloc.o src/ft_memccpy.o src/ft_memchr.o src/ft_memcmp.o src/ft_memcpy.o src/ft_memdel.o src/ft_memmove.o src/ft_memset.o src/ft_putchar.o src/ft_putchar_fd.o src/ft_putendl.o src/ft_putendl_fd.o src/ft_putnbr.o src/ft_putnbr_fd.o src/ft_putstr.o src/ft_putstr_fd.o src/ft_strcat.o src/ft_strchr.o src/ft_strclr.o src/ft_strcmp.o src/ft_strcpy.o src/ft_strdel.o src/ft_strdup.o src/ft_strequ.o src/ft_striter.o src/ft_striteri.o src/ft_strjoin.o src/ft_strlcat.o src/ft_strlen.o src/ft_strmap.o src/ft_strmapi.o src/ft_strncat.o src/ft_strncmp.o src/ft_strncpy.o src/ft_strnequ.o src/ft_strnew.o src/ft_strnstr.o src/ft_strrchr.o src/ft_strrev.o src/ft_strsplit.o src/ft_strstr.o src/ft_strsub.o src/ft_strtrim.o src/ft_tolower.o src/ft_toupper.o src/get_next_line.o
rm -f libft.a
rm -f libftprintf.a
rm -Rf ft_printf_test.bin*
gcc -Wall -Wextra -Werror -I libft/includes/ -c ft_printf.c -o ft_printf.o
make -C libft
gcc -g -Wall -Wextra -Werror -I includes -c src/ft_arrdel.c -o src/ft_arrdel.o
gcc -g -Wall -Wextra -Werror -I includes -c src/ft_atoi.c -o src/ft_atoi.o
gcc -g -Wall -Wextra -Werror -I includes -c src/ft_bzero.c -o src/ft_bzero.o
gcc -g -Wall -Wextra -Werror -I includes -c src/ft_isalnum.c -o src/ft_isalnum.o
gcc -g -Wall -Wextra -Werror -I includes -c src/ft_isalpha.c -o src/ft_isalpha.o
gcc -g -Wall -Wextra -Werror -I includes -c src/ft_isascii.c -o src/ft_isascii.o
gcc -g -Wall -Wextra -Werror -I includes -c src/ft_isdigit.c -o src/ft_isdigit.o
gcc -g -Wall -Wextra -Werror -I includes -c src/ft_islower.c -o src/ft_islower.o
gcc -g -Wall -Wextra -Werror -I includes -c src/ft_isprint.c -o src/ft_isprint.o
gcc -g -Wall -Wextra -Werror -I includes -c src/ft_isupper.c -o src/ft_isupper.o
gcc -g -Wall -Wextra -Werror -I includes -c src/ft_itoa.c -o src/ft_itoa.o
gcc -g -Wall -Wextra -Werror -I includes -c src/ft_lstadd.c -o src/ft_lstadd.o
gcc -g -Wall -Wextra -Werror -I includes -c src/ft_lstdel.c -o src/ft_lstdel.o
gcc -g -Wall -Wextra -Werror -I includes -c src/ft_lstdelone.c -o src/ft_lstdelone.o
gcc -g -Wall -Wextra -Werror -I includes -c src/ft_lstiter.c -o src/ft_lstiter.o
gcc -g -Wall -Wextra -Werror -I includes -c src/ft_lstmap.c -o src/ft_lstmap.o
gcc -g -Wall -Wextra -Werror -I includes -c src/ft_lstnew.c -o src/ft_lstnew.o
gcc -g -Wall -Wextra -Werror -I includes -c src/ft_lstpush.c -o src/ft_lstpush.o
gcc -g -Wall -Wextra -Werror -I includes -c src/ft_malloc.c -o src/ft_malloc.o
gcc -g -Wall -Wextra -Werror -I includes -c src/ft_memalloc.c -o src/ft_memalloc.o
gcc -g -Wall -Wextra -Werror -I includes -c src/ft_memccpy.c -o src/ft_memccpy.o
gcc -g -Wall -Wextra -Werror -I includes -c src/ft_memchr.c -o src/ft_memchr.o
gcc -g -Wall -Wextra -Werror -I includes -c src/ft_memcmp.c -o src/ft_memcmp.o
gcc -g -Wall -Wextra -Werror -I includes -c src/ft_memcpy.c -o src/ft_memcpy.o
gcc -g -Wall -Wextra -Werror -I includes -c src/ft_memdel.c -o src/ft_memdel.o
gcc -g -Wall -Wextra -Werror -I includes -c src/ft_memmove.c -o src/ft_memmove.o
gcc -g -Wall -Wextra -Werror -I includes -c src/ft_memset.c -o src/ft_memset.o
gcc -g -Wall -Wextra -Werror -I includes -c src/ft_putchar.c -o src/ft_putchar.o
gcc -g -Wall -Wextra -Werror -I includes -c src/ft_putchar_fd.c -o src/ft_putchar_fd.o
gcc -g -Wall -Wextra -Werror -I includes -c src/ft_putendl.c -o src/ft_putendl.o
gcc -g -Wall -Wextra -Werror -I includes -c src/ft_putendl_fd.c -o src/ft_putendl_fd.o
gcc -g -Wall -Wextra -Werror -I includes -c src/ft_putnbr.c -o src/ft_putnbr.o
gcc -g -Wall -Wextra -Werror -I includes -c src/ft_putnbr_fd.c -o src/ft_putnbr_fd.o
gcc -g -Wall -Wextra -Werror -I includes -c src/ft_putstr.c -o src/ft_putstr.o
gcc -g -Wall -Wextra -Werror -I includes -c src/ft_putstr_fd.c -o src/ft_putstr_fd.o
gcc -g -Wall -Wextra -Werror -I includes -c src/ft_strcat.c -o src/ft_strcat.o
gcc -g -Wall -Wextra -Werror -I includes -c src/ft_strchr.c -o src/ft_strchr.o
gcc -g -Wall -Wextra -Werror -I includes -c src/ft_strclr.c -o src/ft_strclr.o
gcc -g -Wall -Wextra -Werror -I includes -c src/ft_strcmp.c -o src/ft_strcmp.o
gcc -g -Wall -Wextra -Werror -I includes -c src/ft_strcpy.c -o src/ft_strcpy.o
gcc -g -Wall -Wextra -Werror -I includes -c src/ft_strdel.c -o src/ft_strdel.o
gcc -g -Wall -Wextra -Werror -I includes -c src/ft_strdup.c -o src/ft_strdup.o
gcc -g -Wall -Wextra -Werror -I includes -c src/ft_strequ.c -o src/ft_strequ.o
gcc -g -Wall -Wextra -Werror -I includes -c src/ft_striter.c -o src/ft_striter.o
gcc -g -Wall -Wextra -Werror -I includes -c src/ft_striteri.c -o src/ft_striteri.o
gcc -g -Wall -Wextra -Werror -I includes -c src/ft_strjoin.c -o src/ft_strjoin.o
gcc -g -Wall -Wextra -Werror -I includes -c src/ft_strlcat.c -o src/ft_strlcat.o
gcc -g -Wall -Wextra -Werror -I includes -c src/ft_strlen.c -o src/ft_strlen.o
gcc -g -Wall -Wextra -Werror -I includes -c src/ft_strmap.c -o src/ft_strmap.o
gcc -g -Wall -Wextra -Werror -I includes -c src/ft_strmapi.c -o src/ft_strmapi.o
gcc -g -Wall -Wextra -Werror -I includes -c src/ft_strncat.c -o src/ft_strncat.o
gcc -g -Wall -Wextra -Werror -I includes -c src/ft_strncmp.c -o src/ft_strncmp.o
gcc -g -Wall -Wextra -Werror -I includes -c src/ft_strncpy.c -o src/ft_strncpy.o
gcc -g -Wall -Wextra -Werror -I includes -c src/ft_strnequ.c -o src/ft_strnequ.o
gcc -g -Wall -Wextra -Werror -I includes -c src/ft_strnew.c -o src/ft_strnew.o
gcc -g -Wall -Wextra -Werror -I includes -c src/ft_strnstr.c -o src/ft_strnstr.o
gcc -g -Wall -Wextra -Werror -I includes -c src/ft_strrchr.c -o src/ft_strrchr.o
gcc -g -Wall -Wextra -Werror -I includes -c src/ft_strrev.c -o src/ft_strrev.o
gcc -g -Wall -Wextra -Werror -I includes -c src/ft_strsplit.c -o src/ft_strsplit.o
gcc -g -Wall -Wextra -Werror -I includes -c src/ft_strstr.c -o src/ft_strstr.o
gcc -g -Wall -Wextra -Werror -I includes -c src/ft_strsub.c -o src/ft_strsub.o
gcc -g -Wall -Wextra -Werror -I includes -c src/ft_strtrim.c -o src/ft_strtrim.o
gcc -g -Wall -Wextra -Werror -I includes -c src/ft_tolower.c -o src/ft_tolower.o
gcc -g -Wall -Wextra -Werror -I includes -c src/ft_toupper.c -o src/ft_toupper.o
gcc -g -Wall -Wextra -Werror -I includes -c src/get_next_line.c -o src/get_next_line.o
ar -rsv libft.a src/ft_arrdel.o src/ft_atoi.o src/ft_bzero.o src/ft_isalnum.o src/ft_isalpha.o src/ft_isascii.o src/ft_isdigit.o src/ft_islower.o src/ft_isprint.o src/ft_isupper.o src/ft_itoa.o src/ft_lstadd.o src/ft_lstdel.o src/ft_lstdelone.o src/ft_lstiter.o src/ft_lstmap.o src/ft_lstnew.o src/ft_lstpush.o src/ft_malloc.o src/ft_memalloc.o src/ft_memccpy.o src/ft_memchr.o src/ft_memcmp.o src/ft_memcpy.o src/ft_memdel.o src/ft_memmove.o src/ft_memset.o src/ft_putchar.o src/ft_putchar_fd.o src/ft_putendl.o src/ft_putendl_fd.o src/ft_putnbr.o src/ft_putnbr_fd.o src/ft_putstr.o src/ft_putstr_fd.o src/ft_strcat.o src/ft_strchr.o src/ft_strclr.o src/ft_strcmp.o src/ft_strcpy.o src/ft_strdel.o src/ft_strdup.o src/ft_strequ.o src/ft_striter.o src/ft_striteri.o src/ft_strjoin.o src/ft_strlcat.o src/ft_strlen.o src/ft_strmap.o src/ft_strmapi.o src/ft_strncat.o src/ft_strncmp.o src/ft_strncpy.o src/ft_strnequ.o src/ft_strnew.o src/ft_strnstr.o src/ft_strrchr.o src/ft_strrev.o src/ft_strsplit.o src/ft_strstr.o src/ft_strsub.o src/ft_strtrim.o src/ft_tolower.o src/ft_toupper.o src/get_next_line.o
ar: creating archive libft.a
a - src/ft_arrdel.o
a - src/ft_atoi.o
a - src/ft_bzero.o
a - src/ft_isalnum.o
a - src/ft_isalpha.o
a - src/ft_isascii.o
a - src/ft_isdigit.o
a - src/ft_islower.o
a - src/ft_isprint.o
a - src/ft_isupper.o
a - src/ft_itoa.o
a - src/ft_lstadd.o
a - src/ft_lstdel.o
a - src/ft_lstdelone.o
a - src/ft_lstiter.o
a - src/ft_lstmap.o
a - src/ft_lstnew.o
a - src/ft_lstpush.o
a - src/ft_malloc.o
a - src/ft_memalloc.o
a - src/ft_memccpy.o
a - src/ft_memchr.o
a - src/ft_memcmp.o
a - src/ft_memcpy.o
a - src/ft_memdel.o
a - src/ft_memmove.o
a - src/ft_memset.o
a - src/ft_putchar.o
a - src/ft_putchar_fd.o
a - src/ft_putendl.o
a - src/ft_putendl_fd.o
a - src/ft_putnbr.o
a - src/ft_putnbr_fd.o
a - src/ft_putstr.o
a - src/ft_putstr_fd.o
a - src/ft_strcat.o
a - src/ft_strchr.o
a - src/ft_strclr.o
a - src/ft_strcmp.o
a - src/ft_strcpy.o
a - src/ft_strdel.o
a - src/ft_strdup.o
a - src/ft_strequ.o
a - src/ft_striter.o
a - src/ft_striteri.o
a - src/ft_strjoin.o
a - src/ft_strlcat.o
a - src/ft_strlen.o
a - src/ft_strmap.o
a - src/ft_strmapi.o
a - src/ft_strncat.o
a - src/ft_strncmp.o
a - src/ft_strncpy.o
a - src/ft_strnequ.o
a - src/ft_strnew.o
a - src/ft_strnstr.o
a - src/ft_strrchr.o
a - src/ft_strrev.o
a - src/ft_strsplit.o
a - src/ft_strstr.o
a - src/ft_strsub.o
a - src/ft_strtrim.o
a - src/ft_tolower.o
a - src/ft_toupper.o
a - src/get_next_line.o
ar -rsv libftprintf.a libft/libft.a ft_printf.o
ar: creating archive libftprintf.a
a - libft/libft.a
a - ft_printf.o
ranlib libftprintf.a
$> make test
gcc -Wall -Wextra -Werror -I libft/includes/ -L. -lftprintf -o ft_printf_test.bin ft_printf_test.c
ld: warning: ignoring file ./libftprintf.a, file was built for archive which is not the architecture being linked (x86_64): ./libftprintf.a
Undefined symbols for architecture x86_64:
"_ft_printf_string", referenced from:
_test_printf_percent in ft_printf_test-jTXeph.o
"_ft_strcmp", referenced from:
_test_printf_percent in ft_printf_test-jTXeph.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [test] Error 1
[ ckleines ~/Projects/2013-2014/Algo-1/printf ] $> lipo -info libft/libft.a
input file libft/libft.a is not a fat file
Non-fat file: libft/libft.a is architecture: x86_64
[ ckleines ~/Projects/2013-2014/Algo-1/printf ] $> lipo -info libftprintf.a
input file libftprintf.a is not a fat file
Non-fat file: libftprintf.a is architecture: x86_64
[ ckleines ~/Projects/2013-2014/Algo-1/printf ] $> lipo -info ft_printf.o
Non-fat file: ft_printf.o is architecture: x86_64
Use libtool -static -o instead of ar.
Static library link issue with Mac OS X: symbol(s) not found for architecture x86_64
I've found a slightly dirty but working solution for now. I extract the libft/libft.a archive in a temporary directory. Link the new library with the extracted .o files and then remove the temporary directory.
$(NAME): $(OBJ) $(HEADER)
make -C libft
mkdir libft_o && cd libft_o && ar -x ../libft/libft.a && cd ..
$(AR) $(NAME) libft_o/*.o $(OBJ)
rm -Rf libft_o
ranlib $(NAME)
The drawback being that if an object file from libft at some point has the same name than one from the printf files, it will overwrite things. But that's not likely to happen.
If you have fat architecture object files you must make sure that you pass the s flag to ar. Without it the linker will refuse to take archive files that contain fat architecture .o files. For example:
$ ar rcs libprintf.a *.o
You should then see a warning about creating a 'fat archive'. Don't worry about this, it means that ar won't be able to update the archive file, but the linker will be able to use it to link properly.

gcc builds with -o but not -o3?

My Makefile looks like this:
CC=gcc
CFLAGS=-Wall -Wextra -std=c99 -pedantic
OBJECTS=main.o Scene.o Matrix.o Vector.o Triangle.o Color.o Raster.o
render: $(OBJECTS)
$(CC) $(CFLAGS) -lm -o render -g $(OBJECTS)
rm $(OBJECTS)
clean:
rm -f render*
This builds my executable with no errors, but when I change -o to -o2 or -o3, I get the error:
gcc -Wall -Wextra -std=c99 -pedantic -c -o main.o main.c
gcc -Wall -Wextra -std=c99 -pedantic -c -o Scene.o Scene.c
gcc -Wall -Wextra -std=c99 -pedantic -c -o Matrix.o Matrix.c
gcc -Wall -Wextra -std=c99 -pedantic -c -o Vector.o Vector.c
gcc -Wall -Wextra -std=c99 -pedantic -c -o Triangle.o Triangle.c
gcc -Wall -Wextra -std=c99 -pedantic -c -o Color.o Color.c
gcc -Wall -Wextra -std=c99 -pedantic -c -o Raster.o Raster.c
gcc -Wall -Wextra -std=c99 -pedantic -lm -o3 render -g main.o Scene.o Matrix.o Vector.o Triangle.o Color.o Raster.o
gcc.exe: error: render: No such file or directory
make: *** [render] Error 1
There could be some error in my code detected by the optimization flags, but as I don't get any error messages before this it's hard to know what's going wrong. I'm using MinGW/MSYS on Windows 7.
-o render means create the output file with the name render.
Now you are changing this -o to -o3 which is incorrect. Instead you need to keep -o render as it is and add a -O3 flag for optimization. Note the capital letter O.
-o is the output file flag. You were thinking of -O (capital).

How to generate debug information with Eclipse

I have a C project that can be built in the command line (Linux Mint) which generates
debug information. I can use GDB to debug it in the command line interface, which I find very tedious.
I have used: sudo make DEBUG=1 in the command line.
I need to debug the same project in Eclipse (GALILEO). I can build it in Eclipse, but no debug information is generated, and I can't debug the code (with the error "No Debugging Information available"). Also can't place any break point in the code.
I have used gcc -g as the compiler invocation command (compiler > -O2 -g -Wall -c -fmessage-length=0)
and make DEBUG=1 in custom build command, with the
linker as "gcc"
Can anyone tell me how to set up the project so that the debug information is generated just like when it was built in the command line.
------------------BUILD OUTPUT------------------------------------------------------------
Build of configuration Default for project yuma **
make DEBUG=1 STATIC=1 all
for dir in libtecla netconf libtoaster; do\
cd $dir && make && cd ..;\
done
make[1]: Entering directory /home/shuser/workspace2/yuma/libtecla'
make[2]: Entering directory/home/shuser/workspace2/yuma/libtecla'
mkdir normal_obj
cp ./keytab.h normal_obj/keytab.h
gcc -c -O -DPACKAGE_NAME="" -DPACKAGE_TARNAME="" -DPACKAGE_VERSION="" -DPACKAGE_STRING="" -DPACKAGE_BUGREPORT="" -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_SYS_SELECT_H=1 -DHAVE_SELECT=1 -DHAVE_SYSV_PTY=1 -D_SVID_SOURCE -D_BSD_SOURCE -fpic -o normal_obj/getline.o ./getline.c
[...]
gcc -DLINUX=1 -DGCC=1 -DDEBUG -DHAS_FLOAT=1 -Wall -Wno-long-long -Wformat-y2k -Winit-self -Wswitch-default -Wunused-parameter -Wextra -Wundef -Wshadow -Wpointer-arith -Wwrite-strings -Wbad-function-cast -Wcast-qual -Waggregate-return -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes -Wmissing-declarations -Wpacked -Winvalid-pch -Wredundant-decls -Wnested-externs -Winline -std=gnu99 -fPIC -ggdb3 \
-I. -I../agt -I../mgr -I../ncx -I../platform -I../ydump -I/usr/include -I/usr/include/libxml2 -I/usr/include/libxml2/libxml -c -o ../../target/mgr/mgr.o mgr.c
gcc -DLINUX=1 -DGCC=1 -DDEBUG -DHAS_FLOAT=1 -Wall -Wno-long-long -Wformat-y2k -Winit-self -Wswitch-default -Wunused-parameter -Wextra -Wundef -Wshadow -Wpointer-arith -Wwrite-strings -Wbad-function-cast -Wcast-qual -Waggregate-return -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes -Wmissing-declarations -Wpacked -Winvalid-pch -Wredundant-decls -Wnested-externs -Winline -std=gnu99 -fPIC -ggdb3 \
-I. -I../agt -I../mgr -I../ncx -I../platform -I../ydump -I/usr/include -I/usr/include/libxml2 -I/usr/include/libxml2/libxml -c -o ../../target/mgr/mgr_cap.o mgr_cap.c
[...]
gcc -ggdb3 -DDEBUG=1 -DLINUX=1 -DGCC=1 -DHAS_FLOAT=1 -Wall -Wno-long-long -Wformat-y2k -Winit-self -Wswitch-default -Wunused-parameter -Wextra -Wundef -Wshadow -Wpointer-arith -Wwrite-strings -Wbad-function-cast -Wcast-qual -Wcast-align -Waggregate-return -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes -Wmissing-declarations -Wpacked -Winvalid-pch -Wredundant-decls -Wnested-externs -Winline -std=gnu99 -fPIC \
-I. -I../../netconf/src/platform -I../../netconf/src/ncx -I../../netconf/src/agt -I/usr/include/yuma/platform -I/usr/include/yuma/ncx -I/usr/include/yuma/agt -I/usr/include -I/usr/include/libxml2 -I/usr/include/libxml2/libxml -c -o ../bin/toaster.o toaster.c
----------------------DEBUG CONSOLE---------------------------
No source available for "main() "
[...]
.gdbinit: No such file or directory.
Reading symbols from /home/shuser/yuma-2.2-2/netconf/target/bin/netconfd...(no debugging symbols found)...done.
1-gdb-set confirm off
1^done
(gdb)
2-gdb-set width 0
2^done
[...]
=library-loaded,id="/lib/i386-linux-gnu/libm.so.6",target-name="/lib/i386-linux-gnu/libm.so.6",host-name="/lib/i386-linux-gnu/libm.so.6",symbols-loaded="0",thread-group="i1"
~"Stopped due to shared library event\n"
Stopped due to shared library event
*stopped,thread-id="1",stopped-threads="all",core="0"
22 info sharedlibrary
(gdb)

Resources