Porting a Windows C++ DLL to Mac OS X

Posted on 2003-03-10
Medium Priority
Last Modified: 2013-12-26
I have C++ code that I used to write a DLL on Windows 2000. I want to create a comparable library on Mac OS X.

What is the best way to go about this? Frameworks seem to be the way to write a shared library for the Mac. But, I cannot figure out how to export my classes when using a framework.

Can you write a Framework in C++ supporting all of your classes and functions?

If not. What is the best way to write a library on OS X.

Thanks for your help.

Question by:pricciar
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
LVL 14

Expert Comment

by:Tommy Braas
ID: 8116058
There are several different options for creating libraries for Mac OS X. Frameworks, loadable bundles, and ".so" are all valid delivery methods of libraries.

You need to answer a few questions before I can give you a recommendation:

What is the intended use of the library?
Who are the users of the library?
How will these users access the library?


Author Comment

ID: 8116551
Hi orangehead. Thanks for replying.
The major problem I was having when I asked the question I solved today.
I could not export my classes using the Project Builder that Apple supplies with their developer package. When I tried to build a framework with that the classnames would be mangled, and I couldn't call them from an application.

When I make a framework with Codewarrior, I do not have that problem.

But, to answer your questions.

1) The library goes out as part of an SDK. It gives other programmers access to functions that we have written, without giving them the actual code.

2) The users of the library are programmers who acquire the SDK.

3) Doesn't that depend on the library? I don't think I understand this question. I am sorry.

From what I can grasp I have four choices
static library
shared library
loadable bundle

What is a .so? What is the difference between a loadable bundle and a framework?

I am leaning towards a framework, because it seems to be the standard way libraries are handled in OS X.

Any comments you might have would be appreciated. While the problem I am facing isn't as vexing or urgent. It would be nice to have a clearer understanding of the different kinds of libraries available to me.

LVL 14

Accepted Solution

Tommy Braas earned 2000 total points
ID: 8122126
What I meant by question number 3, is if the users will load the library and "discover" it, or if they will link to it. I gues they will be linking to it! :-)

A loadable nudle is like a plug-in.

A ".so" is a shared library the Unix way.

I think your best bet is to go with a framework. There is some good documentation installed with the developer tools from Apple regarding how to build libraries. Usually what kills the beginner is that they forget to include the headers reauired to link to the framework. I think that might have been your problem. You need to check which headers should be public by doing the following:

1. Select "Edit Active Target..." from the Project menu
2. Expand "Build Phases", if collapsed
3. Select "Headers"
4. Check the "Public" check boxes next to headers you want to expose

Don't forget that the rest of the headers will not be available to the users of your framework. That means that any non-exported headers that are referenced in the published headers, won't be available. Make sure you import those headers from your implementation files, so that they get compiled into the resulting framework.

Also, don't forget that when creating a framework, that you need to add a path element to the header file name when importing/including! Well, it'll work for you as the designer not to include the path, but for anyone else, it won't. I am sure you've seen it in action (#include <Carbon/Carbon.h). E.g.

   #include <myheader.h>


   #include <myframework/myheader.h>

Here's a link to Apple's dev tools web site:


Let me know if you need more help!
Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!


Author Comment

ID: 8122818
Thanks. yes. Framework is the direction I have decided to take.

But, a further question if it doesnt' take up too much of your time.

While figuring out how frameworks worked and how to write them, I used the example Framework that came with the Developer tools. And, that worked just fine.

Following that example, I tried to make my own test framework. The only difference was, I was using the C++ compiler and classes.

I couldn't access the functions at all. I couldn't access the class. Everything was exactly the same, aside from C++.
Is there anything I should do in the Project Builder to make it work with C++?

Like I said earlier. This was not a big deal, because I switched over to Codewarrior, and that created a framework with classes without a problem. It's just one of those things, you know? I wonder what I was doing wrong.

Thanks for your help. I appreciate it.

LVL 14

Expert Comment

by:Tommy Braas
ID: 8124686
Did you select the Carbon framework project type in Project Builder?

Author Comment

ID: 8134084
Yes. I selected Carbon framework project type.

Was that incorrect? Is there another type of project I should use?

I thought i had this problem solved with Codewarrior. But, alas, no. I can build the framework. Then add it to an application, and it links and builds just fine. Just the application doesn't run when I try to run it. Very odd.

You wouldn't know of any project samples. For either Apple Project Builder, or Codewarrior that show how a framework can be built using C++ would you?

Thanks for all of your help. I am sorry I am taking up so much of your time.


Expert Comment

ID: 8808758
Go to http://developer.apple.com for tons of example programs.

Featured Post

Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question