this is my first question here, I hope to do everything in the right way.
I'm a quite new Ubuntu user and if possible I need some help with a specific Makefile. I downloaded QEMU 2.1.0 and I'm currently changing some source code files for a custom version. In particular I have an sd.c file like the following:
[...]
#include "hw/mydistribution.h"
[...]
Nac = poisson_distribution(Nac_mean);
and a mydistribution.h file where for example I define the poisson_distribution() using functions from GSL library:
#include <math.h>
#include <gsl/gsl_rng.h>
#include <gsl/gsl_randist.h>
[...]
unsigned int poisson_distribution(double expected_value) {
const gsl_rng_type * T;
gsl_rng * r;
unsigned int k;
gsl_rng_env_setup();
T = gsl_rng_default;
r = gsl_rng_alloc (T);
k = gsl_ran_poisson (r, expected_value);
gsl_rng_free (r);
return k;
}
Now, I know that if I had all the aforementioned parts in the same file [e.g. myfile.c] I could compile from terminal using:
gcc myfile.c -o myfile -lgsl -lgslcblas -lm
and it works because I tried. But how to ask to QEMU Makefile to do this? honestly this Makefile seems too complex for my entry level. I googled info about makefiles and after reading I thought to find in QEMU Makefile something like:
LDLIBS := -lgsl -lgslcblas -lm
[...]
$(CC) -o $@ $^ $(LDLIBS)
but searching for the real QEMU Makefile implementation I found the rules.mak file where:
%.o: %.c
$(call quiet-command,$(CC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) $($@-cflags) -c -o $@ $<," CC $(TARGET_DIR)$@")
Maybe this is the line to tweak. The question is: how to tweak? I tried to edit this line as:
%.o: %.c
$(call quiet-command,$(CC) $(QEMU_INCLUDES) $(QEMU_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) $($@-cflags) -c -o $@ $< -lgsl -lgslcblas -lm," CC $(TARGET_DIR)$@")
but it didn't work and I got the following errors
ubuntu@ubuntu:~/Desktop/qemu-2.1.0$ make
GEN config-host.h
GEN trace/generated-tracers.h
GEN trace/generated-tracers.c
GEN arm-softmmu/config-target.h
LINK arm-softmmu/qemu-system-arm
../hw/sd/sd.o: In function `poisson_distribution':
/home/ubuntu/Desktop/qemu-2.1.0/include/hw/mycard.h:1630: undefined reference to `gsl_rng_env_setup'
/home/ubuntu/Desktop/qemu-2.1.0/include/hw/mycard.h:1632: undefined reference to `gsl_rng_default'
/home/ubuntu/Desktop/qemu-2.1.0/include/hw/mycard.h:1633: undefined reference to `gsl_rng_alloc'
/home/ubuntu/Desktop/qemu-2.1.0/include/hw/mycard.h:1641: undefined reference to `gsl_ran_poisson'
/home/ubuntu/Desktop/qemu-2.1.0/include/hw/mycard.h:1646: undefined reference to `gsl_rng_free'
../hw/sd/sd.o: In function `weibull_distribution':
/home/ubuntu/Desktop/qemu-2.1.0/include/hw/mycard.h:1676: undefined reference to `gsl_rng_env_setup'
/home/ubuntu/Desktop/qemu-2.1.0/include/hw/mycard.h:1678: undefined reference to `gsl_rng_default'
/home/ubuntu/Desktop/qemu-2.1.0/include/hw/mycard.h:1679: undefined reference to `gsl_rng_alloc'
/home/ubuntu/Desktop/qemu-2.1.0/include/hw/mycard.h:1687: undefined reference to `gsl_ran_weibull'
/home/ubuntu/Desktop/qemu-2.1.0/include/hw/mycard.h:1692: undefined reference to `gsl_rng_free'
collect2: error: ld returned 1 exit status
make[1]: *** [qemu-system-arm] Error 1
make: *** [subdir-arm-softmmu] Error 2
And after all I think it would not be a perfect solution since the other files don't need GSL library and there's no need to apply -lgsl -lgslcblas -lm to every .c file. I would like to create a new Makefile where all the other files continue to be compiled like the original Makefile but when it comes to sd.c I would like it to be compiled as said before in order to avoid undefined references
Thanks in advance to the persons that will give me precise suggestions to help me fix this issue