📜 ⬆️ ⬇️

Cocotron, the latest news from the front of Objective-C

Cocotron is a runtime implementation for Objective-C, similar to the Apple-Cocoa runtime. It is quite different from other popular open runtime - GNUstep, both in order and in implementation.

Cocotron is great for porting code from OSX to Win32. Of course, the implementation of the API is far from ideal, but, as practice shows, developers always quickly solve problems.

Initially, Cocotron was used only for cross-building based on XCode and mingw-toolchain. For cross-build deployment is available on Windows, Linux and Solaris.
')
Of course, this approach left the most difficult and expensive stage in the development chain - OSX (optimally - on the original hardware). The possibility of Cocotron, as a platform, could not be fully disclosed due to this dependency.


Cocotron cannot work with the original GCC, where another Objective-C runtime is used. For this reason, GCC needs to be assembled with Apple patches, which, among other things, slightly expand the language of vanilla GCC.

The installation process for GCC is quite traditional; first you need to download the source tree:
  svn checkout http://cocotron-tools-gpl3.googlecode.com/svn/trunk/gcc cocotron-gcc 

and then compile it:
  mkdir gcc-build
 cd gcc-build
 ../cocotron-gcc/configure --prefix = / opt / objc --with-gnu-as --with-gnu-ld --without-newlib --disable-multilib \
     --disable-libssp --disable-nls --disable-libobjc --enable-libffi --enable-objc-gc \
     --enable-languages ​​= c, objc, c ++, obj-c ++ --enable-checking = release
 make -j2
 sudo make install 

here I use the prefix / opt / objc for GCC and Cocotron.

Alternatively, you can use the collected deb package , which was kindly provided by the newcomer pfactum .

Now you can go to the specific assembly Cocotron. Currently, the native build is supported for Linux, OpenBSD (and probably FreeBSD), and Darwin (i.e. OSX). To assemble, you must pick up the fork of the official tree with github:
  git clone git: //github.com/farcaller/cocotron.git
 cd cocotron
 git checkout origin / native-build -b native-build 

(By the way, the master branch is automatically synchronized with the official svn, so if someone wants to "dig out" the source code and prefers git, you are welcome).

The build system is based on CMake, and not younger than 2.6:
  mkdir build
 cd build
 cmake -DCMAKE_C_COMPILER = / opt / objc / bin / gcc \
     -DCMAKE_CXX_COMPILER = / opt / objc / bin / g ++ \
     -DCMAKE_INSTALL_PREFIX = / opt / objc ..
 make
 sudo make install 

So far, she only collects Foundation, work on the AppKit build scripts in the process.

The assembled library can be tested:
  cat> test.m << EOF
 #import <Foundation / Foundation.h>

 int main (int argc, char * argv [])
 {
         NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
         NSLog (@ "Hello, Objective-C World!");

         [pool drain];
         return 0;
 }
 EOF 

  / opt / objc / bin / gcc test.m -o test -I / opt / objc / include -L / opt / objc / lib \
   -lFoundation -lpthread -ldl 


I hope that the development of Cocotron will attract new developers to it and increase the popularity of Objective-C, a very interesting programming language.

Source: https://habr.com/ru/post/62951/


All Articles