Find the answer to your Linux question:
Results 1 to 4 of 4
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    converting C code into command line executable


    I thought this question's best category would be in the newbie section.

    Basically I have a C code, (for simplicity is only prints a few lines), called printx.c that I would like to convert into a binary file so whenever I have to type "printx" in the command line it would execute the program

    ofcourse gcc will give me a binary file if I do a "gcc printx.c", but even the output file (e.g. print.out) would have to be executed in the following manner


    I only ask, because I notice programs like mailx (which is written in C) is a binary file that could be run in this manner (at least that's what I notice on my ubuntu distro)

  2. #2
    If you look at the options available with gcc, it will tell you that there is an option to name the output binary whatever you want.

    You can use "man gcc" to look it up.

  3. #3
    Linux Engineer GNU-Fan's Avatar
    Join Date
    Mar 2008
    I reckon that you don't wish to type the trailing "./" when you start your program.

    Ok, here is the deal: When you type in a command with "./", the shell interpreter looks for the given program in a set of certain directories. These directories are determined by the PATH shell variable. Separated by ":"
    echo $PATH
    to see them.

    This PATH variable can be adjusted to include your own directories, or even the "current" directory. Look it up in the bash manual.

    What I do is creating a "bin" directory in my $HOME folder and append ":$HOME/bin:" to the variable. Then I put all my personal programs in this directory.
    Debian GNU/Linux -- You know you want it.

  4. $spacer_open
  5. #4
    yep, I guess that's what I was looking for


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts