[英]g++ file format not recognized; treating Object.o as linker script
Object.hpp 对象.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
Object.cpp Object.cpp
void Object::update() {
}
Here's my Makefile: 这是我的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
Here's the error I get when building (after building, it's a linker error): 这是构建时遇到的错误(构建后是链接器错误):
/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
Any idea of what's going on? 有什么想法吗? Thanks in advance.
提前致谢。
Were you, by any chance, using ccache? 您是否偶然使用了ccache? I just had a very similar problem to yours and omitting ccache in the compilation solved it.
我只是遇到了一个与您的问题非常相似的问题,因此在编译中省略了ccache解决了它。
makefiles are of the form: makefile的格式为:
xxx.o : xxx.cpp
g++ -c xxx.cpp
Yours doesn't look anything like that. 你的看起来不像那样。 So, change yours to be:
因此,将您的更改为:
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
Note that these are your first steps, there are far better ways of writing makefiles that do not include every detail of your source files/object files/etc. 请注意,这些是您的第一步,有很多更好的方式来编写makefile,但这些方法并不包含源文件/目标文件/等的每个细节。
Your Makefile looks perfect, if a little verbose, and missing the header dependencies. Makefile看起来很完美(如果有些冗长),并且缺少标头依赖项。 I assume the shell commands have a leading tab character.
我假设shell命令具有一个制表符字符。 I assume your build command is
make mahgame
. 我认为您的构建命令是
make mahgame
。
As you said, you have a linker error. 如您所说,您有一个链接器错误。
Object.o
does not appear to be a valid .o
. Object.o
似乎不是有效的.o
。 Get the compiler to re-generate it. 获取编译器以重新生成它。
$ rm Object.o
$ make mahgame
g++ -c Object.cpp
g++ -o mahgame Game.o State.o PlayState.o Object.o Player.o...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.