c++ - 文件格式无法识别;视为链接描述文件。文本文件错误?

标签 c++ linux

我正在运行 ubuntu、linux。我正在尝试编译三个文件,一个 main.cpp 和 Token.h 以及 Token.cpp 文件。我正在尝试从一个名为 test1 的文件中读取,该文件是一个文本文件。这是我对终端的输入

g++ test1 -std=c++11 main.cpp token.cpp token.h -Wall -o myprog

我收到以下错误-

/usr/bin/ld:test1: file format not recognized; treating as linker script
/usr/bin/ld:test1:2: syntax error
collect2: error: ld returned 1 exit status

我删除了 main 中的所有数据以确保不是那样。

谢谢你。

最佳答案

I am trying to read in from a file called test1 that is a text file.

您认为如果将它传递给 g++,您会从中读取吗?你能澄清一下你想做什么吗?

要构建您的程序,请尝试使用它:

g++ -std=c++11 main.cpp token.cpp -Wall -o myprog

g++是 C++ 编译器,它将您的 C++ 代码编译/链接到可执行程序中。一旦您的程序被 g++ 编译,您就可以执行它并将您的文件名传递给程序(假设您的文件名为 test1):

./myprog test1

关于c++ - 文件格式无法识别;视为链接描述文件。文本文件错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43794824/

相关文章:

linux - 调试未知的 Linux 机器

c++ - 模板默认为具有更多模板的模板

c++ - C 程序可以处理 C++ 异常吗?

linux - 在 curl 中拆分标题和内容

linux - 如何在 linux(OPENSUSE)中运行 dmalloc?

linux - Bash - 在一个命令中杀死所有进程

c++ - 我不明白移动语义如何作用于 std::string

c++ - 什么是名称查找机制?

c++ - 使用 lambda 作为试运行选项正常吗?

linux - sed:打印带有时间和 ls -altr info 的目录树