ATC - dolores de Cabeza con C¶
Linking libraries¶
Tools:
- gcc: compilador.
- pkg-config: para producir links, estaticos o dinamicos, para incluir una libreria en gcc.
pkg-config --static --libs libtiff-4
pkg-config --libs libtiff-4
- cpp: C pre-processor, lo sué para buscar header files en el sistema.
cpp -v /dev/null -include "tiffio.h"
- ldd: para encontrar las libraries que se linkearon a un binario.
- https://superuser.com/a/239593
- Las static libraries incluidas no aparecen en ldd, pero si gcc se corrio con "-g" (para debugging) se podrían ver con otros comandos: https://stackoverflow.com/a/1124581/11524079
Notes:
- El orden de los "links" en gcc es importante, las dependencias "más altas" van al final.
- Las librerias estaticas tipo "libXXX.a" (son "archives" de archivos ".o") se incluyen con la opción "-L" seguida el path a la carpeta que las contiene, y hay que agregar un "-lXXX" después.
Guia para incluir cosas:
- -I
- The include directory will be location of the header ".h" files.
- -L
- The library directory will be the location of the library (.a or .so)
- -l
- And the library name will be the name of the library file, without the leading 'lib' prefix or its extension (i.e. -lsal rather than -l libsal.a ).
Makefiles¶
Ver: https://makefiletutorial.com/
A Makefile consists of a set of rules. A rule generally looks like this:
targets : prerequisites
command
command
command
Shell/env variables: https://stackoverflow.com/a/28891382/11524079
Escribir texto en archivos comprimidos¶
Es magia: https://stackoverflow.com/a/9156471/11524079
gzFile fp;
fp = gzopen(NAME, "wb");
gzprintf(fp, "Hello, %s!\n", "world");
gzclose(fp);
Debuguear con gdb¶
gdb está bastante bueno.
Para arreglar una cosa en CellID lo llamé así:
gdb --args cell -b /tmp/rcell.test.dir/dir649d396b4a60/Position11/bf_rcell2.649d2105a3d2.txt -f /tmp/rcell.test.dir/dir649d396b4a60/Position11/fl_rcell2649d4f0f724a.txt -o /tmp/rcell.test.dir/dir649d396b4a60/Position11/out -p /tmp/rcell.test.dir/parameters_649d50293e59.txt
Era importante el flag --args
para que cell
recibiera los argumentos que están después.
Luego en el prompt de gdb luego puse run
para que se ejecute el programa, y luego where
para que me muestre el traceback que necesitaba:
Compilar en modo "debug"¶
Para gdb funcionara, tuve que compilar todo CellID en modo debug.
Si no, tarde o temprano aparece un error que impide usar where
para ver el trace:
(No debugging symbols found in cell)
Compilar en modo debugging implica pasarle el flag -g
a gcc, pero por algún motivo no alcanzaba con ponerlo enfrente del build target cell
en el Makefile, usando gcc -g -o
bla bla bla.
Lo que sirvió fue lo siguiente:
CFLAGS = -g -Wall
CC = gcc $(CFLAGS)
CLIBS = -ltiff -lzstd -llzma -ljpeg -lz -lm -lwebp
objects = cell.o segment.o tif.o nums.o date_and_time.o fit.o fft.o fft_stats.o split_and_overlap.o contiguous.o fl_dist.o align_image.o flatten.o
cell: $(objects)
$(CC) -o $@ $(CFLAGS) $(objects) $(CLIBS)
cell.o: segment.h tif_routines.h date_and_time.h nums.h point.h image_type.h align_image.h split_and_overlap.h parameters.h
tif.o: tif_routines.h
segment.o: segment.h nums.h fit.h tif_routines.h fft_stats.h point.h image_type.h split_and_overlap.h contiguous.h fl_dist.h parameters.h flatten.h
contiguous.o: contiguous.h
nums.o: nums.h tif_routines.h
date_and_time.o: date_and_time.h
fit.o: fit.h
fft.o: fft.h complex.h
fft_stats.o: segment.h fft.h fft_stats.h point.h complex.h
split_and_overlap.o: split_and_overlap.h contiguous.h
fl_dist.o: fl_dist.h contiguous.h
align_image.o: align_image.h
flatten.o: flatten.h
Imagino que la parte de CFLAGS = -g -Wall
y CC = gcc $(CFLAGS)
debe haber configurado algo más globalmente, pero ni idea. Funcionó.