Guest User

Untitled

a guest
Apr 26th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. #import <Foundation/NSObject.h>
  2.  
  3. @interface Fraction: NSObject {
  4. int numerator;
  5. int denominator;
  6. }
  7.  
  8. -(void) print;
  9. -(void) setNumerator: (int) n;
  10. -(void) setDenominator: (int) d;
  11. -(int) numerator;
  12. -(int) denominator;
  13. @end
  14.  
  15. #import "Fraction.h"
  16. #import <stdio.h>
  17.  
  18. @implementation Fraction
  19. -(void) print {
  20. printf( "%i/%i", numerator, denominator );
  21. }
  22.  
  23. -(void) setNumerator: (int) n {
  24. numerator = n;
  25. }
  26.  
  27. -(void) setDenominator: (int) d {
  28. denominator = d;
  29. }
  30.  
  31. -(int) denominator {
  32. return denominator;
  33. }
  34.  
  35. -(int) numerator {
  36. return numerator;
  37. }
  38. @end
  39.  
  40. #import <stdio.h>
  41. #import "Fraction.h"
  42.  
  43. int main( int argc, const char *argv[] ) {
  44. // create a new instance
  45. Fraction *frac = [[Fraction alloc] init];
  46.  
  47. // set the values
  48. [frac setNumerator: 1];
  49. [frac setDenominator: 3];
  50.  
  51. // print it
  52. printf( "The fraction is: " );
  53. [frac print];
  54. printf( "n" );
  55.  
  56. // free memory
  57. [frac release];
  58.  
  59. return 0;
  60. }
  61.  
  62. $ sudo apt-get install gobjc gnustep gnustep-devel
  63. $ gcc `gnustep-config --objc-flags` -o main main.m -lobjc -lgnustep-base
  64. /tmp/ccIQKhfH.o:(.data.rel+0x0): undefined reference to `__objc_class_name_Fraction'
  65.  
  66. include ${GNUSTEP_MAKEFILES}/common.make
  67.  
  68.  
  69. TOOL_NAME = main
  70. main_OBJC_FILES = main.m
  71.  
  72.  
  73. include ${GNUSTEP_MAKEFILES}/tool.make
  74.  
  75. $ source /usr/share/GNUstep/Makefiles/GNUstep.sh
  76. $ make
  77. Making all for tool main...
  78. Linking tool main ...
  79. ./obj/main.o:(.data.rel+0x0): undefined reference to `__objc_class_name_Fraction'
  80.  
  81. undefined reference to `__objc_class_name_Fraction'
  82.  
  83. gcc -I /usr/include/GNUstep/ -I /usr/include/mysql -L /usr/lib/GNUstep/
  84. -lgnustep-base -lmysqlclient
  85. -g -ggdb
  86. -fconstant-string-class=NSConstantString -o test *.m
  87.  
  88. #import <stdio.h>
  89. #import "Fraction.m"
  90.  
  91. int main( int argc, const char *argv[] ) {
  92. //create a new instance
  93. Fraction *frac = [[Fraction alloc] init];
  94.  
  95. //set the values
  96. [frac setNumerator: 1];
  97. [frac setDenominator: 3];
  98.  
  99. //print it
  100. printf("The fraction is : ");
  101. [frac print];
  102. printf("n");
  103.  
  104. //free memory
  105. [frac release];
  106.  
  107. return 0;
  108. }
Add Comment
Please, Sign In to add comment