2 Replies
      Latest reply on Aug 16, 2019 11:35 AM by k0taperk0t
      k0taperk0t Level 1 Level 1 (0 points)



        I'm really newbie in Apple world. I have big project on C++ and need to port them from Linux on MacOs.

        Please explain me what name of API in macOs SDK is for C/C++ programming?

        I know Classic API and Carbon API, they are not supported. As I know modern API is Cocoa. So, Cocoa supports C/C++, or only Obj-C/C++ and Swift?


        I tried to find documentation for syscalls for macOs, but I found only Archive, like here (last updated in 2002). Does somewhere exist comfortable, modern and actual documentation (with search and etc)?


        Headers in /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include - to which API do they belong? Is it still supported, not deprecated? How long it will be supported?


        Maybe you can recommend me some books or articles for system programming C/C++ on MacOs? I found books such as "Mac OS X Internals: A Systems Approach" - it is 13 years old

        • Re: Which API is intended for C/C++ programming?
          Ken Thomases Level 4 Level 4 (765 points)

          Cocoa, which is a high-level framework targeted at GUI app development, does require either Objective-C/C++ or Swift.  (There are third-party bindings to other languages, like Xamarin/C##.)


          There are a number of C-based high-level frameworks, such as Core Foundation, Core Graphics (a.k.a. Quartz), etc.


          The high-level frameworks are documented online and in Xcode's documentation viewer.  (Although I feel that Apple's documentation has been getting steadily worse over the years.)  Sometimes, the nitty-gritty details are only documented in the respective header files.


          For system programming, macOS is Unix.  There are the standard C library, the standard C++ library, and the POSIX/BSD library and syscalls.  The headers in …/usr/include are and will remain supported, in general; specific (old) functions may be marked as deprecated.  The compiler should warn you about those.  The POSIX/BSD APIs are documented in the man pages installed with the developer tools.  Just "man <function>" at the command line will get you the up-to-date docs.  I don't know if that counts as "comfortable, modern and actual".


          Older documentation can become a bit out of date, but is still usually fundamentally correct.


          If you want more specifics, you'll have to explain specifically what you're trying to achieve and can't figure out how to do.

            • Re: Which API is intended for C/C++ programming?
              k0taperk0t Level 1 Level 1 (0 points)



              Yes, macOS is Unix, and POSIX-compatible, but unfortunately is not fully.

              Some system calls are missed in macOS or exist, but makes SEGV.

              For example, semaphores - in documentation we could find system call sem_open (sem_init doesn't exist), but we get SEGV (or it just will not work - I don't remember) if we will try to use it in our program. Why? Because we should use dispatch_semaphore_create. But see again manpage for sem_open - nothing is said there about it. Thanks God we have StackOverflow. Official documentation for dispatch_semaphore_create is only for Obj-C/Swift, but fortunately this syscall is also available for C.


              When I wrote about comfortable documentation with search, I meant something like this. But it is not official documentation. As I understand something similar, but official doesn't exist =( Okaay. Just macOS is not Open-Source project and therefore I think this situation is a little bit strange.


              I just searched any "official documentation", but as I understand, official documentation is manpages =) Okey, now I know

              And also I'm confused in Apple API's. Now it is more clear

              Thanks again