Is there any kind of command line option for as(gnu) to compile directly to exe instead of going to an object file?
Is there any kind of command line option for as(gnu) to compile directly to exe instead of going to an object file?
No. But you could call gcc instead of as.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
note that gcc also creates object files before producing the .exe - it's just that gcc (and many other c compilers) call the linker as part of the compilation step, to produce the final .exe file.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Ok I'm a little confused now. Stupidly, I tried "as main.s -o main.exe" thinking that might work, but it actually did! The exe actually ran, but it is the exact same file as when generated for a .o file. Why would a .o file actually be able to run on windows? Doesn't a .o file have to be linked before being able to run?
If your program doesn't contain any calls to library functions, that could indeed work. Executables and object files essentially use the same format (COFF in a PE wrapper). I'm still a little surprised that Windows loads the file, but if it does, it would indeed execute.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
On the subject of linking, how exactly do you link to the c standard libraries? I imagine you would just call the linker with two files, your file, and then the c libraries. However, I have no idea what that second file would be in MinGW.
The GNU linker takes library arguments the same way as GCC. -l<libname>, where libname is prefixed "lib" and postfixed ".so" and ".a" in search of the actual library file. E.g. -lcurses will link against the curses library, and the linker will look for libcurses.so and libcurses.a. The CRT is libc, so you want -lc.
Don't forget that order matters in Unix linkers. Put the C library last.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
Definitely. GCC needs the startup, MSVC doesn't because it's included in its CRT. (That's the advantage when the CRT is part of the compiler package.)
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
Whats an entry point?