Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 542
  • Last Modified:

Porting a Windows C++ DLL to Mac OS X

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.

  • 3
  • 3
1 Solution
Tommy BraasCommented:
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?

pricciarAuthor Commented:
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.

Tommy BraasCommented:
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!
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

pricciarAuthor Commented:
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.

Tommy BraasCommented:
Did you select the Carbon framework project type in Project Builder?
pricciarAuthor Commented:
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.

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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now