g++文件格式无法识别;将Object.o视为链接器脚本
g++ file format not recognized; treating Object.o as linker script
对象.hpp
#ifndef OBJECT_HPP
#define OBJECT_HPP
#include <SFML/Graphics.hpp>
using namespace std;
class Object {
private:
sf::Image image;
public:
float x;
float y;
int width;
int height;
sf::Sprite sprite;
virtual void update();
};
#endif
对象.cpp
void Object::update() {
}
这是我的Makefile:
LIBS=-lsfml-graphics -lsfml-window -lsfml-system
all:
@echo "** Building mahgame"
State.o : State.cpp
g++ -c State.cpp
PlayState.o : PlayState.cpp
g++ -c PlayState.cpp
Game.o : Game.cpp
g++ -c Game.cpp
Object.o : Object.cpp
g++ -c Object.cpp
Player.o : Player.cpp
g++ -c Player.cpp
mahgame : Game.o State.o PlayState.o Object.o Player.o
g++ -o mahgame Game.o State.o PlayState.o Object.o Player.o $(LIBS)
#g++ -c "State.cpp" -o State.o
#g++ -c "PlayState.cpp" -o PlayState.o
#g++ -c "Game.cpp" -o Game.o
#g++ -c "Object.hpp" -o Object.o
#g++ -c "Player.hpp" -o Player.o
#g++ -o mahgame Game.o State.o PlayState.o Object.o Player.o $(LIBS)
clean:
@echo "** Removing object files and executable..."
rm -f mahgame
install:
@echo '** Installing...'
cp mahgame /usr/bin
uninstall:
@echo '** Uninstalling...'
rm mahgame
以下是我在构建时遇到的错误(构建后,这是一个链接器错误):
/usr/bin/ld:Object.o: file format not recognized; treating as linker script
/usr/bin/ld:Object.o:1: syntax error
collect2: error: ld returned 1 exit status
make: *** [all] Error 1
知道发生了什么事吗?提前谢谢。
您是否在使用ccache?我刚刚遇到了一个与您非常相似的问题,在编译中省略了ccache解决了这个问题。
您的Makefile看起来很完美,虽然有点冗长,并且缺少标头依赖项。我假设shell命令有一个前导制表符。我假设您的构建命令是make mahgame
。
正如您所说,您有一个链接器错误。CCD_ 2似乎不是有效的CCD_ 3。让编译器重新生成它。
$ rm Object.o
$ make mahgame
g++ -c Object.cpp
g++ -o mahgame Game.o State.o PlayState.o Object.o Player.o...
生成文件的格式为:
xxx.o : xxx.cpp
g++ -c xxx.cpp
你的一点也不像。所以,将您的更改为:
LIBS=.....
[EDIT]
all : mahgame rmerr
rmerr :
rm -f err
[/EDIT]
State.o : State.cpp
g++ -c State.cpp 2>>err
PlayState.o : PlayState.cpp
g++ -c PlayState.cpp 2>>err
.....
mahgame : Game.o State.o .....
g++ -o mahgame Game.o State.o PlayState.o Object.o Player.o $(LIBS) 2>>err
请注意,这是您的第一步,还有更好的方法来编写makefile,不包括源文件/对象文件等的每个细节。
相关文章:
- lambda参数转换为constexpr技巧,然后获取带链接的数组
- CMake-按正确顺序将项目与C运行时对象文件链接
- 从链接列表c++中删除一个项目
- 有根的二进制搜索树.保留与其父级的链接
- 读取文件的最后一行并输入到链接列表时出错
- 静态数据成员的问题-修复链接错误会导致编译器错误
- node-gyp 在 macOS 上未正确链接库
- 基于boost的程序的静态链接——zlib问题
- 生成库失败:无法识别文件格式;作为链接器脚本处理
- 微控制器的首次 gcc 链接器脚本编译但不运行
- 将.init_array部分包含在链接器脚本中会产生不可用的输出
- 链接器脚本中断程序
- 如何在没有外部脚本的情况下链接CMake和SQLite
- g++文件格式无法识别;将Object.o视为链接器脚本
- 无法通过 VIM 运行链接脚本
- 将C++程序输出与 Python 脚本链接
- 需要避免在需要使用链接器脚本 *.ld 文件的静态库中对"WinMain"进行未定义的引用
- 用于快速确定哪些源代码导致不必要的 .so 链接的脚本
- 无法识别文件格式;作为链接器脚本处理
- 如何在链接器脚本中使用存档中的目标文件