gpt4 book ai didi

c++ - 无法识别 g++ 文件格式;将 Object.o 视为链接描述文件

转载 作者:行者123 更新时间:2023-11-28 07:58:10 25 4
gpt4 key购买 nike

对象.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 解决了这个问题。

关于c++ - 无法识别 g++ 文件格式;将 Object.o 视为链接描述文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12205222/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com