GNUstep under Ubuntu Linux

From GNUstepWiki

Revision as of 19:38, 28 December 2012; view current revision
←Older revision | Newer revision→
  1. Objective C 2.0 on a fresh install of Ubuntu 12.10 Server
  2. Patryk Laurent (http://pakl.net/)
  3. Dec 28, 2012
  1. Dependencies

sudo aptitude install build-essential git subversion ninja cmake

  1. Dependencies for GNUStep Base

sudo aptitude install libffi-dev libxml2-dev libgnutls-dev libicu-dev

  1. Dependencies for libdispatch

sudo aptitude install libblocksruntime-dev libkqueue-dev libpthread-workqueue-dev autoconf libtool cd ~ git clone git://github.com/nickhutchinson/libdispatch.git svn co http://svn.gna.org/svn/gnustep/modules/core svn co http://svn.gna.org/svn/gnustep/libs/libobjc2/trunk libobjc2 svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm cd llvm/tools svn co http://llvm.org/svn/llvm-project/cfe/trunk clang

cd ~/llvm mkdir build cd build cmake .. make -j8 # 8=your number of build CPUs

echo "export PATH=\$PATH:~/llvm/build/bin" >> ~/.bashrc echo "export CC=clang" >> ~/.bashrc echo "export CXX=clang++" >> ~/.bashrc source ~/.bashrc clang -v clang++ -v

cd ~/libobjc2 mkdir build cd build cmake .. make -j8 sudo -E make install

cd ~/core/make ./configure --enable-debug-by-default --with-layout=gnustep make && sudo -E make install echo ". /usr/GNUstep/System/Library/Makefiles/GNUstep.sh" >> ~/.bashrc source ~/.bashrc

cd ~/core/base/ ./configure make -j8 sudo -E make install

cd ~/libdispatch sh autogen.sh ./configure CFLAGS="-I/usr/include/kqueue" LDFLAGS="-lkqueue -lpthread_workqueue -pthread -lm" make -j8 sudo -E make install sudo ldconfig

  1. ----------------------------------------------------------------------------------------
  2. TEST COMPILING SOME CODE FROM THE INTERNET
  3. ----------------------------------------------------------------------------------------

You can compile the following code with:

clang `gnustep-config --objc-flags` `gnustep-config --objc-libs` -fobj-arc -fobjc-runtime=gnustep -fblocks -lobjc blocktest.m

clang `gnustep-config --objc-flags` `gnustep-config --objc-libs` -fobj-arc -fobjc-runtime=gnustep -fblocks -lobjc -ldispatch -lgnustep-base Fraction.m helloGCD_objc.m



cat > blocktest.m << EOF

  1. include <stdio.h>

int main() {

   void (^hello)(void) = ^(void) {
       printf("Hello, block!\n");
   };
   hello();
   return 0;

} EOF

cat > helloGCD_objc.m << EOF

  1. include <dispatch/dispatch.h>
  2. import <stdio.h>
  3. import "Fraction.h"

int main( int argc, const char *argv[] ) {

  dispatch_queue_t queue = dispatch_queue_create(NULL, NULL); 
  Fraction *frac = [[Fraction alloc] init];
  [frac setNumerator: 1];
  [frac setDenominator: 3];
  // print it
  dispatch_sync(queue, ^{
    printf( "The fraction is: " );
    [frac print];
    printf( "\n" );
  });
  dispatch_release(queue);
  return 0;

}

EOF

cat > Fraction.h << EOF

  1. import <Foundation/NSObject.h>

@interface Fraction: NSObject {

  int numerator;
  int denominator;

}

-(void) print; -(void) setNumerator: (int) n; -(void) setDenominator: (int) d; -(int) numerator; -(int) denominator; @end

EOF


cat > Fraction.m << EOF

  1. import "Fraction.h"
  2. import <stdio.h>

@implementation Fraction -(void) print {

  printf( "%i/%i", numerator, denominator );

}

-(void) setNumerator: (int) n {

  numerator = n;

}

-(void) setDenominator: (int) d {

  denominator = d;

}

-(int) denominator {

  return denominator;

}

-(int) numerator {

  return numerator;

} @end

EOF