Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cordova command-line build fails in /tmp on Mac

I get a linker error building a brand-new PhoneGap app from the command line. It creates a bunch of files, and if I open the created .xcodeproj in Xcode, it builds just fine. So what's wrong with my command-line environment?

$ phonegap create /tmp/buildtest-ios
$ cd /tmp/buildtest-ios
$ phonegap -V build ios
[phonegap] detecting iOS SDK environment...
[phonegap] Checking iOS requirements...
[phonegap] using the local environment
[phonegap] compiling iOS...
[phonegap] Generating config.xml from defaults for platform "ios"
[phonegap] Compiling app on platform "ios" via command "/private/tmp/buildtest-ios/platforms/ios/cordova/build" 
   [error] An error occurred while building the ios project.** BUILD FAILED **


The following build commands failed:
    Check dependencies
(1 failure)
** BUILD FAILED **


The following build commands failed:
    Ld /private/tmp/buildtest-ios/platforms/ios/build/emulator/HelloWorld.app/HelloWorld normal i386
(1 failure)

If I run the offending Ld command myself from the command line, I get "file not found". Does that mean the compiler failed and the linker error is just a red herring?

This is PhoneGap 3.3.0-0.18.0 on Mac OS X 10.9. I can create and build an Android app with this installation, no trouble. I get the exact same behavior if I use cordova directly. I've tried it on two Macs with the same symptom.

like image 613
jab Avatar asked Dec 07 '13 01:12

jab


1 Answers

I finally discovered the answer using the cordova command-line tools. Cordova has a -d flag which is way more verbose than PhoneGap's -V flag. The linker was failing with a bunch of errors like

duplicate symbol _OBJC_METACLASS_$_CDVTimer in:
    /private/tmp/buildtest-ios/platforms/ios/build/emulator/libCordova.a(CDVTimer.o)
    /tmp/buildtest-ios/platforms/ios/build/emulator/libCordova.a(CDVTimer.o)

Note that /tmp on Mac is a symlink to /private/tmp, so these are pointing to the same file. No wonder they're duplicate symbols! So why is it trying to include the same file twice?

I tried creating a new test project in an empty folder /private/my-new-tmp2/buildtest-ios. Building it failed with the same error. So apparently something is weird with Cordova's iOS projects and the Ld linker in the /private directory on Mac OS X 10.9, and I'm the only person who's ever tried this. (As I said, building for Android works fine.)

In case someone else ever runs into the same problem, the solution is to build the project in /Users/me/some/directory rather than anywhere in /tmp or /private. Problem solved.

like image 159
jab Avatar answered Oct 28 '22 14:10

jab