FLTK vuole g++, e cosi' ho degli inaspettati "undefined reference", che invece non ho usando gcc.
Dopo molti tentativi ho risolto ricompilando la libreria, libjpeg, con g++ invece che con gcc,
e rinominandola libjpeg++.a. Ma non e' certo la soluzione ottimale.
Non ci sono dei flag per g++ (o altri sistemi) per fargli linkare il mio codice con le funzioni di libjpeg.a
(quella di default di slackware, cioe' compilata con gcc) ?
Ho estratto il problema in un mimimo sorgente, example.c,
tratto dall' example.c compreso nei sorgenti di http://www.ijg.org.
Ecco cosa succede:
Se compilo cosi':
Codice: Seleziona tutto
bash-3.2$ gcc -Wall -o example example.c -ljpeg
bash-3.2$ example
bash-3.2$
e' totto OK
mentre se uso g++:
Codice: Seleziona tutto
bash-3.2$ g++ -Wall -o example example.c -ljpeg
/tmp/cca7S8eB.o: In function `write_JPEG_file(char*, int)':
example.c:(.text+0x14): undefined reference to `jpeg_std_error(jpeg_error_mgr*)'
example.c:(.text+0x33): undefined reference to `jpeg_CreateCompress(jpeg_compress_struct*, int, unsigned int)'
example.c:(.text+0x87): undefined reference to `jpeg_stdio_dest(jpeg_compress_struct*, _IO_FILE*)'
example.c:(.text+0xc3): undefined reference to `jpeg_set_defaults(jpeg_compress_struct*)'
example.c:(.text+0xda): undefined reference to `jpeg_set_quality(jpeg_compress_struct*, int, int)'
example.c:(.text+0xee): undefined reference to `jpeg_start_compress(jpeg_compress_struct*, int)'
example.c:(.text+0x130): undefined reference to `jpeg_write_scanlines(jpeg_compress_struct*, unsigned char**, unsigned int)'
example.c:(.text+0x152): undefined reference to `jpeg_finish_compress(jpeg_compress_struct*)'
example.c:(.text+0x172): undefined reference to `jpeg_destroy_compress(jpeg_compress_struct*)'
collect2: ld returned 1 exit status
bash-3.2$
sapere se succede solo sul mio computer.
ecco example.c:
Codice: Seleziona tutto
/* example.c
test tratto da example.c compreso nei sorgenti
di www.ijg.org (jpegsrc.v6b.tar.gz).
gcc -Wall -o example example.c -ljpeg */
#include <stdio.h>
#include <jpeglib.h>
#include <setjmp.h>
JSAMPLE * image_buffer; /* Points to large array of R,G,B-order data */
int image_height=9; /* Number of rows in image */
int image_width=9; /* Number of columns in image */
void write_JPEG_file(char * filename, int quality)
{
struct jpeg_compress_struct cinfo;
struct jpeg_error_mgr jerr;
FILE * outfile; /* target file */
JSAMPROW row_pointer[1]; /* pointer to JSAMPLE row[s] */
int row_stride; /* physical row width in image buffer */
cinfo.err = jpeg_std_error(&jerr);
jpeg_create_compress(&cinfo);
if ((outfile = fopen(filename, "wb")) == NULL) {
fprintf(stderr, "can't open %s\n", filename); return; }
jpeg_stdio_dest(&cinfo, outfile);
cinfo.image_width = image_width; /* image width and height, in pixels */
cinfo.image_height = image_height;
cinfo.input_components = 3; /* # of color components per pixel */
cinfo.in_color_space = JCS_RGB; /* colorspace of input image */
jpeg_set_defaults(&cinfo);
jpeg_set_quality(&cinfo, quality, TRUE /* limit to baseline-JPEG values */);
jpeg_start_compress(&cinfo, TRUE);
row_stride = image_width * 3; /* JSAMPLEs per row in image_buffer */
while (cinfo.next_scanline < cinfo.image_height) {
row_pointer[0] = & image_buffer[cinfo.next_scanline * row_stride];
(void) jpeg_write_scanlines(&cinfo, row_pointer, 1); }
jpeg_finish_compress(&cinfo);
fclose(outfile);
jpeg_destroy_compress(&cinfo);
}
int main(int argc, char *argv[])
{
int n=0;
unsigned char pnt[243]; /* creo un array che contiene un'immagine 9x9 RGB */
/* carico un po' di valori RGB per produrre un'immagine con tre righe grige: */
while(n<81){pnt[n]=180;n++;} while(n<162){pnt[n]=120;n++;} while(n<243){pnt[n]=60;n++;}
image_buffer=pnt;
write_JPEG_file("out.jpg",90);
return(0);
}
/*** EOF ***/
Ciao,
Rogx.


