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

    Question How to compile and run C with Knoppix Live

    I'm using a knoppix live cd (recommended by uni) to compile and run c programs off a usb drive - practice makes perfect. I get compile error messages when not done properly, warning messages, etc which is good. But when I try to run the program nothing happens. So for example, to compile test.c (which displays a simple printf statement), I would type:

    $ gcc -o test test.c

    Then to run the program, I type:

    $ test

    And nothing happens. It just goes to the next line, ready to take in another command. Why?

  2. #2
    Linux Engineer d38dm8nw81k1ng's Avatar
    Join Date
    Mar 2005
    because you're running the linux command test and not your own test program. linux doesn't look in the directory by default. it first looks in /bin, then /usr/bin (and any other predefined directories) but never the current directory. to tell it to run the file from the current directory, use
    note the ./ and not just /
    the . tells linux to look in the current directory. you can also give the pathname relative to the directory. say you are in /home/user and the file is in /home/user/prog/test you will run
    to execute the code.
    Here's why Linux is easier than Windows:
    Package Managers! Apt-Get and Portage (among others) allow users to install programs MUCH easier than Windows can.
    Hardware Drivers. In SuSE, ALL the hardware is detected and installed automatically! How is this harder than Windows' constant disc changing and rebooting?

  3. #3
    That makes perfect sense. Thanks.

  4. $spacer_open
  5. #4
    d38dm8nw81k1ng is correct that the path needs to be emphasized with ./.
    However, the name test is not a unique name cause it conflicts with bash.
    If you used say like test1 or test\ 1 or whatever then it would have worked.
    BTW, permissions should be perused also.

Posting Permissions

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