0

I have to convert java code to objective-c code. Here I have to write the following code and run on my terminal:

$ cat Hello.java 
public class Hello {
public static void main(String[] args) {
System.out.println("hello, world");
 }
 }
$ j2objc Hello.java
translating Hello.java
Translated 1 file: 0 errors, 0 warnings

To compile the translated file:

$ j2objcc -c Hello.m
$ j2objcc -o hello Hello.o

Here when I run $ j2objcc -o hello Hello.o on my terminal, I get the following error.

$ j2objcc -o hello Hello.o
Undefined symbols:
  "_objc_autoreleasePoolPop", referenced from:
      -[JavaLangThread run] in libjre_emul.a(Thread.o)
  "_objc_autoreleasePoolPush", referenced from:
      -[JavaLangThread run] in libjre_emul.a(Thread.o)
ld: symbol(s) not found
clang: error: linker command failed with exit code 1 (use -v to see invocation)

How can I resolve this error?

durron597
  • 31,968
  • 17
  • 99
  • 158
user1676640
  • 635
  • 7
  • 17
  • 37
  • 1
    seems like the folder where `j2objc` is located is not in your path. – MByD Oct 12 '12 at 12:51
  • What version of Xcode do you have installed? – rob mayoff Oct 15 '12 at 03:49
  • looks like the error is caused by clang. Do you have clang correctly setup and can you run the command clang from the Terminal? Have you tried to run in verbose mode and see if it gives you more info? j2objcc -v -o hello Hello.o – Giorgio Apr 01 '13 at 13:48

2 Answers2

2

You need to add the path to where you unzipped the j2objc distribution bundle. For example:

$ cd $HOME
$ unzip ~/Downloads/j2objc-*.zip
$ export PATH=${PATH}:${HOME}/j2objc

Note: the export command above needs to be added to your ${HOME}/.bashrc file so it's set when you log out and back in.

tball
  • 1,984
  • 11
  • 21
1

You comment you are using XCode 3.2.6. Currently, J2ObjC seems to require XCode 4+.

Reference: https://code.google.com/p/j2objc/

ArturoTena
  • 713
  • 5
  • 15