在 Ubuntu 上使用 g++ 编译器运行程序

Running program with g++ compiler on Ubuntu

本文关键字:编译器 运行 程序 g++ Ubuntu      更新时间:2023-10-16

我需要帮助在 Ubuntu 上运行我的程序。我有两个 cpp 文件和一个头文件。我收到以下错误。有人可以帮我吗?

gopy@gopy-VPCEB36GM:~/Desktop/helo$ g++ -c Sequence.cpp
gopy@gopy-VPCEB36GM:~/Desktop/helo$ g++ -c SequenceTest.cpp
gopy@gopy-VPCEB36GM:~/Desktop/helo$ g++ -o Sequence.o SequenceTest.o test
g++: error: test: No such file or directory

o文件是在我打开helo文件夹时创建的

g++ man

-o <file>                Place the output into <file>

均值测试必须紧跟在 -o 标志之后,否则链接器认为测试是输入

gopy@gopy-VPCEB36GM:~/Desktop/helo$ g++ -o test Sequence.o SequenceTest.o

尝试

g++ -o test Sequence.o SequenceTest.o

正如其他人提到的,-o代表输出文件名。在这种情况下,g++ 假定Sequence.o作为输出文件名,SequenceTest.otest是要编译或链接的文件。所以

g++ -o test Sequence.o SequenceTest.o

是正确的方法。而且,您可以使用单个命令完成整个编译过程。

g++ Sequence*.cpp -o test

非答案是'sudo apt-get codeblocks'。您可以花更多的时间学习C++,而花更少的时间使用命令行。