Re: Fwd: help in the usage of compiling c files

Francesco Lazzarotto <[email protected]> Thu, 24 Sep 2020 19:29:49 +0200
Newsgroups gmane.comp.gnu.mingw.user
Message-ID <CAMyLAb=YaCtTd4E11WYH9s4XjxJotPv5dxb6Jz=dfCE7iJrQkg@mail.gmail.com>
Hello, you should compile object files and then link, like

cc -g -I. -ansi -Wall -pedantic   -c -o image_size.o image_size.c
cc -g -I. -ansi -Wall -pedantic   -c -o readimage.o readimage.c
cc -g -I. -ansi -Wall -pedantic   -c -o jpegll_enc.o jpegll_enc.c
cc -g -o encoder image_size.o readimage.o jpegll_enc.o -L. -lm

this works for me using gcc 7.5 on Linux, then it's better to put (cc is
alias to gcc)
compile commands in a Makefile such:

text file Makefile:

#---------------------------------------------------
TARGET1=encoder
CC=cc -g

SRC = $(wildcard *.c)
OBJ = $(SRC:.c=.o)
CFLAGS = -I. -ansi -Wall -pedantic
LDFLAGS = -L. -lm

TARGETS = $(TARGET1)

$(TARGET1): $(OBJ)
$(CC) -o $@ $^ $(LDFLAGS)

all: $(TARGETS)
echo "done all targets"

.PHONY: clean
clean:
rm -f $(OBJ) $(TARGETS)
#---------------------------------------------------

then you can compile with

make

(log files attached, created with make > out.log 2> err.log )
If you want to compile on mingw you need to change cc with
mingw compiler command.
(i686-w64-mingw32-gcc.exe or x86_64-w64-mingw32-gcc.exe on MS win msys2)
you can also remove warnings putting header files as compiler tips write.

Hope this can help you.

Cheers.
Francesco Lazzarotto.


On Thu, 24 Sep 2020 at 18:45, Aileen Sengupta <[email protected]>
wrote:

>
> ---------- Forwarded message ---------
> From: Aileen Sengupta <[email protected]>
> Date: Mon, 21 Sep 2020, 01:18
> Subject: help in the usage of compiling c files
> To: <[email protected]>
>
>
>
> Dear Team,
>
> I have recently installed the MinGW and I am trying to run the following
> command
> gcc -o encoder jpegll_enc.c idc.h readimage.c image_size.c and I get the
> following error:
>
> [image: image.png]
>
> I have all the necessary files in the same folder as shown in the command
> prompt.
> I have attached the files in the email. I have tried every possible
> solutions and I needed help. Can you help me with the possible solution?
> --
> Thanks and Regards,
> Aileen Sengupta
>
> https://sites.google.com/site/aileensengupta/
> https://in.linkedin.com/in/aileen-sengupta-91547a24
> _______________________________________________
> MinGW-Users mailing list
> [email protected]
>
> This list observes the Etiquette found at
> http://www.mingw.org/Mailing_Lists.
> We ask that you be polite and do the same.  Disregard for the list
> etiquette may cause your account to be moderated.
>
> _______________________________________________
> You may change your MinGW Account Options or unsubscribe at:
> https://lists.osdn.me/mailman/listinfo/mingw-users
> Also: mailto:[email protected]?subject=unsubscribe



-- 
******************************************************************
*** PLEASE NOTE MY PERSONAL EMAIL ADDRESS
*** HAS CHANGED TO [email protected]
******************************************************************
Francesco Lazzarotto
mailto:[email protected]
skype:fralaz1971

_______________________________________________
MinGW-Users mailing list
[email protected]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.osdn.me/mailman/listinfo/mingw-users
Also: mailto:[email protected]?subject=unsubscribe
image.png (image/png, 50.9 KB) - not displayed
Makefile (application/octet-stream, 281 B) - not displayed
out.log (text/x-log, 259 B)
cc -g -I. -ansi -Wall -pedantic   -c -o image_size.o image_size.c
cc -g -I. -ansi -Wall -pedantic   -c -o readimage.o readimage.c
cc -g -I. -ansi -Wall -pedantic   -c -o jpegll_enc.o jpegll_enc.c
cc -g -o encoder image_size.o readimage.o jpegll_enc.o -L. -lm
err.log (text/x-log, 1.1 KB)
readimage.c: In function ‘readimage’:
readimage.c:39:3: warning: implicit declaration of function ‘exit’ [-Wimplicit-function-declaration]
   exit(1);
   ^~~~
readimage.c:39:3: warning: incompatible implicit declaration of built-in function ‘exit’
readimage.c:39:3: note: include ‘<stdlib.h>’ or provide a declaration of ‘exit’
readimage.c:33:13: warning: unused variable ‘c’ [-Wunused-variable]
     {int r, c;
             ^
jpegll_enc.c:31:6: warning: return type of ‘main’ is not ‘int’ [-Wmain]
 void main(int argc, char **argv)
      ^~~~
jpegll_enc.c: In function ‘main’:
jpegll_enc.c:47:12: warning: implicit declaration of function ‘getopt’; did you mean ‘getcode’? [-Wimplicit-function-declaration]
   while((c=getopt(argc,argv,"i:o:m:x:y:h"))!=EOF)
            ^~~~~~
            getcode
jpegll_enc.c:38:15: warning: unused variable ‘optind’ [-Wunused-variable]
   extern int  optind;
               ^~~~~~
jpegll_enc.c:37:11: warning: unused variable ‘ifp’ [-Wunused-variable]
     FILE *ifp, *ofp;
           ^~~