A.nechi A.nechi - 3 months ago 15
C Question

C application wont be linked dynamically

I have a C application: FFT that is linked dynamically with eclipse but seeing the fact that I'm using a simulator that only deals with statically linked application i had to add the "-static" flag in my Makefile as following:

CC=gcc
CFLAGS=-g -static -c -Wall -O5 -mavx
LDFLAGS=

SOURCES=$ fft.c
OBJECTS=$(SOURCES:.c=.o)

EXECUTABLE=fft


all: $(TASKMAP) $(SOURCES) $(EXECUTABLE)

$(EXECUTABLE): $(OBJECTS)
$(CC) $(LDFLAGS) $(OBJECTS) -lm -o $@

.c.o:
$(CC) $(CFLAGS) $< -lm -o $@


clean:
rm -fr $(OBJECTS) $(EXECUTABLE)


Normally the static link should work but when i type the following command:

:~/workspace/fft$ file fft

I get this message:

fft: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=0xa499c8104f09cd85fbfbb33c75e51c606f117acf, not stripped

could someone help me on this?

Answer

You need to add the -static flags to the LDFLAGS section.

You also don't need -static flags in the CFLAGS.