GC3: Grid Computing Competence Center

Blog index

GC3 graudates into S3IT
Posted early Tuesday morning, July 1st, 2014
How to create a module that also load a virtualenvironment
Posted late Friday morning, March 7th, 2014
Openstack workshop at GC3
Posted at noon on Saturday, February 22nd, 2014
Moving LVM volumes used by a Cinder storage
Posted late Friday evening, February 21st, 2014
How to configure swift glusterfs
Posted Monday night, February 10th, 2014
Yet another timeout problem when starting many instances at once
Posted late Friday night, February 8th, 2014
Fixing LDAP Authentication over TLS/SSL
Posted Monday night, January 6th, 2014
Linker command-line options for Intel MKL
Posted Saturday night, January 4th, 2014
A virtue of lazyness
Posted Saturday afternoon, December 21st, 2013
(Almost) readable CFEngine logs
Posted Thursday afternoon, December 19th, 2013
CFEngine error: ExpandAndMapIteratorsFromScalar called with invalid strlen
Posted Wednesday afternoon, December 11th, 2013
'Martian source' log messages and the default IP route
Posted Monday afternoon, November 25th, 2013
GC3 takes over maintenance of the Schroedinger cluster
Posted at noon on Monday, November 4th, 2013
Grid Engine: how to find the set of nodes that ran a job (after it's finished)
Posted early Wednesday morning, October 30th, 2013
Python2 vs Python3
Posted at teatime on Friday, September 13th, 2013
GC3Pie 2.1.1 released
Posted Friday evening, September 6th, 2013
Happy SysAdmin day!
Posted mid-morning Friday, July 26th, 2013
Object-oriented Python training
Posted Thursday afternoon, July 25th, 2013
Elasticluster 1.0.0 released
Posted Thursday night, July 18th, 2013
Short Autotools tutorial
Posted at lunch time on Friday, July 5th, 2013
Patch Emacs' PostScript printing
Posted Tuesday evening, June 11th, 2013
Slides of the Object-oriented Python course now available!
Posted Tuesday evening, June 11th, 2013
Automated deployment of CFEngine keys
Posted at midnight, May 31st, 2013
blog/Resize_an_image
Posted Tuesday evening, May 14th, 2013
Join us at the Compute Cloud Experience Workshop!
Posted early Monday morning, April 29th, 2013
GC3 Beamer theme released
Posted at lunch time on Friday, April 5th, 2013
VM-MAD at the International Supercompting Conference 2013
Posted at lunch time on Tuesday, March 26th, 2013
The GC3 is on GitHub
Posted at lunch time on Monday, March 18th, 2013
How to enable search in IkiWiki
Posted Friday afternoon, March 15th, 2013
GC3Pie Training
Posted Thursday night, March 7th, 2013
Object-oriented Python training
Posted Thursday afternoon, March 7th, 2013
Advance Reservations in GridEngine
Posted late Thursday morning, March 7th, 2013
GridEngine accounting queries with PostgreSQL
Posted Wednesday night, March 6th, 2013
Floating IPs not available on Hobbes
Posted at teatime on Tuesday, February 26th, 2013
Notes on SWIFT
Posted mid-morning Tuesday, February 12th, 2013
An online Python code quality analyzer
Posted at lunch time on Saturday, February 9th, 2013
Seminar on cloud infrastructure
Posted Sunday night, February 3rd, 2013
GC3 announce its cloud infrastructure Hobbes
Posted Wednesday afternoon, January 30th, 2013
GC3Pie 2.0.2 released
Posted Monday afternoon, January 28th, 2013
Continuous Integration with Jenkins
Posted at noon on Saturday, January 26th, 2013
On the importance of testing in a clean environment
Posted mid-morning Monday, January 21st, 2013
Weirdness with ImageMagick's `convert`
Posted at teatime on Tuesday, January 15th, 2013
boto vs libcloud
Posted Tuesday afternoon, January 15th, 2013
Resolve timeout problem when starting many instances at once
Posted at lunch time on Monday, January 7th, 2013
Proceedings of the EGI Community Forum 2012 published
Posted at teatime on Monday, December 17th, 2012
SGE Workaround Installation
Posted at lunch time on Tuesday, December 4th, 2012
How to pass an argument of list type to a CFEngine3 bundle
Posted mid-morning Thursday, November 22nd, 2012
GC3 at the 'Clouds for Future Internet' workshop
Posted mid-morning Wednesday, November 21st, 2012
GC3 attends European Commission Cloud Expert Group
Posted mid-morning Monday, October 29th, 2012
SwiNG - SDCD2012 event
Posted at lunch time on Monday, October 22nd, 2012
Large Scale Computing Infrastructures class starts tomorrow!
Posted late Tuesday afternoon, September 25th, 2012
From bare metal to cloud at GC3
Posted mid-morning Monday, September 24th, 2012
GC3 at the EGI Technical Forum 2012
Posted Thursday night, September 20th, 2012
Training on GC3Pie and Python
Posted late Friday evening, September 7th, 2012
GC3Pie used for research in Computational Quantum Chemistry
Posted late Thursday afternoon, September 6th, 2012
``What's so great about MPI or Boost.MPI?''
Posted mid-morning Thursday, September 6th, 2012
blog/How to generate UML diagram with `pyreverse`
Posted late Thursday morning, August 23rd, 2012
Git's `rebase` command
Posted mid-morning Friday, June 15th, 2012
AppPot 0.27 released!
Posted at noon on Thursday, June 14th, 2012
Urban computing - connecting to your server using `mosh`
Posted mid-morning Wednesday, June 6th, 2012
Whitespace cleanup with Emacs
Posted Tuesday afternoon, June 5th, 2012
Translate pages on this site
Posted Thursday evening, May 31st, 2012
Scientific paper citing GC3Pie
Posted Wednesday evening, May 30th, 2012
GC3 attends Nordugrid 2012 conference
Posted at lunch time on Wednesday, May 30th, 2012
How the front page image was made
Posted late Wednesday evening, May 16th, 2012
GC3 blog launched!
Posted late Tuesday evening, May 15th, 2012
New GC3 Wiki now online!
Posted Tuesday evening, May 15th, 2012
AppPot paper on arXiv
Posted Tuesday evening, May 15th, 2012
GC3 at the EGI Technical Forum 2011
Posted Tuesday evening, May 15th, 2012

More on topic...

Compiling an Objective-C application on Ubuntu (Hobbes instance)

One of our users developed an Objective-C application on his MacOSX machine, and had trouble compiling it on an instance on Hobbes, running Ubuntu 12.04 LTS.

Compiling Objective-C application is a bit uncommon for Linux users, so I'm writing down a few notes in case you stumble upon the same mistakes I made.

The Step by step example_ will guide you through all the errors you will find trying to compile the program, while the Compiling, the easy way_ section will show you how you are supposed to do it.

Step by step example

First of all, you need the objective-c compiler, which is, of course GCC, but on Ubuntu you need to installe one more package containing libraries and header files. Since you are compiling, it's a good idea to install also the build-essential metapackage which contains some standard development tools as well:

apt-get install gobjc build-essential

Then, download this simple hello world file: hello.m

#import <Foundation/Foundation.h>

@interface HelloWorld : NSObject
- (void) hello;
@end

@implementation HelloWorld
- (void) hello {
    NSLog(@"hello world!");
}
@end

int main(void) {
    HelloWorld *hw = [[HelloWorld alloc] init];
    [hw hello];
    [hw release];
}

GCC is able to compile objective-c code, and should be able to recognize the source code automatically; however, if you try to compile it and you get an error like:

~$ gcc hello.m
hello.m:2:2: warning: #import is a deprecated GCC extension [-Wdeprecated]
hello.m:2:34: fatal error: Foundation/Foundation.h: No such file or directory
compilation terminated.

it means that GCC misinterpreted the source code as C language, so add the option -x objective-c

The next thing you will try to do is:

~$ gcc -x objective-c hello.m
hello.m:2:34: fatal error: Foundation/Foundation.h: No such file or directory
compilation terminated.

which will fail. Even though the Foundation/Foundation.h header file is a very standard header (like <stdio.h> for C), it's not found by default, and it's not even installed together with the gobjc package: you have to install gnustep-devel:

apt-get install gnustep-devel

This will install the Foundation/ directory in /usr/include/GNUstep/. Of course the following command will not be enough:

~$ gcc -x objective-c -I/usr/include/GNUstep hello.m
In file included from /usr/include/GNUstep/Foundation/NSClassDescription.h:30:0,
                 from /usr/include/GNUstep/Foundation/Foundation.h:50,
                 from hello.m:2:
/usr/include/GNUstep/Foundation/NSException.h:42:2: error: #error The current setting for native-objc-exceptions does not match that of gnustep-base ... please correct this.
hello.m: In function ‘-[HelloWorld hello]’:
hello.m:10:5: error: cannot find interface declaration for ‘NXConstantString’

To get rid of the NXConstantString error, add the option -fconstant-string-class=NSConstantString:

~$ gcc -x objective-c -I/usr/include/GNUstep -fconstant-string-class=NSConstantString   hello.m
In file included from /usr/include/GNUstep/Foundation/NSClassDescription.h:30:0,
                 from /usr/include/GNUstep/Foundation/Foundation.h:50,
                 from hello.m:2:
/usr/include/GNUstep/Foundation/NSException.h:42:2: error: #error The current setting for native-objc-exceptions does not match that of gnustep-base ... please correct this.

while the last error is removed by passing -D_NATIVE_OBJC_EXCEPTIONS option:

~$ gcc  -x objective-c -I/usr/include/GNUstep -fconstant-string-class=NSConstantString  -D_NATIVE_OBJC_EXCEPTIONS hello.m
/tmp/ccRfUDNU.o: In function `_i_HelloWorld__hello':
hello.m:(.text+0x1b): undefined reference to `NSLog'
/tmp/ccRfUDNU.o: In function `main':
hello.m:(.text+0x30): undefined reference to `objc_get_class'
hello.m:(.text+0x40): undefined reference to `objc_msg_lookup'
hello.m:(.text+0x5a): undefined reference to `objc_msg_lookup'
hello.m:(.text+0x79): undefined reference to `objc_msg_lookup'
hello.m:(.text+0x94): undefined reference to `objc_msg_lookup'
/tmp/ccRfUDNU.o: In function `__objc_gnu_init':
hello.m:(.text+0xb3): undefined reference to `__objc_exec_class'
/tmp/ccRfUDNU.o:(.data+0x260): undefined reference to `__objc_class_name_NSConstantString'
/tmp/ccRfUDNU.o:(.data+0x270): undefined reference to `__objc_class_name_NSObject'
collect2: ld returned 1 exit status

Now we only have a linking problem, which should be solved linking against the gnustep-base library:

~$ gcc  -x objective-c -I/usr/include/GNUstep -fconstant-string-class=NSConstantString  -D_NATIVE_OBJC_EXCEPTIONS -lgnustep-base hello.m
/tmp/ccN4Knor.o: In function `_i_HelloWorld__hello':
hello.m:(.text+0x1b): undefined reference to `NSLog'
/tmp/ccN4Knor.o: In function `main':
hello.m:(.text+0x30): undefined reference to `objc_get_class'
hello.m:(.text+0x40): undefined reference to `objc_msg_lookup'
hello.m:(.text+0x5a): undefined reference to `objc_msg_lookup'
hello.m:(.text+0x79): undefined reference to `objc_msg_lookup'
hello.m:(.text+0x94): undefined reference to `objc_msg_lookup'
/tmp/ccN4Knor.o: In function `__objc_gnu_init':
hello.m:(.text+0xb3): undefined reference to `__objc_exec_class'
/tmp/ccN4Knor.o:(.data+0x260): undefined reference to `__objc_class_name_NSConstantString'
/tmp/ccN4Knor.o:(.data+0x270): undefined reference to `__objc_class_name_NSObject'
collect2: ld returned 1 exit status

Why, you may ask? Simple: the -l<library> options must be put after the source file (or the object files) you are compiling/linking, like in:

~$ gcc  -x objective-c -I/usr/include/GNUstep -fconstant-string-class=NSConstantString  -D_NATIVE_OBJC_EXCEPTIONS hello.m -lgnustep-base
~$

Compiling, the easy way

The compilation flags showed in the previous example are not sufficient for any program. Luckly, the gnustep-devel package provides a tools with similar functionalities to the pkg-config used for all the packages supporting it. This tool is invoked with the gnustep-config command, and accept multiple options:

~$ gnustep-config --help
usage: gnustep-config [option]

This program prints information on the current gnustep
installation.  [option] determines what is printed.  Here
is the list of options:

[...]
--objc-flags: prints all the flags required to compile an ObjC file

--objc-libs: prints all the flags required to link a pure ObjC program (no foundation/gui)

--base-libs: prints all the flags required to link a command-line ObjC program (no gui)

--gui-libs: prints all the flags required to link a GUI ObjC program
[...]

To compile the hello.m program, for instance, this command line will do the job:

~$ gcc $(gnustep-config --objc-flags) hello.m $(gnustep-config --base-libs)
hello.m: In function ‘main’:
hello.m:18:1: warning: control reaches end of non-void function [-Wreturn-type]

The reason why we are now getting a warning while compiling the code is because:

~$ gnustep-config --objc-flags
-MMD -MP -DGNUSTEP -DGNUSTEP_BASE_LIBRARY=1 -DGNU_GUI_LIBRARY=1 -DGNU_RUNTIME=1 -DGNUSTEP_BASE_LIBRARY=1 -fno-strict-aliasing -fexceptions -fobjc-exceptions -D_NATIVE_OBJC_EXCEPTIONS -fPIC -Wall -DGSWARN -DGSDIAGNOSE -Wno-import -g -O2 -fstack-protector --param=ssp-buffer-size=4 -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -Werror=format-security -fgnu-runtime -fconstant-string-class=NSConstantString -I. -I/home/gc3-user/GNUstep/Library/Headers -I/usr/local/include/GNUstep -I/usr/include/GNUstep

has the -Wall option as well.

top