problems with make on cygwin

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Bob the Avenger

problems with make on cygwin

Post by Bob the Avenger »

When i call make -f makefile on cygwin i get the error "i568-elf-gcc.exe: This application has failed to start because cygwin1.dll was not found. Re-installing the application may fix this problem." But i have tried reinstalling cygwin several times. Also when i manually try to compile it works fine, so the problem doesn't seem to be in i586-elf-gcc. The contents of the makefiles i've tried running are:

Code: Select all

LIBDIR = ../include
GCC = i586-elf-gcc -Wall -pedantic -nostdlib  -std=gnu99 -nodefaultlibs -ffreestanding -finline-functions -O2 -I$(LIBDIR) -c -o 
NASM = nasm -f elf -o
AS = i586-elf-as -o
LNKR_SCRIPT = link.ld
OUTPUT = kernel.elf
OBJS = loader.o main.o gdt.o paging.o ../libc/string.o ../libc/video.o
LINK = i586-elf-ld -Map mapfile.map -T $(LNKR_SCRIPT) -o $(OUTPUT) $(OBJS)

# cross compiler path
export PATH=$PATH:/cygdrive/C/cross/bin

kernel.elf: $(OBJS)
   $(LINK)
#loader.o: loader.asm 
#   $(NASM) loader.asm
main.o: main.c
   $(GCC) main.c
gdt.o: gdt.c
   $(GCC) gdt.c
paging.o: paging.c
   $(GCC) paging.c 
and

Code: Select all

LIBDIR = ../include
GCC = i586-elf-gcc -Wall -pedantic -nostdlib  -std=gnu99 -nodefaultlibs -ffreestanding -finline-functions -O2 -I$(LIBDIR) -c -o 
NASM = nasm -f elf
AS = i586-elf-as -o
LNKR_SCRIPT = link.ld
OUTPUT = kernel.elf
OBJS = loader.o main.o gdt.o paging.o ../libc/string.o ../libc/video.o
LINK = i586-elf-ld -Map mapfile.map -T $(LNKR_SCRIPT) -o $(OUTPUT) $(OBJS)

# cross compiler path
export PATH=$PATH:/cygdrive/C/cross/bin

string.o: string.c
   $(GCC) string.c
video.o: video.c
   $(GCC) video.c
Thanks in advance for any help.
Cjmovie

Re:problems with make on cygwin

Post by Cjmovie »

I'm no expert, but...
Most likely it's because when you run a makefile, it's running the program from inside a different location, so when it tries to access "cygwin1.dll" (the POSIX layer for Cygwin programs, IIRC) directly, it can't find it (because it's operating out of a directory other than its own).
The way to fix this is to check your PATH variable and make sure it points into your cygwin '\bin' directory and also make sure cygwin1.dll is located in there. For a cheap solution, copy (COPY!) and paste cygwin1.dll into your C:\Windows\System32 (or whatever your root windows installation is) so it can be accessed.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:problems with make on cygwin

Post by Pype.Clicker »

Just out of curiousity, have you located cygwin1.dll somewhere (and most precisely, can you tell us where it stands?)

One of the things that looks weird to me is your line

Code: Select all

PATH=$PATH:xxxxx
I remember i had issues when reusing the same variable on both left and right side of a Make environment setting. IIRC you have "PATH := <expression>" that better handle those cases.

And you should most likely have "$(PATH)" on the right side rather than "$PATH" ... just echo $(PATH) before compiling to make sure it worked.


You can also try to call "i586-elf-gcc --verbose" to know where GCC fetches its libraries etc. That will also tell whether your problem depends on your makefile or not (if not, even --verbose may fail, unfortunately)

Hope it'll help: on a Unix system i'd investigate such problems with "strace" tool, but for Windows, i can merely emit hypothesis ...
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:problems with make on cygwin

Post by Solar »

The culprit is the following line:

Code: Select all

export PATH=$PATH:/cygdrive/C/cross/bin
By default, make uses /bin/sh as shell - the above is a valid bash statement, but apparently Cygwin 'sh' chokes of it. (I was able to reproduce this behaviour - PATH is getting truncated somehow.)

The solution is to put that 'export' statement either in your local profile (~/.bash_profile) or the global one (/etc/profile). This way it will get passed to 'make' correctly, and you can delete the 'export' line from your Makefile.

Edit: Looking at the other two posts, I might be wrong about the reasons of the error, but the solution sure works. ;)
Every good solution is obvious once you've found it.
Bob the Avenger

Re:problems with make on cygwin

Post by Bob the Avenger »

Your a genius!!! it was the PATH bit, i commented it out and it ran. Now i got to fix the errors in the make file, i get i586-elf-gcc: no input files.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:problems with make on cygwin

Post by Solar »

Probably one of the *.o files you specified in $(OBJS) does not exist, and doesn't have a corresponding *.c file.

Make tries to be pretty smart about certain things. kernel.elf depends on all the files in $(OBJS). If one of those doesn't exist, make tries to create it. If there is no explicit rule (like, for loader.o ../libc/string.o ../libc/video.o in the first example), make tries to figure out what to do using "implicit" rules. One of them says, "generate *.o files from *.c files by running $(GCC)".

You probably see where this breaks when, say, there is no ../libc/string.c...
Every good solution is obvious once you've found it.
Bob the Avenger

Re:problems with make on cygwin

Post by Bob the Avenger »

when i run the second makefile, the command passed to gcc is
"i586-elf-gcc -Wall -pedantic -nostdlib -std=gnu99 -nodefaultlibs -ffreestanding -finline-functions -O2 -I../include -c -o string.c"
somehow string.o doesn't get passed
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:problems with make on cygwin

Post by Solar »

Hint: I posted a functional (so I hope) Makefile in this thread. It uses filename globbing to find the sources to compile, which is more stable than hardcoding (and forgetting to update) filenames in your Makefile.
Every good solution is obvious once you've found it.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:problems with make on cygwin

Post by Pype.Clicker »

Bob the Avenger wrote: Your a genius!!! it was the PATH bit, i commented it out and it ran. Now i got to fix the errors in the make file, i get i586-elf-gcc: no input files.

oooops . i hope you had a backup of those .c files !

Code: Select all

GCC = i586-elf-gcc -Wall -pedantic -nostdlib  -std=gnu99 -nodefaultlibs -ffreestanding -finline-functions -O2 -I$(LIBDIR) -c -o 
...
$(GCC) strings.c
will expand into

Code: Select all

i586-elf-gcc <all your flags> -c -o strings.c
thus there's no input and strings.c is your output!
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:problems with make on cygwin

Post by Solar »

Whoa... another point for keeping your sources under version control from day #1. :D
Every good solution is obvious once you've found it.
Bob the Avenger

Re:problems with make on cygwin

Post by Bob the Avenger »

thanks, looks very impressive, i'll try it now
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:problems with make on cygwin

Post by Solar »

Bob the Avenger wrote: somehow string.o doesn't get passed
You don't tell make anything about passing string.o anywhere...
Every good solution is obvious once you've found it.
Bob the Avenger

Re:problems with make on cygwin

Post by Bob the Avenger »

thanks for the link Solar, that makefile worked like a charm, i wish both you, Pipe.Clicker and CJmovie much toffee
Post Reply