Am I trying to wrap a C++ project?

Hi all :wave:t2:
I'm trying to use the CLINGO answer set solver from Swift. CLINGO is written in C/C++ and this is already where my confusion begins. The project declares a clingo.h header, but all of its implementations files are .cc. Does this mean that the project is a C++ app, and can't be imported into Swift via SPM?

Thanks :upside_down_face:

So long as you only include clingo.h then this should be fine. SwiftPM can build C++, but Swift can't understand C++ code. clingo.h exposes a C-compatible header file, and so SwiftPM absolutely can understand that. You should be fine.


Could you give me any pointers for using Clingo with Swift? Iā€™m new to Swift and Iā€™m not getting anywhere following tutorials for importing other C libraries into a Swift program and trying to perform the analogous steps for Clingo.

1 Like

Looking at the repository and the conference papers on clingo, it's written in C++. Interfacing with C++ is more involved with than with C because C++ interoperability is still a moving, experimental feature of Swift that is rather incomplete. So, current practice seems to be to write a wrapper to your library that provides a compatible Swift interface (C, Objective-C) interface, and is able to call the C++ routines. Objective-C++ is probably the best option if you know the language since you write the interface section in Objective-C, and the implementations in Objective-C++. However, you can also build a wrapper from C if that is more suited to your knowledge base.

1 Like
Terms of Service

Privacy Policy

Cookie Policy