62

I am having trouble getting MacPorts to function properly. I just installed OSX Lion 10.7.3 I downloaded and installed MacPorts first, and then after reading the requirements, I downloaded Xcode4.3 from the App Store, and then installed it. I launched Xcode and it looks to be operational and functional. However when I attempted to port with MacPorts, it gave me this error message(excerpt):

Warning: xcodebuild exists but failed to execute
Warning: Xcode does not appear to be installed; most ports will likely fail to build.

I followed the advice from:

How do i install additional packages for Xcode on OSX Lion to allow MacPorts to work

and installed command_line_tools_for_xcode from the Preferences within Xcode. I closed Xcode, and again got the errors:

$ sudo port install libsocketsPassword:
Warning: xcodebuild exists but failed to execute
Warning: Xcode does not appear to be installed; most ports will likely fail to build.
--->  Computing dependencies for libsockets
--->  Dependencies to be installed: openssl zlib
--->  Extracting zlib
Error: Couldn't determine your Xcode version (from '/usr/bin/xcodebuild -version').
Error: 
Error: If you have not installed Xcode, install it now; see:
Error: http://guide.macports.org/chunked/installing.xcode.html
Error: 
Error: Target org.macports.extract returned: unable to find Xcode
Error: Failed to install zlib
Log for zlib is at: /opt/local/var/macports/logs/_opt_local_var_macports_sources_rsync.macports.org_release_tarballs_ports_archivers_zlib/zlib/main.log
Error: The following dependencies were not installed: openssl zlib
Error: Status 1 encountered during processing.

I am uncertain where to go next with this. How do i trouble shoot my Xcode and MacPort interface?

Community
  • 1
  • 1
Jason
  • 1,307
  • 1
  • 12
  • 11

17 Answers17

85

In theory this should work if you have Xcode4.3 installed (in /Applications):

$ sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer/

(And you've installed the optional command line tools)

Dave
  • 12,408
  • 12
  • 64
  • 67
geowar
  • 4,397
  • 1
  • 28
  • 24
  • This also worked for me when updating Xcode from 4.2 to 4.3; I believe you only need to reinstall mac-ports if you do a major OS update – Mihai Damian Mar 13 '12 at 09:28
  • 1
    +1. Thank you!! The accepted/highest rated answer looked really painful! – Otto Mar 19 '12 at 21:52
  • Worked for me too: Xcode 4.3.2 on OSX 10.7.3 using MacPorts 2.0.4 – Dave Apr 02 '12 at 19:00
  • 1
    For reference, xcode-select is from Apple: http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man1/xcode-select.1.html – dkamins Apr 12 '12 at 03:15
  • Restarting your terminal after running this may help you. – crizCraig Apr 18 '12 at 15:59
  • This command is now part of the Macports warning: `Warning: You may need to run 'sudo xcode-select -switch /Applications/Xcode.app'` – Peter Ajtai Apr 30 '12 at 17:47
  • Great! Sometime it could be `sudo xcode-select -switch /Developer/Applications/Xcode.app/Contents/Developer/`. Just check where Xcode installed and change the command line appropriately – Rocco Jun 02 '12 at 04:23
18

Everything will start working fine after installation of "Command Line Tools for Xcode" package. You can get it from here: https://developer.apple.com/downloads/index.action#

  • Don't know why this was voted down... worked like a charm for me.. thanks Pavel – Juergen Riemer Apr 28 '12 at 06:58
  • My reinstall of macports would not run correctly until the command line tools were also downloaded via the preferences in xcode. This answer matches what I did to get macports working. – devNoise Apr 30 '12 at 16:01
  • Before trying any migration. I downloaded the "Command Line Tools..." and works perfectly. Mac OS Lion + xCode 4.3.3. No need to migrate – Ignacio Pascual Jul 18 '12 at 20:31
  • Vote this up! This worked for me, using XCode 4.4 and Mountain Lion – Benjamin Intal Aug 07 '12 at 06:47
  • This fixed a related problem for me. EPD ipython wouldn't run after I upgraded to XCode 4.6. Installing the command line tools (from the Xcode Gui) did the trick. – Mike Ellis Apr 06 '13 at 13:59
11

Please see the MacPorts migration instructions for Xcode 4.3.

The instructions are pretty involved. You need to run xcode-select to set a new tools path, update developer_dir in macports.conf (as described by Henk Poley), re-install MacPorts (ouch), and finally uninstall and re-install all of your ports (double ouch).

Edit: libpvx still wouldn't install after the above. Two extra steps were required:

  1. sudo ln -s /Developer /
  2. sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs /SDKs

YMMV if you have different ports installed!

Community
  • 1
  • 1
gmcnaughton
  • 2,233
  • 1
  • 21
  • 28
  • 2
    I was able to get this to work by ONLY adding the two soft links to my root directory (Developer and SDKs mentioned in the Edit). No macports migration necessary. – plainjimbo Feb 17 '12 at 20:20
  • This additional information helped out and it ended up working. I updated the config file using:`sudo nano /opt/local/etc/macports/macports.conf` . Thanks a lot, I am successfully using MacPorts now. – Jason Feb 17 '12 at 21:28
  • 2
    These instructions are more complex than what is needed. I simply ensured that `xcode-select` was pointing to the right path and that /opt/local/etc/macports.conf had `developer_dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain`. – ioquatix Feb 25 '12 at 03:28
10

Also in /opt/local/etc/macports/macports.conf change the line with developer_dir to point to / instead of /Developer.

Henk Poley
  • 729
  • 8
  • 17
  • 1
    Remember to uncomment the line as well! (It's commented out with a # by default) – gmcnaughton Feb 17 '12 at 18:37
  • I used: 'sudo nano /opt/local/etc/macports/macports.conf' to edit the config, and this still didn't do it, so I followed the additional advice of @gmcnaughton and it finally worked. Thanks for helping. – Jason Feb 17 '12 at 21:25
  • Worked for me wit XCode 4.6 – silentser Apr 29 '13 at 13:09
5

After

sudo xcode-select -switch /Applications/Xcode.app

I also had to run

sudo xcodebuild -license

and accept the licence

Greg Allen
  • 575
  • 5
  • 14
4

Here is a solution that has worked for me:

  1. Install Command Line Tools for Xcode

    Xcode -> Preferences -> Downloads
    
  2. Help MacPorts find the right Xcode folder

    sudo /usr/bin/xcode-select -switch /Applications/Xcode.app
    
  3. Create symbolic links for clang compilers as they now live elsewhere

    sudo ln -s `which clang` /Applications/Xcode.app/Contents/Developer/usr/bin/
    sudo ln -s `which clang++` /Applications/Xcode.app/Contents/Developer/usr/bin/
    
  • 1
    is sudo /usr/bin/xcode-select -switch /Applications/Xcode.app/Contents/Developer more appropriate? I'm successfully building macports this way now. – Matt Feb 24 '12 at 06:34
  • It appears that `Contents/Developer` gets automatically added. `xcode-select -print-path` shows `/Applications/Xcode.app/Contents/Developer` – Harish Narayanan Feb 24 '12 at 10:13
2
sudo mv /usr/bin/xcodebuild /usr/bin/xcodebuild.old
sudo ln -s /Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild /usr/bin/xcodebuild 
Juan Mellado
  • 14,973
  • 5
  • 47
  • 54
henryse
  • 21
  • 1
2

Try using trunk, there's no release supporting Xcode 4.3 yet.

2

Setting the developer path in /opt/local/etc/macports.conf works for me,

developer_dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain

since most of the compilers are stored there now instead of /usr/bin under Developer.

Pall Melsted
  • 358
  • 1
  • 12
2

None of this works for me. Wait for macports to release a new version that officially supports XCode 4.3+

1

I have macports installed without admin/root privileges, so I was unable to test the xcode-select answers. However, I observed that Pall Melsted's answer worked, but not initially. What I found out was that I had not accepted the Xcode 4.5 license agreement!

If you have just installed Xcode for the purposes of macports, and you haven't accepted the Xcode license yet, you might get the error presented by the original post. When I checked my Xcode version using /usr/bin/xcodebuild -version, I was given the prompt to read and accept the license. After doing so, and after having made the changes suggested by Pall to the macports.conf developer_dir, it all works now.

ronalchn
  • 12,225
  • 10
  • 51
  • 61
svohara
  • 2,159
  • 19
  • 17
1

Starting with Xcode 4.3, the command-line build tools are not installed by default. Launch Xcode, open the Preferences, and go to the Downloads tab. From there you should have an option to install the command-line tools.

You can also download them from the web here: https://developer.apple.com/downloads/index.action

Disclaimer: I haven't installed Xcode 4.3 yet. I have only read about it on the web.

rob mayoff
  • 375,296
  • 67
  • 796
  • 848
  • 1
    I installed the command line tools, as per [link](http://stackoverflow.com/questions/9323738/unable-to-get-macport-functionality-after-installing-xcode-4-3), it did not have an effect. – Jason Feb 17 '12 at 07:04
  • 2
    You could try running `xcode-select -switch /Applications/Xcode.app`. – rob mayoff Feb 17 '12 at 07:23
  • 1
    This works, but now clang is not where macports expects it to be, i.e. in usr/bin/clang – Pall Melsted Feb 17 '12 at 11:57
1

As of 27/2/2012, the official suggestion from MacPorts seems to be to not use XCode 4.3 and instead use 4.1 through 4.2.1, which can be downloaded from Apple.

There is a bug ticket which might be useful to follow the evolution of this.

Incidentally, and as reported in my comment #11 in that bug report, I am able to build ports without warnings by using the 2 most sane-looking suggestions found in this question: sudo /usr/bin/xcode-select -switch /Applications/Xcode.app/Contents/Developer and changing developer_dir in /opt/local/etc/macports/macports.conf to /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain

hmijail
  • 1,069
  • 9
  • 17
0

You should definitely run sudo xcode-select -switch /Applications/Xcode.app like everyone here says, that'll fix many problems, but certainly not all.

Afaik, all the remaining problems exist within the configuration information for various packages. You might simply reinstall MacPorts as described in the migration instructions, but I found another solution.


You should begin finding all effected port files using commands like grep /Developer/ ..., after executing sudo bash and cd /opt/local naturally.

You should identify all effected ports by using port provides ..., which I piped through sed and sort | uniq. You could simply reinstall all these ports using either port -n upgrade --force ... or separate port uninstall ... and port install ... commands.

I recommend using one large port -n upgrade --force ... command to avoid duplicate rebuilds of dependencies, using the separate uninstall and install commands afterwards.

There are of course various ports for which /Developer exists only inside text config files, meaning you can fix them manually with sed -i -e 's/\/Developer//g' ..., but you cannot do so with binaries obviously.

I'm afraid you must at minimum rebuild all your Python and Perl installations, making this upgrade an ideal time to clean out packages that depend upon older versions, ala python26 and perl5.8.

There are several technically effected ports I decided against rebuilding like fuse4x-kext, who contained /Developer inside Library/Extensions/fuse4x.kext/Contents/MacOS/fuse4x but hasn't prevented sshfs from working correctly.

Jeff Burdges
  • 4,204
  • 23
  • 46
0

I had initially installed xcode 3.2.2, after which I installed 4.3. When I ran the xcode-select, I still got the same error about no xcode project in /Applications. I then dug into the /usr/bin/xcodebuild script and found out that this was working correctly, and another instance of xcodebuild (the one installed with xcode 4.3, not the one in /usr/bin) was being run and returning the error:

xcodebuild: error: The directory /Applications does not contain an Xcode project.

It seems the /usr/bin/xcode-select does not work for xcode 4.3, (it's compiled so you can't really see why it's not working). Strings doesn't give any clues. Good thing osx has strace.. oh wait.

Anyways, the best I could do was modify /opt/local/etc/macports.conf and uncomment the line containing the path to the xcode installation. That seems to fix my problem for the most part.

siesta
  • 1,365
  • 2
  • 16
  • 21
0

As alternative: you can make downgrade of Xcode to 4.2.1 version. DMG of Xcode 4.2.1 placed here: https://developer.apple.com/downloads/index.action

After this MacPorts became works fine for me.

npub
  • 21
  • 2
0

This is fixed in MacPorts 2.0.4.

To upgrade:

  1. Download MacPorts 2.0.4 from the install site or run sudo port selfupdate.
  2. Run the MacPorts migration described here to reinstall all ports. This is painful but required to get back to a working state.
Adam
  • 164
  • 1
  • 4