views:

1183

answers:

3

I'm getting a totally bizzare error trying to compile a C program using GCC. Here is the batch file I am using:

echo Now compiling, assembling, and linking the core:
nasm -f aout -o start.o start.asm

gcc -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -I./include -c -o consoleio.o consoleio.c
gcc -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -I./include -c -o core.o core.c
gcc -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -I./include -c -o system.o system.c

ld -T link.ld -o core.bin start.o core.o system.o consoleio.o
echo Done!

concat.py

pause

Here are the error messages I am receiving when trying to run this code. All files are in the same directory, yes the PATH variable is set up correctly:

C:\Simple\core>build.bat

C:\Simple\core>echo Now compiling, assembling, and linking the core:
Now compiling, assembling, and linking the core:

C:\Simple\core>nasm -f aout -o start.o start.asm

C:\Simple\core>gcc -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-func
tions -nostdinc -fno-builtin -I./include -c -o consoleio.o consoleio.c
The system cannot execute the specified program.

C:\Simple\core>gcc -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-func
tions -nostdinc -fno-builtin -I./include -c -o core.o core.c

C:\Simple\core>gcc -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-func
tions -nostdinc -fno-builtin -I./include -c -o system.o system.c
The system cannot execute the specified program.

C:\Simple\core>ld -T link.ld -o core.bin start.o core.o system.o consoleio.o
c:/djgpp/bin/ld.exe: system.o: No such file: No such file or directory (ENOENT)

C:\Simple\core>echo Done!
Done!

C:\Simple\core>concat.py
Traceback (most recent call last):
  File "C:\Simple\core\concat.py", line 12, in <module>
    with open("core.bin", "rb") as core:
IOError: [Errno 2] No such file or directory: 'core.bin'

Now, the interesting thing is the gcc command, which is the issue I'm having. (The other issues seem to be cascading from this.) When compiling core.c, the GCC command works just fine and great, and produces a .o file as expected. When attempting to compile system.c or consoleio.c, GCC fails, but in a very unexpected way: it appears as though windows cannot run the program. This makes zero sense to me. I've tried any number of things, including running these commands myself outside the window. Something about core.c is just special, and I can't figure out what the difference is. I literally copied that line and changed the filenames to create the other two lines that are failing.

So, in short, HELP. I'm using DJGPP and GCC on windows XP, along with a python script at the end that should tie everything together. (This all worked when the project was a single source file, but attempting to split the file into separate files has caused this strange error.)

Thanks.

PS: Yes, we are using a batch file, and I know that makes some of you cringe. However, I'd really like to understand this error before moving on to a makefile if possible. ^_^

EDIT: The accepted answer was indeed our problem, although the issue was with DJGPP, not Windows. (Windows doesn't seem to have a command limit.) The solution was to compile with MinGW instead of DJGPP, which fixed the issue right away. Thanks guys!

+5  A: 

The line that works is 126 characters long, the others are 130 and 136 characters long. The problem is that there is a 127-character limit. I'm not sure how to get around this, but maybe make would get around it for you?...

yjerem
If that's the problem, yes make (if it's DJGPP's make) does work around it. See http://www.delorie.com/djgpp/v2faq/faq16_4.html
CesarB
This is 2008, does anything still have a 126 character command line limit? Certainly native Win32 programs do not. Unless the OP is running a 16-bit version of DJGPP, I can't see this as being the answer.
Greg Hewgill
@Greg Hewgill: DJGPP is always 32-bit, but almost all of its iteraction with the operating system is via DOS calls. DOS is 16-bit. In fact, DJGPP programs start with a 16-bit stub which calls into DPMI to switch to 32-bit mode, so they look like 16-bit DOS programs to Windows.
CesarB
On win32 the max commandline is 8k.Under dos it's 16KB - but that includes a copy of all the enviroment variables
Martin Beckett
A: 

Add -v to the gcc command line. gcc is in fact a driver, which runs several other auxiliary programs (tradicionally, the preprocessor, compiler, and assembler); -v makes it show their command lines as they are being executed, and also enables verbose mode. With this, you can see where it is failing.

CesarB
A: 

As mentioned, DJGPP make (or Bash) or even a simple response file would solve this problem, so it's a non-issue. DJGPP is still plenty good as long for what it does. (P.S. Also see the ELF port or Japheth's HX mod.)

Rugxulo