If jpeg.o is the proper o file, then ditch -ljpeg and just put jpeg.o in your final gcc command.
im getting the following error
(i switched ti ubuntu for a bit). im getting the same error in windows. its directly related to the jpeg lib that i dont haveCode:$ gcc jpeg64.o histogram3.o jpeg64.o: In function `loadJPG': jpeg.c:(.text+0xa7): undefined reference to `jpeg_std_error' jpeg.c:(.text+0xc7): undefined reference to `jpeg_CreateDecompress' jpeg.c:(.text+0xe0): undefined reference to `jpeg_stdio_src' jpeg.c:(.text+0xf4): undefined reference to `jpeg_read_header' jpeg.c:(.text+0x103): undefined reference to `jpeg_start_decompress' jpeg.c:(.text+0x1d0): undefined reference to `jpeg_read_scanlines' jpeg.c:(.text+0x332): undefined reference to `jpeg_finish_decompress' jpeg.c:(.text+0x341): undefined reference to `jpeg_destroy_decompress' collect2: ld returned 1 exit status norma@ubuntu:~/Desktop$
Okay, so libjpeg is actually needed. In Ubuntu, you can fire up synaptic and get "libjpeg62". (I already have it installed, and I don't remember installing it special, but I guess I must have.)
You can also get libjpeg for Windows if you want.
Trying to link the provided jpeg.o compiled for Linux using GCC for windows will bomb. Linux GCC doesn't add leading underscores to function names while Windows GCC does. You'll get lots of errors like "jpeg.c.text+0x57): undefined reference to fopen" because the lib function name under Win will be _fopen instead.
There's a chance the file is getting corrupted. Do "md5sum Lenna.jpg" in the directory you're building and running your code in. It should look like thisCode:94df9c5dd1ae4a348e858e4ea43cd023 *Lenna.jpg
If you know where the file is on the server, can't you just use cp to copy if to your local working directory? If not, do you have curl on the linux machine? This would make it as simple asto copy to whatever local directory you're working from.Code:curl http://www.cise.ufl.edu/class/cgs3460su11/homework/Lenna.jpg > Lenna.jpg
I did a simple test and everything works as expected :
ETA - the return value is incorrect but close enough - the real size of the file should be 2*8 + (256*256) * 4 = 262152. That's OK, you never need it for the homework you're asked to do.Code:evergrove{82}> cat jpeg_main.c #include <stdio.h> #include "jpeg.h" int main (void) { printf ("%d\n", loadJPG("Lenna.jpg", "Lenna.bin")); return 0; } evergrove{83}> gcc -o jpeg_main jpeg_main.c jpeg64.o -ljpeg evergrove{84}> ./jpeg_main 262146
Last edited by KCfromNC; 07-27-2011 at 10:37 AM.
Thanks, tabstop and KCfromNC. My ubuntu crapped out yesterday so I'm going to reinstall and try to work through that.
Were being told to compile using
The server we sign onto using putty is linux. Would the linking of jpeg64.o still cause problems since im in windows? Basically, does the OS need to be linux or just where im compiling/linking?Code:gcc histogram.c jpeg64.o -ljpeg ./a.out lenna.jpg out.txt 4
I totally appreciate all the responses btw! You guys rock! =D
Thanks for all the info! Ubuntu it is! =D
this works perfectly! thanks!Code:evergrove{83}> gcc -o jpeg_main jpeg_main.c jpeg64.o -ljpeg evergrove{84}> ./jpeg_main 262146
what does md5sum do? i read up a little on it and it seems its just an algorithm that verifies the file and 'returns' a value that indicates validity but doesnt create or change the original file?
It's a bit more complex than this, but basically it adds up each byte and gets a sum. If the sum for the exe is the same as the original, then it hasn't been tampered with. If it's different, the two files aren't exactly the same.Now it doesn't actually just do that, but basically that is what happens. (It actually matters if you take the first and second byte of the file and swap their positions - that would give a different md5sum, whereas what I did would not. But just as a way to understand what happens, that's basically what it does.Code:for( sum = x = 0; x < size of file in bytes; x++ ) sum += this byte;
Quzah.
Hope is the first step on the road to disappointment.
thanks for the clarification, quzah! ^_^
new issue: reading information from the binary file.
this is the part of my code that reads the values from the file and its output. i know the dimension values are correct, not sure about pixel 1 values. either way, im assuming theyre right since the values for RGB(first 3 ints)are less than 255. the second set are way off. not sure what im doing wrong if the 1st set works...any ideas/insight?
Code:thunder:112% ./load 262146 DIMENSIONS(in pixels): 256 x 256 124 135 225 4198912 //pixel1 32636 1788271239 225 4198912 //pixel2
Code:fread(&width,sizeof(width),1,fp); //(char* str,int n,FILE* file) fread(&height,sizeof(height),1,fp); printf("DIMENSIONS(in pixels): %d x %d\n",width,height); fread(&h_b,1,1,fp); fread(&h_g,1,1,fp); fread(&h_r,1,1,fp); fread(&alpha,1,1,fp); printf("%d %d %d %d\n",h_b,h_g,h_r,alpha); fread(&h_b2,1,1,fp); fread(&h_g2,1,1,fp); fread(&h_r2,1,1,fp); fread(&alpha2,1,1,fp); printf("%d %d %d %d\n",h_b2,h_g2,h_r2,alpha2);
Is alpha an int or a char? If you are only filling one byte of it, you aren't zeroing out the other 3 (assuming 4 byte ints).
Quzah.
Hope is the first step on the road to disappointment.