0

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

Mahonri Moriancumer
  • 5,993
  • 2
  • 18
  • 28
ColdBrew
  • 95
  • 1
  • 7
  • Do you have the code from Xcode? Did you compile it already? – Svalorzen May 20 '14 at 21:01
  • 1
    Header files contain declarations, or *how to use the function*. Libraries contain the **content** of the function. You will have to *link* libraries with your main code. – Thomas Matthews May 20 '14 at 21:01
  • @Thomas: well, how do I find out which libraries I have to link in order to use the mentioned API? – ColdBrew May 20 '14 at 21:17
  • 1
    That should be in the library's documentation. There's no one-to-one match between headers and libraries. – Fred Foo May 20 '14 at 21:21

2 Answers2

1

Thank you bits_internationl! This worked. In the case of the Quartz 2D API, the line #include <CoreGraphics/CoreGraphics.h>

For future visitors the following resources might be useful.

Description of different Frameworks (Post from Jano): What's the difference between Quartz Core, Core Graphics and Quartz 2D?

How to include Frameworks in Xcode, and standard frameworks directory: https://developer.apple.com/library/mac/documentation/macosx/conceptual/BPFrameworks/Tasks/IncludingFrameworks.html

Community
  • 1
  • 1
ColdBrew
  • 95
  • 1
  • 7
0

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

4pie0
  • 29,204
  • 9
  • 82
  • 118