Ubuntu如何生成 hello.o
时间: 2023-03-28 09:04:12 浏览: 57
你可以使用以下命令在 Ubuntu 中生成 hello.o 文件:
gcc -c hello.c -o hello.o
其中,hello.c 是你的源代码文件,-c 选项告诉 gcc 编译器只编译源代码文件,而不链接生成可执行文件,-o 选项指定输出文件名为 hello.o。
相关问题
用g++将共享文件夹中的hello.cpp生成并在Ubuntu终端下执行。
假设你已经在Ubuntu终端中挂载了Windows共享文件夹,并且 `hello.cpp` 文件位于共享文件夹的路径为 `/mnt/winshare/hello.cpp`,以下是具体步骤:
1. 复制 `hello.cpp` 文件到Ubuntu本地系统中。在终端中输入以下命令:
```
cp /mnt/winshare/hello.cpp ~/hello.cpp
```
上述命令将共享文件夹中的 `hello.cpp` 文件复制到当前用户的home目录下。
2. 使用 `g++` 编译 `hello.cpp` 文件。在终端中输入以下命令:
```
g++ ~/hello.cpp -o hello
```
上述命令将编译 `hello.cpp` 文件,并生成名为 `hello` 的可执行文件。 `-o` 选项指定生成的可执行文件的名称为 `hello`。
3. 在终端中执行 `hello` 可执行文件。在终端中输入以下命令:
```
./hello
```
上述命令将执行名为 `hello` 的可执行文件。
4. 如果不需要再次使用共享文件夹中的文件,可以在终端中卸载共享文件夹。在终端中输入以下命令:
```
sudo umount /mnt/winshare
```
上述命令将卸载 `/mnt/winshare` 目录下的共享文件夹。
ubuntu 编译.cc文件
在 Ubuntu 上编译 .cc 文件需要安装 g++ 编译器,然后运行以下命令:
```
g++ -o output_name input_name.cc
```
其中,output_name 为编译后生成的可执行文件名,input_name.cc 为待编译的源代码文件名。
例如,如果要编译名为 hello.cc 的源码文件,生成可执行文件 hello,可以运行以下命令:
```
g++ -o hello hello.cc
```
执行上述命令后,如果没有错误信息输出,则说明编译成功。可以通过输入以下命令运行编译后的可执行文件:
```
./hello
```
其中,./ 表示当前目录,hello 是可执行文件名。