1

I have a series of files from a shared github project and they run perfectly for everyone else. But everytime I run them I get a

"CMakeFiles/Dice.cpp.dir/Player.cpp.o: In function Player::Player(std::string)': /cygdrive/c/Users/Abby/CLionProjects/Risk_Domination/Player.cpp:51: undefined reference toDice::Dice()'"

error. Dice is the only class that I wrote on my computer. It is included in all the files it is used in, I don't know why the two won't link. I get the same error again the next time I refer to the variable dice.

The file player, which is getting the error, includes everything below. And the class Dice does include a constructor Dice(), which is defined and has been tested.

#include "Dice.h"

//and errors are pointing to line 51:

 this->dice = new Dice();

//and line 81

 a = dice->rollDice(number_of_dice);
user4581301
  • 33,082
  • 7
  • 33
  • 54
abbyALJC
  • 11
  • 1
  • 1
    Too many possibilities to be able to give a good answer. Perhaps checking through some of the common possibilities listed at [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) can help – user4581301 Oct 31 '19 at 20:41
  • What is the exact compiler and/or linker command being run when you get that error? Since you're using CMake, you can get more details by running `make VERBOSE=1`. Since you tagged Cygwin, are you able to reproduce the problem, say, on Linux? There are some link problems that can be unique to Cygwin, though I'd be surprised if they showed up in a simple student project. – Iguananaut Nov 01 '19 at 09:37

1 Answers1

0

You mention that everything work perfectly for others, but for you it doesn't work, specifically for the file you wrote on your PC. For clarification: Can other people compile with Dice?

If you have a linking problem, it is likely that the .cpp file is not set to be compiled with the executable in CMake. This tells me that the issue is in the CMakeLists.txt file, not in any sourcefile.

To fix the issue make sure that the executable or library that you want Dice to be part of includes the Dice.cpp file in the add_executable or similar function.

Frederik Juul
  • 181
  • 1
  • 11