How do i use a bunch of .h and .cpp files to create a static library that can be used in another c++ Project

389 views Asked by At

I am trying to learn C++ from some Stanford Course and they have a custom library which contains a bunch of header files(.h) and their associated source (.cpp) files.

I want to create new C++ projects in xcode 6.x to try out code and include those custom header files in my new projects.

I have no freaking idea how to include those files in my project so that i can peacefully #include "blahblahblah.h" and use functions from that header file without issues.

I am new to both xcode, c++(although i know some coding part) and anything else with this process.

Summary:

  1. I have a folder Library which contains a series of .h and .cpp files.
  2. I have XCode 6.x.x/Eclipse installed.
  3. I want to create a new C++ project and use #include "OneOfThoseHeaderFiles.h" and then use a function or something from those header files.

Also assume i have no clue how to run some command line codes that i see a lot of.

If someone can please tell me in the most simple way(preferably step-by-step) i would be so eternally grateful and sing praises to you until the day i die :)

Note: Either XCode or Eclipse is fine. I really just want to start coding.

I have spent the better part of a whole week trying out xcode, eclipse etc and trying to follow a ton of steps to get it working but i just cant get how to add the files without issues. Either the info seems to be for Xcode 4.x and every menu seems changed or the suggestions are so complicated that a novice like me cant figure it out.

1

There are 1 answers

0
exs On

First off, almost all the information for Xcode will be available on the Apple Developer's portal: https://developer.apple.com/library/prerelease/ios/documentation/ToolsLanguages/Conceptual/Xcode_Overview/start_project.html#//apple_ref/doc/uid/TP40010215-CH2-SW5

To create a simple static library on Xcode 6 you start by creating a new project, then under OS X - Framework and Library select Library, on the next window change the Framework to None (Plain C/C++ Library) and static (since that is what your are stating).

Once your project is created, add the existing headers and sources to your project, either by dragging them with the mouse or with the add files drop menu from the right click functionality, you can create a new group in Xcode if you want some order for them.

When adding the files, on the add window shown you can select to either copy them or use their current location.

If needed you might have to change the "header search path" in your target configuration under "Build Settings", if it is the first time you are using Xcode some of this will sound weird but I am sure you will find most of it on the Apple Developers portal in great detail.

If you want to test the files without having to create an external static library you could create a command line project and test them faster and easier.