PDA

View Full Version : Need help with a code please help :D



Sean11
21st September 2017, 17:28
Hey guys im new to QT programming im writing my first QT c++ game now ive tried to solve this by my self i just cant understand the problem i hope you can help me
i get an error "player.obj : error LNK2019: unresolved external symbol "public: __cdecl Spaceship::Spaceship(void)" (??0Spaceship@@QEAA@XZ) referenced in function "public: void __cdecl Player::spawn(void)" (?spawn@Player@@QEAAXXZ)"

d_stranz
21st September 2017, 18:18
You haven't linked in the object file that implements your "Spaceship" class code, probably because it isn't being compiled because you haven't included the .cpp file in your project's list of source files. The project compiles because you have included the .h file that defines the Spaceship class and its methods, but your problem is a linker error, which takes place after compilation is done.

ado130
21st September 2017, 18:37
I'm not sure, but I think I got same or similar error due to circular dependencies of header files.

d_stranz
21st September 2017, 19:08
I'm not sure, but I think I got same or similar error due to circular dependencies of header files.

That's more likely to result in a compile-time error. Not being able to find a symbol at link time means a library or object file isn't being linked in (or the wrong one -is- being linked in but it doesn't include the symbols being sought after).

Sean11
21st September 2017, 20:30
Ill upload my code and you can see what ive done and whats not.
tnx for your fast comment
this is my code:
https://github.com/SeanR11/Spaceship---first-game

d_stranz
21st September 2017, 23:15
Having your .cpp and .h source code files is useless. What is needed is the project file or Makefile that is used to build your code into an executable. It is there where you are missing the information needed to tell the build tool chain how to build your project.

PierreA
22nd September 2017, 01:02
Are you using cmake or qmake? If cmake, you have a file CMakeLists.txt with a line like this:

add_executable(game main.cpp player.cpp game.cpp)
Add "spaceship.cpp" to the list of cpp files and your problem should go away.

Sean11
22nd September 2017, 01:53
Guys first of all thanks you both for your help
PierreA ur answer actually helped i went to "build" and clicked "build qMake" and it actually fixed my problem.. without adding anything