Thread: Can't run compiled c-programs in linux mint

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    9

    Can't run compiled c-programs in linux mint

    Hi.

    I'm having problems running a c program I made after compiling.

    What happens is this:

    $ gcc filename.c -o filename
    $ filename
    filename: command not found

    So the code compiles, and everything seems to be fine. But for some reason i can't run the program afterwards. I guess there's some sort of package i haven't installed, but I can't figure out which. Can anyone help me?
    Last edited by duckdace; 10-09-2010 at 04:34 AM. Reason: Typoes

  2. #2
    Registered User
    Join Date
    Aug 2003
    Posts
    1,218
    you need to call a program with the directory it is in. In your example you would have to type
    ./filename
    if the program is located in a subdirectory you can do
    subdir/filename
    and so on.

  3. #3
    Registered User
    Join Date
    Oct 2010
    Posts
    9
    Ah, thanks. That explains it. I'm used to work on computers where this is not necessary, as long as I'm in the correct foldet.

  4. #4
    Registered User
    Join Date
    Jan 2011
    Posts
    2

    Question Having a similar problem

    I'm in the correct directory so I'm not sure what the problem is...

    I'm using a linux virtual machine, and I'm not sure if that has anything to do with it, maybe theres some set-up I have failed to do, but down to business.

    I am able to compile the program, price.c, and the computer makes "price". If I try to run the program by typing "price" into the terminal I get the error

    No command 'price' found, did you mean:
    Command 'prime' from package 'prime' (universe)
    price: command not found

    The weird thing is that the program has worked before on other linux machines. Really confused.

    Thank you.

  5. #5
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    So, did you read the thread you brought back from the dead and posted in? Generally in linux, . is not in your path. You need to explicitly say ./price, not just price.

  6. #6
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Seriously, tabstop. What the hell, right?

  7. #7
    Registered User
    Join Date
    Jan 2011
    Posts
    2
    Right my bad guys. Thanks for the help.

  8. #8
    Registered User Andy_PBC's Avatar
    Join Date
    Jan 2011
    Location
    MN
    Posts
    7
    On some systems, "." might be included in the path, "." being your present working directory.

    You can append it to your current search path by using

    Code:
    export PATH=$PATH:.
    And insert it into your ~/.bash_profile or ~/.bashrc file
    .bash_profile vs .bashrc

    Next time you log in, the new PATH will be used.

  9. #9
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Thinking of upgrading to linux...
    By Yarin in forum General Discussions
    Replies: 37
    Last Post: 07-24-2009, 11:40 AM
  2. Replies: 5
    Last Post: 10-25-2007, 12:27 PM
  3. Linux C++ Compiler
    By LiX in forum C++ Programming
    Replies: 12
    Last Post: 12-10-2004, 06:08 AM
  4. Programs run in dos. Why not windows?
    By marcusbankuti in forum C++ Programming
    Replies: 15
    Last Post: 08-11-2002, 07:33 PM
  5. code to run (linux) programs WITH arguments
    By N8760 in forum C++ Programming
    Replies: 3
    Last Post: 12-27-2001, 03:35 PM