Guest User

Untitled

a guest
Jul 16th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.29 KB | None | 0 0
  1. /* -------------------------------------------------------------------------------------------
  2.                                        Error:
  3. $ gcc -std=c99 -Wall tddc.c && ./a.out
  4. /tmp/ccXPmsC6.o: In function `sum_test':
  5. tddc.c:(.text+0x13): undefined reference to `calc_sum'
  6. tddc.c:(.text+0x44): undefined reference to `calc_sum'
  7. collect2: ld returned 1 exit status
  8.  
  9.                                     But if I do...
  10. $ gcc -std=c99 -Wall calc.c tddc.c && ./a.out
  11.  
  12.  
  13.             It works! Why doesn't the first one autoresolve calc.h and calc.c?
  14. ------------------------------------------------------------------------------------------- */
  15.  
  16.  
  17. // Calc unit test
  18. // tddc.c
  19. #include "calc.h"
  20.  
  21. #include <assert.h>
  22. #include <stdbool.h>
  23.  
  24.  
  25. static void sum_test() {
  26.     int sum;
  27.  
  28.     sum = calc_sum(1,30);
  29.     assert(sum == 31 && "test_sum: positive sum");
  30.  
  31.     sum = calc_sum(1,-30);
  32.     assert(sum == -29 && "test_sum: negative sum");
  33. }
  34.  
  35. int main() {
  36.     sum_test();
  37. }
  38.  
  39. //------------------------------------------------------------------------------------------
  40. // calc.h
  41. int calc_sum(int oper1, int oper2);
  42.  
  43.  
  44. //------------------------------------------------------------------------------------------
  45. // calc.c
  46. #include "calc.h"
  47.  
  48. int calc_sum(int oper1, int oper2) {
  49.     return oper1 + oper2;
  50. }
Add Comment
Please, Sign In to add comment