Objective-c support


does cling have any support for objective-c?

If so, how do I activate it?



In principle you activate it with -x objc, like a compiler.

But we have not spent a single second in ObjC support and so it will not work. I thought everyone is using Swift these days? :wink:

Cheers, Axel.

The option -x objc returns:

yawmoos-MacBook:bin yawmoo$ ./cling -x objc
error: language not recognized: ‘objc’

I still use objective-c. What would be needed in order to support it?


so indeed it’s -x objective-c

We will need patches… You will see when starting up that cling compiles some code that’s C++ - we will need a ObjC replacement.

It’s certainly possible - it’s just a bit of work. I will happily accept your patches!


Can you please clarify what you mean and give me some quick guidance so that I can look at what exactly is involved? I would consider patching cling for objc :slight_smile:


To see failure run e.g.

$ ./interpreter/llvm/obj/Debug+Asserts/bin/cling -x objective-c

***************** CLING *****************
* Type C code and press enter to run it *
*            Type .q to exit            *
[cling]$ 12
cling: /home/axel/build/root/github/src/interpreter/cling/lib/Interpreter/ValueExtractionSynthesizer.cpp:401: void cling::ValueExtractionSynthesizer::FindAndCacheRuntimeDecls(): Assertion `!R.empty() && "Cannot find cling::runtime::internal::setValueNoAlloc"' failed.

You can check for all occurrences of CPlusPlus (case insensitive) in cling’s sources to find all the spots where language matters.

Cheers, Axel.

Hi Axel,

I started having a look at this (unfortunately I don’t have a lot of time, so I am proceeding slowly).

I managed to run cling using objective-c++ as a language, so it calls all the existing functions for c++. However I get the following problems:

  1. #import does not work, while #include does

  2. if I call a method on an objective-c class I get the error below, which pretty much says that the objective-c runtime is not working as expected.

Can you please head me in the right direction to solve this?


Alessandros-Mac-mini:bin alessandro$ cling -x objective-c++

****************** CLING ******************

  • Type C++ code and press enter to run it *
  •         Type .q to exit             *

[cling]$ .L /System/Library/Frameworks/Foundation.framework/Foundation
[cling]$ #include <Foundation/Foundation.h>
[cling]$ NSString *s = [NSString stringWithCString:“abcd” encoding:NSUTF8StringEncoding error:NULL];
input_line_4:2:26: warning: class method '+stringWithCString:encoding:error:'
not found (return type defaults to ‘id’) [-Wobjc-method-access]
…[NSString stringWithCString:“abcd” encoding:NSUTF8StringEncoding error:N…
2015-06-22 17:54:51.083 cling[14571:243292] *** NSForwarding: warning: selector (0x10cccd030) for message ‘stringWithCString:encoding:error:’ does not match selector known to Objective C runtime (0x7f82ad00b7c0)-- abort
2015-06-22 17:54:51.085 cling[14571:243292] +[NSString stringWithCString:encoding:error:]: unrecognized selector sent to class 0x7fff79a756d8
2015-06-22 17:54:51.245 cling[14571:243292] *** Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘+[NSString stringWithCString:encoding:error:]: unrecognized selector sent to class 0x7fff79a756d8’
*** First throw call stack:
0 CoreFoundation 0x00007fff8c7e803c __exceptionPreprocess + 172
1 libobjc.A.dylib 0x00007fff8cdd776e objc_exception_throw + 43
2 CoreFoundation 0x00007fff8c7eafad +[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x00007fff8c730e24 forwarding + 1028
4 CoreFoundation 0x00007fff8c730998 _CF_forwarding_prep_0 + 120
5 ??? 0x000000010cccc03c 0x0 + 4509712444
6 ??? 0x000000010cccc060 0x0 + 4509712480
7 cling 0x0000000109608407 _ZN5cling19IncrementalExecutor11executeInitEN4llvm9StringRefE + 87
8 cling 0x00000001096067ce _ZN5cling19IncrementalExecutor25runStaticInitializersOnceERKNS_11TransactionE + 846
9 cling 0x000000010964a852 _ZN5cling11Interpreter18executeTransactionERNS_11TransactionE + 418
10 cling 0x000000010962dddb _ZN5cling17IncrementalParser17commitTransactionEN4llvm14PointerIntPairIPNS_11TransactionELj2ENS0_12EParseResultENS1_21PointerLikeTypeTraitsIS4_EEEE + 3227
11 cling 0x000000010962f5f7 _ZN5cling17IncrementalParser7CompileEN4llvm9StringRefERKNS_18CompilationOptionsE + 183
12 cling 0x0000000109649570 _ZN5cling11Interpreter16EvaluateInternalERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEENS_18CompilationOptionsEPNS_5ValueEPPNS_11TransactionE + 480
13 cling 0x00000001096482dd _ZN5cling11Interpreter7processERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEPNS_5ValueEPPNS_11TransactionE + 301
14 cling 0x000000010943b0d4 _ZN5cling13MetaProcessor7processEPKcRNS_11Interpreter17CompilationResultEPNS_5ValueE + 1332
15 cling 0x00000001093ede92 _ZN5cling13UserInterface16runInteractivelyEb + 2098
16 cling 0x0000000107de214d main + 5437
17 libdyld.dylib 0x00007fff89f975c9 start + 1
libc++abi.dylib: terminating with uncaught exception of type NSException
Abort trap: 6
Alessandros-Mac-mini:bin alessandro$


I have no idea how the ObjectiveC runtime works. Do we need to link against something? Do we need to load something into the interpreter? I’m afraid I’m not the right person to ask… But once you found out what needs to be done we can discuss how to do it! :slight_smile:

Cheers, Axel.