Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include "Dice.h"
- int main(int argc, char **argv) {
- int dieRoll = Dice::roll(6);
- std::cout<<dieRoll<<std::endl;
- std::cin.get();
- return 0;
- }
- #ifndef DieH
- #define DieH
- namespace Dice
- {
- int roll(unsigned int dieSize);
- }
- #endif
- #include <ctime>
- #include <cstdlib>
- #include "Dice.h"
- namespace Dice
- {
- int roll(unsigned int dieSize)
- {
- if (dieSize == 0)
- {
- return 0;
- }
- srand((unsigned)time(0));
- int random_int = 0;
- random_int = rand()%dieSize+1;
- return random_int;
- }
- }
- g++ -o program main.cpp Dice.cpp
- Undefined symbols:
- "Dice::roll(int)", referenced from:
- _main in ccYArhzP.o
- ld: symbol(s) not found
- collect2: ld returned 1 exit status
- g++ main.cpp -c
- g++ dice.cpp -c
- g++ main.o dice.o
- nm main.o dice.o
- main.o:
- 00000000 b .bss
- 00000000 d .ctors
- 00000000 d .data
- 00000000 r .eh_frame
- 00000000 t .text
- 00000098 t __GLOBAL__I_main
- 00000069 t __Z41__static_initialization_and_destruction_0ii
- U __ZN4Dice4rollEj
- U __ZNSi3getEv
- U __ZNSolsEPFRSoS_E
- U __ZNSolsEi
- U __ZNSt8ios_base4InitC1Ev
- U __ZNSt8ios_base4InitD1Ev
- U __ZSt3cin
- U __ZSt4cout
- U __ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_
- 00000000 b __ZStL8__ioinit
- U ___gxx_personality_v0
- U ___main
- 00000055 t ___tcf_0
- U _atexit
- 00000000 T _main
- dice.o:
- 00000000 b .bss
- 00000000 d .data
- 00000000 t .text
- 00000000 T __ZN4Dice4rollEj
- U _rand
- U _srand
- U _time
- // Note, it is an int, not unsigned int
- int roll(int dieSize)
- main.o:
- 00000000 b .bss
- 00000000 d .ctors
- 00000000 d .data
- 00000000 r .eh_frame
- 00000000 t .text
- 00000098 t __GLOBAL__I_main
- 00000069 t __Z41__static_initialization_and_destruction_0ii
- U __ZN4Dice4rollEj
- U __ZNSi3getEv
- U __ZNSolsEPFRSoS_E
- U __ZNSolsEi
- U __ZNSt8ios_base4InitC1Ev
- U __ZNSt8ios_base4InitD1Ev
- U __ZSt3cin
- U __ZSt4cout
- U __ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_
- 00000000 b __ZStL8__ioinit
- U ___gxx_personality_v0
- U ___main
- 00000055 t ___tcf_0
- U _atexit
- 00000000 T _main
- dice.o:
- 00000000 b .bss
- 00000000 d .data
- 00000000 t .text
- 00000000 T __ZN4Dice4rollEi
- U _rand
- U _srand
- U _time
- undefined reference to `Dice::roll(unsigned int)'
Add Comment
Please, Sign In to add comment