Thread: compiler options

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    150

    compiler options

    Hello. I am looking for a compiler that will produce a flat binary image, no DOS segment prefix or .exe info, just straight program code and data. I am running windows xp and currently use turbo c, dev-cpp, mingw, and digital mars. i have NO clue how to make any of these output this kind of file and i know it can be done in mingw, i just cant figure out how! can anyone help me?

  2. #2
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Are you looking for assembler output or just an object file (ie. binary compiled -- but not linked -- code)? Or am I so tired I'm missing the entire point of your question?

    If you just want the code to be compiled but not linked, it's -c.

  3. #3
    Registered User
    Join Date
    Mar 2006
    Posts
    150
    assembler output. I want the output of the compile to be a flat binary image with the extension .bin. I am trying to write code that i can boot with a boot sector i wrote, but i dont know how to run it as a .com file, so i just want to make straight binary code

  4. #4
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    I think this is slightly more advanced than just a compiler switch, but -s or -S is how to get the assembly dump in anything GCC (ie. MinGW).

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    You need some tool(s) that can take an existing executable, and
    • locate the code [so that all address references are resolved and correct]
    • strip off the headers etc.


    I KNOW for a fact that Linux has the ability to do this. I'm not sure if Exe2bin is able to do what you want, but it's an old DOS tool that is still distributed as part of Windows. You may want to have a google for exe2bin and see if it can help you.

    --
    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.

  6. #6
    Registered User
    Join Date
    Mar 2006
    Posts
    150
    But exe2bin will produce DOS binaries, won't it? It produces a .com file, right? I want a flat binary file. Am i just misunderstanding the file format here?

    Ok, i used exe2bin on a test program, and it said that it could not be converted. What can i do to convert this file?
    Last edited by xixpsychoxix; 07-25-2008 at 03:20 PM. Reason: tried using exe2bin
    HA! I WIN!

  7. #7
    Registered User
    Join Date
    Mar 2006
    Posts
    150
    I have one more question about this whole thing, and then i swear im done. If i use the exe2bin provided with digital mars compiler, does it produce a DOS .com file, or does it produce binary code?
    HA! I WIN!

  8. #8
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Use the -ffreestanding switch with gcc/mingw. Here is a decent overview of what you might be looking for.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  9. #9
    Registered User
    Join Date
    Mar 2006
    Posts
    150
    What exactly would the output of the compiler be if I ran it on the program

    Code:
    int main ()
    {
      return 0;
    }
    with this command line option? does it still produce an executable? or is the file in another format?
    HA! I WIN!

  10. #10
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Compilers just produce object files. That particular option merely ensures that the object file is in a format that the linker can turn into a flat binary file. The article I posted explains all that, of course...
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiler Paths...
    By Cobra in forum C++ Programming
    Replies: 5
    Last Post: 09-26-2006, 04:04 AM
  2. Dev C++ Compiler, Indentation?
    By Zeusbwr in forum C++ Programming
    Replies: 3
    Last Post: 10-21-2004, 06:13 AM
  3. lcc win32 compiler download problems
    By GanglyLamb in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 08-01-2004, 07:39 PM
  4. C Compiler
    By SAMSEIED in forum C Programming
    Replies: 5
    Last Post: 06-06-2002, 05:44 PM
  5. Special Compiler for win app's
    By Unregistered in forum Windows Programming
    Replies: 19
    Last Post: 04-26-2002, 03:52 PM