Guest User

Untitled

a guest
Apr 23rd, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. #include <iostream>
  2. #include "Dice.h"
  3.  
  4. int main(int argc, char **argv) {
  5.  
  6. int dieRoll = Dice::roll(6);
  7. std::cout<<dieRoll<<std::endl;
  8.  
  9. std::cin.get();
  10.  
  11. return 0;
  12. }
  13.  
  14. #ifndef DieH
  15. #define DieH
  16.  
  17. namespace Dice
  18. {
  19. int roll(unsigned int dieSize);
  20. }
  21.  
  22. #endif
  23.  
  24. #include <ctime>
  25. #include <cstdlib>
  26. #include "Dice.h"
  27.  
  28. namespace Dice
  29. {
  30. int roll(unsigned int dieSize)
  31. {
  32. if (dieSize == 0)
  33. {
  34. return 0;
  35. }
  36. srand((unsigned)time(0));
  37. int random_int = 0;
  38. random_int = rand()%dieSize+1;
  39.  
  40. return random_int;
  41. }
  42. }
  43.  
  44. g++ -o program main.cpp Dice.cpp
  45.  
  46. Undefined symbols:
  47. "Dice::roll(int)", referenced from:
  48. _main in ccYArhzP.o
  49. ld: symbol(s) not found
  50. collect2: ld returned 1 exit status
  51.  
  52. g++ main.cpp -c
  53.  
  54. g++ dice.cpp -c
  55.  
  56. g++ main.o dice.o
  57.  
  58. nm main.o dice.o
  59.  
  60. main.o:
  61. 00000000 b .bss
  62. 00000000 d .ctors
  63. 00000000 d .data
  64. 00000000 r .eh_frame
  65. 00000000 t .text
  66. 00000098 t __GLOBAL__I_main
  67. 00000069 t __Z41__static_initialization_and_destruction_0ii
  68. U __ZN4Dice4rollEj
  69. U __ZNSi3getEv
  70. U __ZNSolsEPFRSoS_E
  71. U __ZNSolsEi
  72. U __ZNSt8ios_base4InitC1Ev
  73. U __ZNSt8ios_base4InitD1Ev
  74. U __ZSt3cin
  75. U __ZSt4cout
  76. U __ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_
  77. 00000000 b __ZStL8__ioinit
  78. U ___gxx_personality_v0
  79. U ___main
  80. 00000055 t ___tcf_0
  81. U _atexit
  82. 00000000 T _main
  83.  
  84. dice.o:
  85. 00000000 b .bss
  86. 00000000 d .data
  87. 00000000 t .text
  88. 00000000 T __ZN4Dice4rollEj
  89. U _rand
  90. U _srand
  91. U _time
  92.  
  93. // Note, it is an int, not unsigned int
  94. int roll(int dieSize)
  95.  
  96. main.o:
  97. 00000000 b .bss
  98. 00000000 d .ctors
  99. 00000000 d .data
  100. 00000000 r .eh_frame
  101. 00000000 t .text
  102. 00000098 t __GLOBAL__I_main
  103. 00000069 t __Z41__static_initialization_and_destruction_0ii
  104. U __ZN4Dice4rollEj
  105. U __ZNSi3getEv
  106. U __ZNSolsEPFRSoS_E
  107. U __ZNSolsEi
  108. U __ZNSt8ios_base4InitC1Ev
  109. U __ZNSt8ios_base4InitD1Ev
  110. U __ZSt3cin
  111. U __ZSt4cout
  112. U __ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_
  113. 00000000 b __ZStL8__ioinit
  114. U ___gxx_personality_v0
  115. U ___main
  116. 00000055 t ___tcf_0
  117. U _atexit
  118. 00000000 T _main
  119.  
  120. dice.o:
  121. 00000000 b .bss
  122. 00000000 d .data
  123. 00000000 t .text
  124. 00000000 T __ZN4Dice4rollEi
  125. U _rand
  126. U _srand
  127. U _time
  128.  
  129. undefined reference to `Dice::roll(unsigned int)'
Add Comment
Please, Sign In to add comment