How to use .a in swift with an empty header

I'm making a Swift Program.

I got a .a file that builded from some c++ scripts,and I can see some fuctions in it by commed "nm *.a", and a .h file like this

My question is how to call the fuctions in .a like "testDebug",I can call from c# like

[DllImport("__Internal")]
private static extern void testDebug();

Google's answer always with a right .h file,Maybe I should make .h file correct first.

Any reply would be greatly appreciated.

If you’re building an app you should be able to do this as follows:

  1. Add a bridging header to your app.

  2. Include the Objective-C header in your bridging header.

  3. Add the static library (.a) to your project.

  4. Add that to your Link Binary With Libraries build phase.

Looking at your screen shot it seems that you’ve already tried steps 1 and 2. The errors suggest that your bridging header isn’t being compiled as Objective-C. Make sure that C++ and Objective-C Interoperability build setting is set to its default value of objc.


Taking a step back, sharing code in this way is going to get very clunky very fast. For example, a single static library can’t support both the visionOS and visionOS simulator platforms. If you want to share pre-built libraries between teams, it’s best to use an XCFramework. See Creating a multiplatform binary framework bundle.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Thanks very much for your reply. It works very well on my testOClib scripts but not this project. I think my .a may not build for this way.I'll try build another one or another way. And I searched XCFramework,Looks like a good thing,Let me don't have to build into VisonPro every priview. Thanks very much again.

How to use .a in swift with an empty header
 
 
Q