Is there any kind of command line option for as(gnu) to compile directly to exe instead of going to an object file?
Printable View
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.
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
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?
Careful now.
It's not a finished executable. The linker fixes certain function calls and also puts all object files together into a final executable, among other things.
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.
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.
You just need your file(s) and the c library, nothing more.
Of course, how to link from the command line - I have not the slightest idea.
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.
I don't suppose that depends on the compiler (ie different compilers may differ on this behavior)?
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.)
Whats an entry point?