0

I'm trying to use some version of libpcre in a swift program for macOS, through Xcode 12.5. I can't seem to get the system to find the libraries I have tried.

Search on this topic on the web is maddening, because nothing really seems to be complete. I'd like to ask for 2 pathways:

Library which comes with Xcode/macOS

If I look at my target info panel in the project editor, I can add Frameworks and Libraries. I would like to add libpcre.

I hit the "+", scroll down and select libpcre.tbd. It dutifully adds an entry.

How do I now use this in a swift file, and see the various functions from the pcre library?

Library installed from Homebrew

Say I have decided that pcre version 1 isn't enough, and I need to add libpcre2. I use "brew install pcre2", which installs the files in /usr/local/Cellar/pcre2/10.36/ .

How do I now show Xcode how to find these libraries, and use them in my swift file?

The Test

In both cases, my basic test is that I ought to be able to type

let recode = pcre<ESC>

and have Xcode show me the various symbols from the included library.

Hack Saw
  • 2,741
  • 1
  • 18
  • 33
  • I suppose you need to create a bridging header file for it so that you can import the file to the project. – El Tomato May 21 '21 at 01:04
  • I suspect the system included file isn't a supported thing, and just an random inclusion from PHP. I've also learned that to include the pcre2.h library (in the bridging header), you first must define PCRE2_CODE_UNIT_WIDTH to 8, 16, or 32. I'd still love a canonical explanation of how to use a system library, and a homebrew library. – Hack Saw May 24 '21 at 22:02
  • Do you know the exact header file name you are trying to import to the project with libpcre.tbd? – El Tomato May 26 '21 at 07:11
  • No. In fact, I'm not sure there is one. It's not clear to me that Xcode tries to do the right thing here. It seems like I can pick that library, and it'll try to include it, but it's not clear at all that it'll make it actually available to the developer. This is why I'm hoping for an explanation from someone who knows the insides of Xcode really well. – Hack Saw May 26 '21 at 22:01
  • 1
    maybe this will help you: https://stackoverflow.com/a/63269154 http://rustyrazorblade.com/post/2008/external-libraries-in-xcode/ https://github.com/apple/swift-package-manager/blob/263171977ebcd47f4aaca1202cff5a96c5158a64/Documentation/Usage.md#import-system-libraries – DoTryCatch May 27 '21 at 13:05
  • 1
    or have a look how they did it: https://github.com/DimaRU/Shout.git – DoTryCatch May 27 '21 at 13:11

0 Answers0