1

In fact I want to port my wxWidgets-based application over to Mac using OS X 10.8 and Xcode 5. My application at this point will consist of the main executable and couple of dylib's.

So, after opening the XCode and going to the "File->New", I see there are "Project" and "Workspace" submenus.

I'm at a loss to:

  • presume I need to create a workspace, and then in there create 1 project for the main executable and 1 project for each dylib library.
  • forget about the "Workspace" and just start with the project for my main binary and then continue with another project on the same level for the library

Could someone shed some experience please?

5
  • I'm tempted to migrate this to SO as we don't really entertain code level questions here. Before I do that - is there a reason why you asked here as opposed to SO? We allow some basic - Xcode errors or how do I download the app, but this seems more like how to style your setup as opposed to the mechanics of getting the app to run or to understand the developer program service.
    – bmike
    Commented Mar 18, 2016 at 23:19
  • @bmike, SO is for the programming questions only. This one is more for a project design in the un-familiar environment. I do have a lot of experience with MSVC, where the workspace is created along with the first project, but I'm not sure the same paradigm applies to XCode
    – Igor
    Commented Mar 18, 2016 at 23:29
  • @bmike, Like I said the structure of the project is "main application + dylib's". And it is more an XCode question than the programming one.
    – Igor
    Commented Mar 18, 2016 at 23:31
  • @bmike, From the quick look at developer.apple.com/library/ios/featuredarticles/XcodeConcepts/… it definitely looks like I need a workspace first and then keep adding the libraries project in it. Can you confirm?
    – Igor
    Commented Mar 19, 2016 at 0:51
  • There are many tutorials on Xcode I thunk this is too broad to be answered here
    – mmmmmm
    Commented Mar 19, 2016 at 8:13

1 Answer 1

2

This is an example of where a simple C++ command line application and dynamic library are created. The version of Xcode is 7.2.1 which requires at least OS X 10.10.5 execute, but can generate applications that only require OS X 10.7 or newer.

Part I: Create the Workspace, Projects and Source Code Files.

  1. Using the Finder application, create a folder. In this case, I created the folder named "simple" in my "Documents" folder.
  2. Launch the Xcode application. If the "Welcome to Xcode" window pops up, close the window. From the menu bar, select the File->New->Workspace... item. I used the name "simplews.wcworkspace", which I selected to place in the "simple" folder.
  3. From the menu bar, select the File->New->Project... item. Select "OS X Application", then "Command Line Tool". Click the "Next" button.
  4. For "Product Name:" and "Language:", I used "simple" and "C++", respectively. Click the "Next" button.
  5. Under "Add to:" select "simplews". Click the "Create" button.
  6. From the menu bar, select the File->New->Project... item. Select "Framework & Library", then "Library". Click the "Next" button.
  7. For "Product Name:", "Framework:" and "Type:", I used "simplelib", "None (Plain C/C++ library)" and "Dynamic", respectively. Click the "Next" button.

    Note: I choose a dynamic library. If you need a static library, substitute "Static" for "Dynamic". You can also change this after creating the project. (Look for "Mach-O Type" under "Build Settings".)

  8. Under "Add to:" select "simplews". Under "Group:" and "simplews". Click the "Create" button.
  9. From the menu bar, select the File->New->Group item. On the created folder, replace the name "New Group" with "simplelib".
  10. Highlight the "simplelib" folder. From the menu bar, select the File->New->File... item. Select "OS X Source", then "C++ File". Click the "Next" button.
  11. For "Name:" use "simplelib.cpp". Make sure the "Also create a header file" is not checked off. Click the "Next" button.
  12. Verify the "Group" is the "simplelib" folder and under "Targets", "simplelib" is checked off. Click the "Create" button.
  13. Highlight the "simplelib" folder. From the menu bar, select the File->New->File... item. Select "OS X Source", then "Header File". Click the "Next" button.
  14. For "Save As:", use "simplelib.h". Under "Group" select the folder "simplelib". Under "Targets", make sure "simplelib" is checked off. Click the "Create" button.

Part II: Configure Project Dependences

  1. Project "simple" has to be able to find the headers from project "simplelib". Highlight project "simple", then "Build Settings". Change "Header Search Paths" to "../simplelib". An illustration is shown below.

    Hint: Click on the image or open in a new window for a better view.

    700

  2. Project "simple" has to be able to link to the library created by project "simplelib". Highlight project "simple", then "Build Phases". Under "Link Binary With Libraries" click on the + sign and add "libsimplelib.dylib. An illustration is shown below.

    701

  3. Remove the library search paths added by step 2. Highlight project "simple", then "Build Settings". Under "Library Search Paths", delete paths "$(inherited)" and "$(PROJECT_DIR)lib/build/Debug". An illustration before the deletions is shown below.

    702

    When finished, "Library Search Paths" should show no paths as shown in the image included in step 1.

Note: The dependency of project "simple" on project "simplelib" should be detected automatically. Therefore, the step to include one has been omitted.

Part III: Build and Run the Application

Ask Different is not about programming. However, I will include the code that I entered.

simplelib.h

#ifndef simplelib_h
#define simplelib_h

class sample
{
public:
    static void print();
};

#endif /* simplelib_h */

simplelib.cpp

#include <iostream>
#include "simplelib.h"

void sample::print()
{
    std::cout << "Hi from simplelib!\n";
}

main.cpp

#include <iostream>
#include "simplelib.h"

int main(int argc, const char * argv[])
{
    std::cout << "Hello, World!\n";
    sample::print();
    return 0;
}
  1. To build the application first select Product->Scheme->Simple from the menu bar. The sets the focus on application project "Simple".

    Note: The check mark does not always move after making a selection. This has been a bug for quite some time.

  2. Next, select Product->Build from the menu bar.
  3. Finally, select Product->Run from the menu bar. The output is shown in the image below.

704

1
  • 2 questions: First - I have XCode 5.1.1 under OSX 10.8. Which one do you have? 2. My project contains static library as well which statically link to one of the dylib. Could you give an example of this scenario as well? Thank you.
    – Igor
    Commented Mar 19, 2016 at 4:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .