# Writing portable C library in SwiftPM question

**URL:** <https://forums.swift.org/t/writing-portable-c-library-in-swiftpm-question/67951>\
**Category:** Using Swift\
**Tags:** linux, swiftpm, corefoundation\
**Created:** [October 19, 2023, 2:16pm UTC](https://forums.swift.org/t/writing-portable-c-library-in-swiftpm-question/67951 "2023-10-19T14:16:40Z")\
**Posts on this page:** 1\
**Showing post:** 16

<div class="post-metadata">

**Author:** ![Kyle-Ye](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/kyle-ye/32/19686_2.png) [@Kyle-Ye](https://forums.swift.org/u/Kyle-Ye)\
**Post date:** [October 20, 2023, 3:19am UTC](https://forums.swift.org/t/writing-portable-c-library-in-swiftpm-question/67951/16 "2023-10-20T03:19:56Z")

</div>

Max is suggesting we should not reply on old thread. So I'll reply your post on this thread.

> [Formalizing the unavailability of Core Foundation - #13 by compnerd](https://forums.swift.org/t/formalizing-the-unavailability-of-core-foundation/40216/13)

Yes. So I just create a [CoreFoundation fork](https://github.com/Kyle-Ye/OpenFoundation) and try to maintain a cross-platform solution myself.

After all, what I need is just the handy macros of CF not the implementations of the .c file.

```swift
#if !defined(CF_EXTERN_C_BEGIN)
#if defined(__cplusplus)
#define CF_EXTERN_C_BEGIN extern "C" {
#define CF_EXTERN_C_END }
#else
#define CF_EXTERN_C_BEGIN
#define CF_EXTERN_C_END
#endif
#endif

#if TARGET_OS_WIN32
    #if defined(__cplusplus)
        #define _CF_EXTERN extern "C"
    #else
        #define _CF_EXTERN extern
    #endif

    #if defined(_WINDLL)
        #if defined(CoreFoundation_EXPORTS) || defined(CF_BUILDING_CF)
            #define CF_EXPORT _CF_EXTERN __declspec(dllexport)
        #else
            #define CF_EXPORT _CF_EXTERN __declspec(dllimport)
        #endif
    #else
        #define CF_EXPORT _CF_EXTERN
    #endif
#else
#define CF_EXPORT extern
#endif

```

cc @compnerd

---

_[View the full topic](https://forums.swift.org/t/writing-portable-c-library-in-swiftpm-question/67951)._
