Building GNUstep with Clang, Blocks, and Grand Central Dispatch

From GNUstepWiki

(Difference between revisions)
Revision as of 02:29, 3 June 2013
Sdw (Talk | contribs)

← Previous diff
Revision as of 02:37, 3 June 2013
Sdw (Talk | contribs)

Next diff →
Line 1: Line 1:
This guide shows how to install GNUstep-base with clang, blocks and Grand Central Dispatch on Linux. This guide shows how to install GNUstep-base with clang, blocks and Grand Central Dispatch on Linux.
-First some background as the information on this is scattered around the web.+[http://en.wikipedia.org/wiki/Grand_Central_Dispatch Grand Central Dispatch] is a library to assist building apps on multi-core processors. The library for Grand Central Dispatch is called libdispatch, and tasks can be submitted to GCD in blocks or with a C API. To understand the process below, some notes are in order. If you're in a hurry, you can probably skip the notes down to the install instructions.
- +
- +
-[http://en.wikipedia.org/wiki/Grand_Central_Dispatch Grand Central Dispatch] is a library to assist building apps on multi-core processors. The library for Grand Central Dispatch is called libdispatch, and tasks can be submitted to GCD in blocks or with a C API. To understand the process below, some notes are in order. If you're in a hurry, you can probably skip the notes and everything should just build.+
=== GNUstep runtime === === GNUstep runtime ===
* So far as GNUstep, the runtime library for Objective C code used to be called libobjc until Apple released Objective C version 2, and then is called libobjc2. You can get the background here: http://wiki.gnustep.org/index.php/ObjC2_FAQ . (Note Debian and Ubuntu libobjc3 and libobjc4 are still based on libobjc and libobjc2 but numbered differently). * So far as GNUstep, the runtime library for Objective C code used to be called libobjc until Apple released Objective C version 2, and then is called libobjc2. You can get the background here: http://wiki.gnustep.org/index.php/ObjC2_FAQ . (Note Debian and Ubuntu libobjc3 and libobjc4 are still based on libobjc and libobjc2 but numbered differently).
Line 10: Line 7:
** libobjc2 built with Clang does have block support: (use -fblocks flag when compiling your own code) ** libobjc2 built with Clang does have block support: (use -fblocks flag when compiling your own code)
** GNUstep provides block support, whether the compiler does or not. So if using GNUstep, you can use blocks with a GCC libobjc2. ** GNUstep provides block support, whether the compiler does or not. So if using GNUstep, you can use blocks with a GCC libobjc2.
-Now the aim of this exercise is to run GCD, and libdispatch has to be built with clang right now. +** libdispatch currently has some build requirements that necessitate using clang.
-Having settled on a clang build, we observe that Debian wheezy and Ubuntu 13 have a libdispatch infrastructure built on clang (libobjc2 and libdispatch are built using clang). So there are some more decisions:-+So we're going with a clang build since a working GCD is the aim here.
-Why not just run with what Debian provides, i.e. + 
 +Next, we observe that Debian wheezy and Ubuntu 13 have a libdispatch infrastructure built on clang (libobjc2 and libdispatch are built using clang). So there are some more decisions:-
 +Why not just run with what Debian provides instead of compiling from scratch, i.e.
* libobjc2, libdispatch, cblocksruntime compiled with erlang * libobjc2, libdispatch, cblocksruntime compiled with erlang
* gnustep programs compiled with gcc * gnustep programs compiled with gcc
-To make this decision, here is some background on GCD and blocks+To make a decision, here is some background on GCD and blocks
* GCD: As far as I can make out, there are two implementations of GCD out there for Linux. One by [https://www.heily.com/trac/libdispatch/ Mark Heily] and one called [http://opensource.mlba-team.de/xdispatch/docs/current/index.html libxdispatch]. So far as using GCD with GNUstep, Mark's library is the one to use, and this is also the libdispatch library in Debian and Ubuntu. * GCD: As far as I can make out, there are two implementations of GCD out there for Linux. One by [https://www.heily.com/trac/libdispatch/ Mark Heily] and one called [http://opensource.mlba-team.de/xdispatch/docs/current/index.html libxdispatch]. So far as using GCD with GNUstep, Mark's library is the one to use, and this is also the libdispatch library in Debian and Ubuntu.
* GCD is more than just a C library. It requires support from the kernel with light threads (libpthread), and an adptation of BSD signals for Linux (libkqueue). * GCD is more than just a C library. It requires support from the kernel with light threads (libpthread), and an adptation of BSD signals for Linux (libkqueue).
* Blocks: Using blocks with GCD will often result in simpler and more elegant code, but blocks are not part of standard C. Mark provides a 'blocks' library called 'libblocksruntime', but even better, GNUstep has its own implementation of blocks. The two libarires are based on Apples blocks library and have the same API. However, what is not obvious is that the ABI of libblocksruntime is C, however the ABI of GNUstep is objective C. And mixing the two ABIs could lead to memory corruption under certain circumstances. ([https://github.com/nickhutchinson/libdispatch/issues/2 See xcvista's second comment].) * Blocks: Using blocks with GCD will often result in simpler and more elegant code, but blocks are not part of standard C. Mark provides a 'blocks' library called 'libblocksruntime', but even better, GNUstep has its own implementation of blocks. The two libarires are based on Apples blocks library and have the same API. However, what is not obvious is that the ABI of libblocksruntime is C, however the ABI of GNUstep is objective C. And mixing the two ABIs could lead to memory corruption under certain circumstances. ([https://github.com/nickhutchinson/libdispatch/issues/2 See xcvista's second comment].)
-In fact, I did try to get libdispatch on Kubuntu 13. I found that the gcc package must be installed in order to get the objc.h header to compile against, and I had to put the location of objc.h in <GNUstep root>/Makefiles/config.make, as well as adding clang in there. Being new to GNUstep I had a couple of other issues, and it all started having a bad smell about the thing. In addition, posts to the gnustep-discuss newsgroup this year consistently recommended installing from source, so to the the source I went.+In fact, I did try to get libdispatch on Kubuntu 13. I found that the gcc package must be installed in order to get the objc.h header to compile against, and I had to put the location of objc.h in <GNUstep root>/Makefiles/config.make, as well as adding clang in there. Being new to GNUstep I had a couple of other issues, and I started having the "bad smell" feeling that goes with graunching two ABIs. In addition, posts to the gnustep-discuss newsgroup this year consistently recommended installing from source, so to the the source I went.
-libobjc2 and gnustep-base installation+== libobjc2 and gnustep-base installation from source ==
Ivan Vucica has a handy install script for download: https://bitbucket.org/ivucica/ Ivan Vucica has a handy install script for download: https://bitbucket.org/ivucica/
-* I recommend you have a fresh Debian or Ubuntu installation. If not, I recommend you remove all gnustep packages, libobjc* packages, libdispatch* packages, and libblocksruntime* packages.+* I recommend you have a fresh Debian or Ubuntu installation. If not, you should remove all gnustep packages, libobjc* packages, libdispatch* packages, and libblocksruntime* packages.
-* I ran installs on both Gentoo Linux and Kubuntu 13. Gentoo takes a while to setup, but can be simpler for something like this because there is no other cruft around.�+* I ran installs on both Gentoo Linux and Kubuntu 13. Gentoo takes a while to setup, but can be simpler for something like this because there is no other cruft around.
 + 
 +

Revision as of 02:37, 3 June 2013

This guide shows how to install GNUstep-base with clang, blocks and Grand Central Dispatch on Linux.

Grand Central Dispatch is a library to assist building apps on multi-core processors. The library for Grand Central Dispatch is called libdispatch, and tasks can be submitted to GCD in blocks or with a C API. To understand the process below, some notes are in order. If you're in a hurry, you can probably skip the notes down to the install instructions.

GNUstep runtime

  • So far as GNUstep, the runtime library for Objective C code used to be called libobjc until Apple released Objective C version 2, and then is called libobjc2. You can get the background here: http://wiki.gnustep.org/index.php/ObjC2_FAQ . (Note Debian and Ubuntu libobjc3 and libobjc4 are still based on libobjc and libobjc2 but numbered differently).
    • libobjc2 built with GCC 4.6 and 4.7 has most of Objective C v2 supported, but doesn't have blocks support
    • libobjc2 built with Clang does have block support: (use -fblocks flag when compiling your own code)
    • GNUstep provides block support, whether the compiler does or not. So if using GNUstep, you can use blocks with a GCC libobjc2.
    • libdispatch currently has some build requirements that necessitate using clang.

So we're going with a clang build since a working GCD is the aim here.

Next, we observe that Debian wheezy and Ubuntu 13 have a libdispatch infrastructure built on clang (libobjc2 and libdispatch are built using clang). So there are some more decisions:- Why not just run with what Debian provides instead of compiling from scratch, i.e.

  • libobjc2, libdispatch, cblocksruntime compiled with erlang
  • gnustep programs compiled with gcc

To make a decision, here is some background on GCD and blocks

  • GCD: As far as I can make out, there are two implementations of GCD out there for Linux. One by Mark Heily and one called libxdispatch. So far as using GCD with GNUstep, Mark's library is the one to use, and this is also the libdispatch library in Debian and Ubuntu.
  • GCD is more than just a C library. It requires support from the kernel with light threads (libpthread), and an adptation of BSD signals for Linux (libkqueue).
  • Blocks: Using blocks with GCD will often result in simpler and more elegant code, but blocks are not part of standard C. Mark provides a 'blocks' library called 'libblocksruntime', but even better, GNUstep has its own implementation of blocks. The two libarires are based on Apples blocks library and have the same API. However, what is not obvious is that the ABI of libblocksruntime is C, however the ABI of GNUstep is objective C. And mixing the two ABIs could lead to memory corruption under certain circumstances. (See xcvista's second comment.)

In fact, I did try to get libdispatch on Kubuntu 13. I found that the gcc package must be installed in order to get the objc.h header to compile against, and I had to put the location of objc.h in <GNUstep root>/Makefiles/config.make, as well as adding clang in there. Being new to GNUstep I had a couple of other issues, and I started having the "bad smell" feeling that goes with graunching two ABIs. In addition, posts to the gnustep-discuss newsgroup this year consistently recommended installing from source, so to the the source I went.

libobjc2 and gnustep-base installation from source

Ivan Vucica has a handy install script for download: https://bitbucket.org/ivucica/

  • I recommend you have a fresh Debian or Ubuntu installation. If not, you should remove all gnustep packages, libobjc* packages, libdispatch* packages, and libblocksruntime* packages.
  • I ran installs on both Gentoo Linux and Kubuntu 13. Gentoo takes a while to setup, but can be simpler for something like this because there is no other cruft around.