as to exe

This is a discussion on as to exe within the Tech Board forums, part of the Community Boards category; Is there any kind of command line option for as(gnu) to compile directly to exe instead of going to an ...

  1. #1
    Registered User
    Join Date
    Jun 2008
    Posts
    127

    as to exe

    Is there any kind of command line option for as(gnu) to compile directly to exe instead of going to an object file?

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    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

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    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.

  4. #4
    Registered User
    Join Date
    Jun 2008
    Posts
    127
    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?

  5. #5
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,667
    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.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Quote Originally Posted by herWter View Post
    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?
    You are compiling assembler straight to an exe, that is certainly an entirely different question since assembler is already compiled, in a sense.

  7. #7
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Quote Originally Posted by herWter View Post
    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

  8. #8
    Registered User
    Join Date
    Jun 2008
    Posts
    127
    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.

  9. #9
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,667
    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.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  10. #10
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    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

  11. #11
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,246
    Quote Originally Posted by Elysia View Post
    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.
    In addition to the C library you also need the runtime startup module which provides the entry point. Often called crt0.o or something like that.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  12. #12
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,667
    I don't suppose that depends on the compiler (ie different compilers may differ on this behavior)?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  13. #13
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    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

  14. #14
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Quote Originally Posted by brewbuck View Post
    In addition to the C library you also need the runtime startup module which provides the entry point. Often called crt0.o or something like that.
    Which is one of those fun ones to have to compile on an embedded machine.... Of course the cool thing about compiling your own crt0.s is that you can define your own main() function Which is more useful than it may sound on an embedded system.

  15. #15
    Registered User
    Join Date
    Jun 2008
    Posts
    127
    Whats an entry point?

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to monitor exe and dll interactions?
    By George2 in forum C Programming
    Replies: 1
    Last Post: 10-26-2007, 04:22 AM
  2. how to run an exe command in c++ and get back the results?
    By mitilkhatoon in forum C++ Programming
    Replies: 5
    Last Post: 09-21-2006, 06:00 PM
  3. Close another exe from another exe??
    By Tony in forum Windows Programming
    Replies: 1
    Last Post: 06-12-2002, 07:19 AM
  4. insert another exe into exe
    By lliero in forum C Programming
    Replies: 8
    Last Post: 04-12-2002, 12:22 PM
  5. adding bytes to EXE to call another EXE
    By lliero in forum C Programming
    Replies: 2
    Last Post: 03-30-2002, 06:23 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21