在 Mac 终端中运行可执行文件 [英] Running an executable in Mac Terminal

查看:214
本文介绍了在 Mac 终端中运行可执行文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚制作了一个 .c 文件,并在 OS X 10.8.2 的终端中使用 gcc 编译它.

I just made a .c file and compiled it with gcc in the terminal on OS X 10.8.2.

我的语法是 gcc -o <sourcefile> 那很好.现在我看到我有一个可执行文件和文件 这样告诉我,但我不知道除了双击图标/lame 之外如何实际运行它.当我尝试通过键入运行可执行文件时,我找不到命令,但我认为它是可执行的...?

My syntax was gcc -o <filename> <sourcefile> and that was fine. Now I see I have an executable and file <filename> tells me as such, but I'm not sure how to actually run it beside double clicking the icon, /lame. When I try running the executable by just typing I get command not found, but I thought it was executable...?

谢谢.

我太愚蠢了,它只是打开

I"m so stupid, it was just open <filename>

推荐答案

Unix 只会运行在系统路径上可用的命令,你可以通过 $PATH 变量查看

Unix will only run commands if they are available on the system path, as you can view by the $PATH variable

echo $PATH

位于不在路径上的目录中的可执行文件无法运行,除非您指定它们的完整位置.所以在你的情况下,假设可执行文件在你正在使用的当前目录中,那么你可以这样执行它

Executables located in directories that are not on the path cannot be run unless you specify their full location. So in your case, assuming the executable is in the current directory you are working with, then you can execute it as such

./my-exec

其中 my-exec 是您的程序名称.

Where my-exec is the name of your program.

这篇关于在 Mac 终端中运行可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆