我正在运行 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/