1

I've just downloaded Cygwin and I've installed those useful packages from https://cygwin.mirror.constant.com library :

lynx, wget, curl, rsync, tar, bash-completion,make gcc-c, gcc-g++, gcc-fortran openssh and chere

I've seen on forums that they are the basic packages you should have. After this, I've tried to create object files with make in a folder with a makefile on it but here's the result:

$ make
gcc -g -m32 -g -Wall -c -o tp3.o tp3.c
gcc -g -m32 -g -Wall -c -o equals.o equals.s
gcc -g -m32 -g -Wall -c -o transpose.o transpose.s
gcc -g -m32 -g -Wall -c -o multiply.o multiply.s
gcc -g -m32 -g -Wall -c -o diagonal.o diagonal.s
gcc -g -m32 -g -Wall -c -o average.o average.s
gcc -g -m32 -g -Wall -o tp3 tp3.o equals.o transpose.o multiply.o diagonal.o average.o
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/../../../../x86_64-pc-cygwin/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-cygwin/6.4.0//libgcc_s.dll.a when searching for -lgcc_s
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/../../../../x86_64-pc-cygwin/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/libgcc_s.dll.a when searching for -lgcc_s
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/../../../../x86_64-pc-cygwin/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-cygwin/6.4.0//libgcc_s.dll.a when searching for -lgcc_s
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/../../../../x86_64-pc-cygwin/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/libgcc_s.dll.a when searching for -lgcc_s
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/../../../../x86_64-pc-cygwin/bin/ld: cannot find -lgcc_s
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/../../../../x86_64-pc-cygwin/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-cygwin/6.4.0//libgcc.a when searching for -lgcc
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/../../../../x86_64-pc-cygwin/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-cygwin/6.4.0//libgcc.a when searching for -lgcc
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/../../../../x86_64-pc-cygwin/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/libgcc.a when searching for -lgcc
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/../../../../x86_64-pc-cygwin/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/libgcc.a when searching for -lgcc
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/../../../../x86_64-pc-cygwin/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-cygwin/6.4.0//libgcc.a when searching for -lgcc
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/../../../../x86_64-pc-cygwin/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/libgcc.a when searching for -lgcc
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/../../../../x86_64-pc-cygwin/bin/ld: cannot find -lgcc
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/../../../../x86_64-pc-cygwin/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/../../../libcygwin.a when searching for -lcygwin
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/../../../../x86_64-pc-cygwin/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/../../../libcygwin.a when searching for -lcygwin
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/../../../../x86_64-pc-cygwin/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/../../../libcygwin.a when searching for -lcygwin
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/../../../../x86_64-pc-cygwin/bin/ld: cannot find -lcygwin
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/../../../../x86_64-pc-cygwin/bin/ld: cannot find -ladvapi32
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/../../../../x86_64-pc-cygwin/bin/ld: cannot find -lshell32
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/../../../../x86_64-pc-cygwin/bin/ld: cannot find -luser32
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/../../../../x86_64-pc-cygwin/bin/ld: cannot find -lkernel32
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/../../../../x86_64-pc-cygwin/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-cygwin/6.4.0//libgcc_s.dll.a when searching for -lgcc_s
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/../../../../x86_64-pc-cygwin/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/libgcc_s.dll.a when searching for -lgcc_s
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/../../../../x86_64-pc-cygwin/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-cygwin/6.4.0//libgcc_s.dll.a when searching for -lgcc_s
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/../../../../x86_64-pc-cygwin/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/libgcc_s.dll.a when searching for -lgcc_s
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/../../../../x86_64-pc-cygwin/bin/ld: cannot find -lgcc_s
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/../../../../x86_64-pc-cygwin/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-cygwin/6.4.0//libgcc.a when searching for -lgcc
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/../../../../x86_64-pc-cygwin/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-cygwin/6.4.0//libgcc.a when searching for -lgcc
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/../../../../x86_64-pc-cygwin/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/libgcc.a when searching for -lgcc
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/../../../../x86_64-pc-cygwin/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/libgcc.a when searching for -lgcc
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/../../../../x86_64-pc-cygwin/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-cygwin/6.4.0//libgcc.a when searching for -lgcc
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/../../../../x86_64-pc-cygwin/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-pc-cygwin/6.4.0/libgcc.a when searching for -lgcc
/usr/lib/gcc/x86_64-pc-cygwin/6.4.0/../../../../x86_64-pc-cygwin/bin/ld: cannot find -lgcc
collect2: error: ld returned 1 exit status
make: *** [Makefile:18: tp3] Error 1

My Makefile looks like this:

CC=gcc
CFLAGS=-g -m32 -g -Wall
RM=rm -f
TARGET=tp3
OBJECTS=tp3.o equals.o transpose.o multiply.o diagonal.o average.o

.PHONY: clean

.c.o:
    $(CC) $(CFLAGS) -c -o $@ $<

.s.o:
    $(CC) $(CFLAGS) -c -o $@ $<

all: tp3

$(TARGET): $(OBJECTS)
    $(CC) $(CFLAGS) -o $@ $^

clean:
    $(RM) *.o $(TARGET)

An example of one of the assembly file multiply.s:

.globl matrix_multiply_asm

matrix_multiply_asm:
        push %ebp      /* save old base pointer */
        mov %esp, %ebp /* set ebp to current esp */

        /* Write your solution here */

        leave          /* restore ebp and esp */
        ret            /* return to the caller */

It compiles quietly well but a big error that I've tried to resolve comes right after it. It says that g is incompatible [...] when searching for -lgcc_s. When I work on Linux, I don't have this error. Can someone explain me what it means and what can I do? Also, I'm not quite sure what command to use to execute a file (.dat) after the make command on this terminal.

PS: The name of my current folder is tp3 and I have .c, .s and .dat files in it.

Michael Petch
  • 46,082
  • 8
  • 107
  • 198
polycodor
  • 91
  • 1
  • 12

1 Answers1

1

From the output I can tell you have installed 64-bit Cygwin. The 64-bit Cygwin gcc/g++ that you have installed doesn't include the 32-bit libraries and support files. That causes the issue with the appropriate files not being found. Your Makefile appears to be generating 32-bit programs (-m32 option)

You have a couple of choices:

  • Make 64-bit executables and remove the -m32 option in your Makefile. Since the assembly file templates your professor has given you have 32-bit prologue and epilogue this isn't really an option in your case. It appears they want you to create a 32-bit program.
  • Make 32-bit executable with a 32-bit cross compiler

If you want 64-bit Cygwin to generate 32-bit programs you will need to rerun the installer and add these additional packages: cygwin32-gcc-core and cygwin32-gcc-g++

You will have to modify the Makefile so that you use i686-pc-cygwin-gcc instead of gcc. That can be done by modifying:

CC=gcc

to be:

CC=i686-pc-cygwin-gcc

i686-pc-cygwin-gcc is a Cygwin cross compiler that builds 32-bit (i686) programs and has a set of the 32-bit libraries and support files needed to generate 32-bit C programs.

The 32-bit Cygwin Windows cross compiler will require you to add leading underscores to the functions you mean to export (via .globl directive) to your C code. As an example your multiply.s file would have to look like:

.globl _matrix_multiply_asm  /* added leading underscore here */

_matrix_multiply_asm:        /* added leading underscore here */
        push %ebp      /* save old base pointer */
        mov %esp, %ebp /* set ebp to current esp */

        /* Write your solution here */

        leave          /* restore ebp and esp */
        ret            /* return to the caller */

You will have to make a similar change to each of the .s files. Once properly assembled and linked you can run it with the command:

./tp3.exe testmatrix2.dat

If you don't wish to add the underscores to the beginning of the exported functions in your .s files you can get your make file to add them for you with GCC's -fleading-underscore option. You apply this to just the .s files. Your make file could then look like:

CC=i686-pc-cygwin-gcc
CFLAGS=-g -m32 -g -Wall
CFLAGS_AS=$(CFLAGS) -fleading-underscore
RM=rm -f
TARGET=tp3
OBJECTS=tp3.o
OBJECTS_AS=equals.o transpose.o multiply.o diagonal.o average.o

.PHONY: clean

.c.o:
    $(CC) $(CFLAGS) -c -o $@ $<

.s.o:
    $(CC) $(CFLAGS_AS) -c -o $@ $<

all: tp3

$(TARGET): $(OBJECTS) $(OBJECTS_AS)
    $(CC) $(CFLAGS) -o $@ $^

clean:
    $(RM) *.o $(TARGET)
Michael Petch
  • 46,082
  • 8
  • 107
  • 198
  • I suggest to just remove the `-m32` – matzeri Mar 14 '18 at 20:26
  • @matzeri Did you see option `Make 64-bit executables and remove the -m32 option in your Makefile` in my answer. Problem is that his assignment requires 32-bit as they are expected to fill in their code between existing function prologue/epilogue that specifically use 32-bit. My original answer (see the edits) weighed more heavily on the first option, until I found the exact assignment (with all files) then I opted in favor of the answer which uses 32-bit code. You have to realize original question the OP posted was w/o a lot of context. heavily edited his question once I found the assignment. – Michael Petch Mar 14 '18 at 20:37
  • @matzeri : so I suggested that as an option, but pointed out why in this assignment that may not be an option. It may be for someone else, which is why I mentioned it. For this assignment, 32-bit may be a requirement. And it is a good exercise to see how you can do this on Cygwin. – Michael Petch Mar 14 '18 at 20:39
  • If 32bit is a requirement, he/she can use a Cygwin32 bit installation. Cross compilation seems an additional complication. – matzeri Mar 16 '18 at 08:33