Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

j2objc 0.9.8.2 and Xcode 7 not yet supported - "ld: library not found for -lj2objc_main" #466

Closed
andrewfunston opened this issue Sep 27, 2015 · 30 comments
Assignees
Milestone

Comments

@andrewfunston
Copy link

I've searched a bit and found nothing that seems similar. I've also checked my build environment vs the docs + FAQ and haven't found anything out of line. I'm new to j2objc and was trying to get a minimal build environment running. I followed the recommendations for build environment setup from the j2objc docs.

j2objc version was a pull/build from master from today (9/26/2015), but I tried with the release version ".9.8.2" with the same results.

Sorry for the image of my build.gradle, it kept failing when I had it converted to a .txt, etc. Very odd.

The error is as follows:

:java-core:x86_64DebugJava-core-j2objcStaticLibrary
:java-core:linkDebugTestJ2objcExecutable
ld: library not found for -lj2objc_main
clang: error: linker command failed with exit code 1 (use -v to see invocation)

:java-core:linkDebugTestJ2objcExecutable FAILED

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':java-core:linkDebugTestJ2objcExecutable'.

    A build operation failed.
    Linker failed while linking testJ2objc.
    See the complete log at: file:///Users/a/parati/java-core/build/tmp/linkDebugTestJ2objcExecutable/output.txt

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

screen shot 2015-09-26 at 10 27 56 pm

@advayDev1
Copy link
Contributor

What are the full errors in:
file:///Users/a/parati/java-core/build/tmp/linkDebugTestJ2objcExecutable/output.txt ?

@andrewfunston
Copy link
Author

I can't attach txt files so I'll have to plop them here, but it says essentially the same thing:


See file:///Users/a/parati/java-core/build/tmp/linkDebugTestJ2objcExecutable/output.txt for all output for linkDebugTestJ2objcExecutable.
linking testJ2objc failed.
ld: library not found for -lj2objc_main
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Finished linkDebugTestJ2objcExecutable, see full log file:///Users/a/parati/java-core/build/tmp/linkDebugTestJ2objcExecutable/output.txt.


Also in the directory [/Users/a/parati/java-core/build/tmp/linkDebugTestJ2objcExecutable/] is the "options.txt" that has this:


-o
/Users/a/parati/java-core/build/binaries/testJ2objcExecutable/debug/testJ2objc
/Users/a/parati/java-core/build/objs/testJ2objcExecutable/debug/testJ2objcObjc/551bb472kewcfrm35cmxbgh2t/EmptyTest.o
/Users/a/parati/java-core/build/objs/testJ2objcExecutable/debug/testJ2objcObjc/e8di3ks3a2jrkijz9l5wqcpvs/BaseTest.o
/Users/a/parati/java-core/build/binaries/java-core-j2objcStaticLibrary/x86_64Debug/libjava-core-j2objc.a
-ljunit
-lmockito
-ObjC
-lguava
-lj2objc_main
-ljavax_inject
-ljre_emul
-ljsr305
-L/Users/a/install/j2objc-master/dist/lib
-lc++
-licucore
-lz
-framework
foundation
-framework
Security
-framework
ExceptionHandling


@advayDev1
Copy link
Contributor

What is the output of
ls -al /Users/a/install/j2objc-master/dist/lib
?

@advayDev1
Copy link
Contributor

@andrewfunston : please do answer the above, but I think I know the problem.

j2objc_main was moved into the Mac-only builds with 0.9.8.2 to support Xcode 7. The plugin only supports j2objc 0.9.8.1 and Xcode 6 at the moment. I've updated the title to reflect this.

@advayDev1 advayDev1 changed the title Gradle build fails while linking with "ld: library not found for -lj2objc_main" j2objc 0.9.8.2 and Xcode 7 not yet supported - "ld: library not found for -lj2objc_main" Sep 28, 2015
@advayDev1 advayDev1 added this to the 0.5 Release milestone Sep 28, 2015
@advayDev1
Copy link
Contributor

This is going to be a non-trivial amount of work. A lot of our tasks assume iOS and OSX use the same files.

Let's discuss on Wednesday @brunobowden

@advayDev1
Copy link
Contributor

@andrewfunston - if you can use Xcode 6 / j2objc 0.9.8.1 you should try doing so; this will take a while to get working on Xcode 7 / j2objc 0.9.8.2.

@andrewfunston
Copy link
Author

Sorry for the delay, as for the first request:

as-MacBook-Pro:~ a$ ls -al /Users/a/install/j2objc-master/dist/lib/
total 684872
drwxr-xr-x 21 a staff 714 Sep 26 17:02 .
drwxr-xr-x 9 a staff 306 Sep 26 17:02 ..
-rw-r--r-- 1 a staff 11108331 Sep 26 17:02 cycle_finder.jar
-rw-r--r-- 1 a staff 45024 Sep 26 16:33 hamcrest-core-1.3.jar
-rw-r--r-- 1 a staff 11084601 Sep 26 16:33 j2objc.jar
-rw-r--r-- 1 a staff 6540 Sep 26 16:28 j2objc_annotations.jar
-rw-r--r-- 1 a staff 1947757 Sep 26 16:54 j2objc_guava.jar
-rw-r--r-- 1 a staff 245039 Sep 26 16:33 j2objc_junit.jar
-rw-r--r-- 1 a staff 2497 Sep 26 16:33 javax.inject-1.jar
-rw-r--r-- 1 a staff 3186072 Sep 26 16:44 jre_emul-src.jar
-rw-r--r-- 1 a staff 2353625 Sep 26 16:33 jre_emul.jar
-rw-r--r-- 1 a staff 33031 Sep 26 16:33 jsr305-3.0.0.jar
-rw-r--r-- 1 a staff 93376320 Sep 26 16:54 libguava.a
-rw-r--r-- 1 a staff 341648 Sep 26 16:48 libjavax_inject.a
-rw-r--r-- 1 a staff 126732112 Sep 26 16:42 libjre_emul.a
-rw-r--r-- 1 a staff 65256752 Sep 26 16:42 libjre_emul_core.a
-rw-r--r-- 1 a staff 1986848 Sep 26 16:47 libjsr305.a
-rw-r--r-- 1 a staff 14253872 Sep 26 16:47 libjunit.a
-rw-r--r-- 1 a staff 17165496 Sep 26 17:00 libmockito.a
drwxr-xr-x 10 a staff 340 Sep 26 17:01 macosx
-rw-r--r-- 1 a staff 1500011 Sep 26 16:33 mockito-core-1.9.5.jar

Right now I only have it generating the sources which works well enough for my exploratory purposes. (i.e. setting j2objc.translateOnlyMode=true). Thanks for your help.

advayDev1 added a commit to madvay/j2objc-gradle that referenced this issue Oct 5, 2015
advayDev1 added a commit to madvay/j2objc-gradle that referenced this issue Oct 5, 2015
advayDev1 added a commit to madvay/j2objc-gradle that referenced this issue Oct 5, 2015
Refactor of native compilation to support separate ios vs. osx libraries.

Issue j2objc-contrib#466
@advayDev1
Copy link
Contributor

Hello @andrewfunston - I believe this is fixed. Would you like to be a guinea pig for us? =)

Please ensure you have Xcode 7 and j2objc 0.9.8.2.1. And please build the plugin directly from head (see https://github.com/j2objc-contrib/j2objc-gradle/blob/master/CONTRIBUTING.md sections "Local Development" and "Testing on your own Gradle project"). Let us know if you have any difficulties.

@advayDev1
Copy link
Contributor

cc @kirkvogen

@advayDev1
Copy link
Contributor

Verified against my own internal app that Xcode 7 support is now working for iOS device, iOS simulator, and OSX desktop apps.

@maxbritto
Copy link

Hi @advayDev1 , thanks for the work on XCode 7 version support!
Is there anythibng we should change in our configuration to be able to use it ?
With those changes all the gradle tasks now work but I can't build on XCode.
It ignores the library :

ld: warning: ignoring file /Users/mbritto/Documents/Dev2A/Rainbow/branches/mobile/android-ios-cocoapods/rainbowapi/build/j2objcOutputs/lib/iosDebug/librainbowapi-j2objc.a, missing required architecture i386 in file /Users/mbritto/Documents/Dev2A/Rainbow/branches/mobile/android-ios-cocoapods/rainbowapi/build/j2objcOutputs/lib/iosDebug/librainbowapi-j2objc.a (3 slices)

And as a result I have link errors for every j2objc class I use in the project.

@advayDev1
Copy link
Contributor

@maxbritto in your build.gradle's j2objcConfig section please add:

j2objcConfig {
supportedArchs += ['ios_i386']
}

I'm intrigued as to what OS versions you are building for that i386 is relevant (we thought it was just for 32-bit simulators so removed it from the default set). This is unrelated to Xcode 7 though.

@maxbritto
Copy link

It was for the iPhone 5 simulator. I did some more tests and without adding the modifications to the gradle file I can build for a real iPhone or for the simulators starting at iPhone 5S. The iPhone 4S and iPhone 5 simulator have the link error.

@advayDev1
Copy link
Contributor

To be clear:

  • without the supportedArchs change it works on all real iphones and iphone 5s simulators and beyond
  • with the supportedArchs change it works also on the simulator for 4s and the simulator for 5
    did i read that right?

So @maxbritto everything is working for you overall?

@maxbritto
Copy link

That is exactly that and yes, everything is working for me know, thanks for your help :)

@advayDev1
Copy link
Contributor

np - @maxbritto thanks for being a guinea pig.

@kirkvogen
Copy link

I built it and tried out the new version locally. I can build my project with the new plugin version, but in Xcode I get linker errors saying that it cannot find my classes that were translated from Java. Also, if I add the -mios-version-min=8.0 as extraObjcCompilerArgs, I get additional build errors (error: 'CSSM_SAMPLE' is unavailable: not available on iOS).

@andrewfunston
Copy link
Author

Apologies: I'm afk until Wednesday, I'll run through it when I get back
into the office then. Thanks for the update, that was fast!

On Mon, Oct 5, 2015, 2:08 AM Advay Mengle [email protected] wrote:

np - @maxbritto https://github.com/maxbritto thanks for being a guinea
pig.


Reply to this email directly or view it on GitHub
#466 (comment)
.

@advayDev1
Copy link
Contributor

@kirkvogen, can you please paste the exact Xcode errors you get?

Does your linker log have anything like:

ld: warning: ignoring file /Users/mbritto/Documents/Dev2A/Rainbow/branches/mobile/android-ios-cocoapods/rainbowapi/build/j2objcOutputs/lib/iosDebug/librainbowapi-j2objc.a, 
missing required architecture i386 in file /Users/mbritto/Documents/Dev2A/Rainbow/branches/mobile/android-ios-cocoapods/rainbowapi/build/j2objcOutputs/lib/iosDebug/librainbowapi-j2objc.a 
(3 slices)

If so add to the top of your build.gradle's j2objcConfig section: supportedArchs += ['ios_i386']

Also Instead of using -mios-version-min=8.0; you can now add to the top of your j2objcConfig: minIosVersion = '8.0'

@kirkvogen
Copy link

@advayDev1 Hey, success! I did need to add the supportedArchs bit to resolve the linker errors. And, the minIosVersion setting resolved the linker warnings. Thanks!

@kirkvogen
Copy link

@advayDev1 Also, I can now run the build task and run J2ObjC-translated unit tests. Previously, I was getting build errors with the earlier version of the plugin when I tried running the test. It works now!

@advayDev1
Copy link
Contributor

Thanks @kirkvogen ! Good to know everything's working for you. If any of you on this thread who have the basics working and need to try some of the more advanced stuff (multiple projects, custom external libraries, etc.), check out #490 and please provide any feedback directly on that PR regarding things that are unclear.

@brunobowden - any luck getting your project working again with Xcode 7?

@brunobowden
Copy link
Contributor

It's working like a charm for me on Xcode 7. I've got it working for the
follwoing:

  • j2objc unit tests
  • iPhone 6 Plus (64 bit)
  • iPhone 6 Plus Simulator (x86_64)
  • iPhone 5 simulator (i386 through fix from the FAQ).

I was expecting the simulators to fail since it wasn't linking to the osx
library versions. What else needs to be fixed at this point?

On Mon, Oct 5, 2015 at 8:37 PM Advay Mengle [email protected]
wrote:

Thanks @kirkvogen https://github.com/kirkvogen ! Good to know
everything's working for you. If any of you on this thread who have the
basics working and need to try some of the more advanced stuff (multiple
projects, custom external libraries, etc.), check out #490
#490 and please
provide any feedback directly on that PR regarding things that are unclear.

@brunobowden https://github.com/brunobowden - any luck getting your
project working again with Xcode 7?


Reply to this email directly or view it on GitHub
#466 (comment)
.

@advayDev1
Copy link
Contributor

No the simulators need the appropriate architecture on iOS sysroot, not the OSX sysroot. I think the commit got that right. The only thing left for Xcode 7 is your bug #488 - which is for OSX based unit tests and apps, not for simulators

@kirkvogen
Copy link

I have experienced a couple of issues that it get in the way a bit. Sometimes Xcode crashes while the Gradle plugin is running. Also, build time is a bit of an issue. If I don't change any Java files, the build is a second or two. If I change a Java file, it often stays at the j2objcAssemble showing 98% for two to three minutes. Prior to using the plugin I had a Makefile for doing J2ObjC translation. That only took a few seconds to run. Granted, the Makefile did less. It just did translation and let Xcode do the ObjC compilation and linking.

I've watched the CPU during this long pause and it is typically around 3% utilized. This makes me wonder if it is some kind of file or I/O issue.

I've tried setting J2OBJC_RELEASE_ENABLED=false, but it doesn't seem to help much. I typically run the j2objcXcode task instead of build. I've got some translated test failures I need to fix before I can run build regularly.

@kirkvogen
Copy link

I think my performance issue might be due to a source JAR that I'm translating and building (hamcrest). I shouldn't need to translate and build it anyway, since the J2ObjC comes with hamcrest pre-built, right?

@kirkvogen
Copy link

I corrected the project to use the built-in JUnit and Hamcrest. The performance issue appears to have gone away. I can make a Java source change, rebuild, and takes about five seconds.

I added the following into j2objcConfig to include the built-in libraries. Is that the proper way to do it? I hope that doesn't result in my implementation (non-test) code being linked with those libraries.

translateJ2objcLibs = ["j2objc_junit.jar", "hamcrest-core-1.3.jar"]

@advayDev1
Copy link
Contributor

Yeah you did everything right. @kirkvogen , I've filed #492; we might as well add the new 0.9.8.2.1 libraries since we've made that a minimum requirement now.

@andrewfunston
Copy link
Author

It works for me! I had to reverted back to b7f4aad to get it functioning, the current head fails unable to link to the protobuf_runtime, but I assume that's part of a WIP.

Let me know if I need to run through anything else.

@advayDev1
Copy link
Contributor

@andrewfunston - could you expand at #498? Protobuf runtime is neither known to work nor known not to work, as neither Bruno or I use them at the moment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants