how to use MacPorts libraries in an Xcode project using the Xcode GUI -- anyone?

Andrew Udvare audvare at gmail.com
Fri Jan 29 21:17:20 UTC 2021



> On 2021-01-29, at 12:40, Ken Cunningham <ken.cunningham.webuse at gmail.com> wrote:
> 
> I was working on an Xcode project in the Xcode GUI the other day (Apple's ld64-530) and needed various parts  that I know MacPorts supplies.
> 
> 
> But it is not simple or intuitive to know how to add headers and libraries from MacPorts to an Xcode project, I found.
> 
> 
> I did see how to add header search paths (that was not trivially easy to find, but could be found), but I had to add "/opt/local/include" which brought in everything from MacPorts, rather than just the bit I wanted. And then there are the libraries, and then the install_names will be all wrong.
> 
You should have /opt/local/include as one of the header search paths if you intend to link with a dylib that is in /opt/local/lib. But then you must also have the correct rpath in the binary too.
> 
> So, as I was working through this I thought -- in 20 years, this must have come up many times -- where is the wiki page on how to do this? And -- there must be many people out there who use Xcode all day long who know how to make this work smoothly much better than I do.
> 
> 
> Does anyone have the recipe for happy use of MacPorts headers and libraries in an Xcode GUI project?

You can add /opt/local/Library/Frameworks as one of the Framework search paths.

Not required but you should have /opt/local/lib as a library lookup path.

These last two are not required if you link only in the following way:

When you go to the project settings, you can click on 'Build Phases' and then under 'Link Binary With Libraries', click the + button and add frameworks from /opt/local/Library/Frameworks and dylibs from /opt/local/lib. In the dialog, on the bottom left, choose Add Other then Add Files. Then hit Command+Shift+G and type /opt/local. Browse to find the library (dylib)/framework you want to add.

The resulting binary should have commands similar to (otool -l):

Load command 36
          cmd LC_RPATH
      cmdsize 48
         path /opt/local/Library/Frameworks (offset 12)

For any directly linked framework:

Load command 33
          cmd LC_LOAD_DYLIB
      cmdsize 64
         name @rpath/Commandant.framework/Commandant (offset 24)
   time stamp 2 Wed Dec 31 19:00:02 1969
      current version 1.0.0
compatibility version 1.0.0

And possibly:

Load command 77
          cmd LC_RPATH
      cmdsize 32
         path /opt/local/lib (offset 12)

I've patched many projects to use frameworks from MacPorts, most recently mas: https://github.com/Tatsh/ports/tree/master/sysutils/mas

Andrew


More information about the macports-users mailing list