Search code examples
c++quartz-2d

How to include an API


For a Program I'm writing in C++, I need some squares in different colors to be drawn in a window and than disappear again. (Or be overdrawn)

I'm using Xcode and I figured the easiest way to go is the Quartz 2D API, which seems to support exactly the graphics functionality I need.

But now I'm lost. How do I link the API in my source code?

All I learned in my lectures is that you can link a header file with something like #include "myHeader.h" to link the definition of self written classes, or #include <iostream> to include standard libraries.

I'd really appreciate a way to use this specific API, or better yet, a way to figure out how to link any given API.

EDIT: At this point the code looks still like this:

#include <iostream>
using namespace std;

int main()
{
    return 0;
}

And I'm still wondering what line of code comes after the first #include


Solution

  • You should find a README or other tutorial on how to use your API.

    In general, you have to provide a declaration of functions that you want to use from API. You can write it in your files or #include appropriate headers. Then you need to link to the object code of API functions, i.e. you can includes API libraries via IDE interface ( Linker->Libraries->Add library with API code). But API might be just a package of .h and .cpp files, so you are supposed to put this files into your project, include i.e. "api.h" and use utilities from API in your code directly, because program will link to object code created from API files included via this "api.h" file.

    Example with inclusion of compiled library:

    http://www.interactivebrokers.com/download/GettingStartedC++API.pdf

    Example with object code of API built in project:

    https://github.com/rudimeier/twsapi/blob/master/TestPosixSocketClient/PosixTestClient.h