title: Not sure how to export Objective-C classes. Undefined symbols for architecture i386
body: <p>I'm trying to do some work on GTK+ on OSX and I'm having a little trouble because, to be honest, I'm not all that familiar with Objective-C. I have enough programming experience that I quickly got up to speed on the basic syntax, and I can look up what I need in documentation. But the problems I'm having are related to linking the library and exposing the classes to the program I'm linking to.</p>
  
  <p>GTK+ is a C library, but the OSX backend includes a couple Objective-C classes. They're not exposed as public API, they're only used internally; but for something I'm working on I'd like to try to expose these classes publicly.</p>
  
  <p>For reference, here is one of the classes:</p>
  
  <p><a href="https://github.com/GNOME/gtk/blob/gtk-2-24/gdk/quartz/GdkQuartzWindow.h" rel="nofollow">https://github.com/GNOME/gtk/blob/gtk-2-24/gdk/quartz/GdkQuartzWindow.h</a>
    <a href="https://github.com/GNOME/gtk/blob/gtk-2-24/gdk/quartz/GdkQuartzWindow.c" rel="nofollow">https://github.com/GNOME/gtk/blob/gtk-2-24/gdk/quartz/GdkQuartzWindow.c</a></p>
  
  <p>I've changed the build system so that it installs the header files. I have another source file (outside the gtk+ build system) that does something like:</p>
  
  <pre><code>GdkQuartzWindow *win = [[GdkQuartzWindow alloc] /* other messages... */ ];
  </code></pre>
  
  <p>When I try to compile I get a linker error:</p>
  
  <pre><code>Undefined symbols for architecture i386:
    ".objc_class_name_GdkQuartzWindow", referenced from:
    pointer-to-literal-objc-class-name in main-a8d029.o
  ld: symbol(s) not found for architecture i386
  clang: error: linker command failed with exit code 1 (use -v to see invocation)
  </code></pre>
  
  <p>I'm not very familiar with how Objective-C compiler/linker works and having trouble understanding how I can (or if I can) solve this.</p>
  
  <p>When I run <code>nm libgdk-quartz-2.0.dylib  | grep GdkQuartzWindow</code> I see a lot of messages on this class:</p>
  
  <pre><code>00057120 t -[GdkQuartzWindow beginManualMove]
  000575c0 t -[GdkQuartzWindow beginManualResize]
  00056c50 t -[GdkQuartzWindow canBecomeKeyWindow]
  ... (many more) ...
  000b2030 s .objc_class_name_GdkQuartzWindow
  </code></pre>
  
  <p>At the bottom of that list, you see the thing that the linker is complaining doesn't exist. But if I use <code>nm -g</code> instead of <code>nm</code> then nothing is shown, so something is not being exported correctly.</p>
  
  <p>For normal C symbols, the build process builds an alias file that includes </p>
  
  <p><a href="https://developer.apple.com/library/mac/documentation/DeveloperTools/Conceptual/CppRuntimeEnv/Articles/SymbolVisibility.html" rel="nofollow">Apple's docs</a> give me the impression that this shouldn't be a problem when my target is i386 (which it currently is). They say:</p>
  
  <blockquote>
    <p>In a 32-bit OS X project, these visibility controls apply only to the C or C++ subset of your code. They do not apply to Objective-C classes and methods. Objective-C class and message names are bound by the Objective-C runtime, not by the linker, so the notion of visibility does not apply to them. There is no mechanism for hiding an Objective-C class or method defined in a dynamic library from the clients of that library.</p>
  </blockquote>
  
  <p>But, I am receiving an error saying I have undefined symbols, so my error seems to contradict this. If I change this line so that it's allocating an <code>NSWindow</code> instead, everything works fine; so it's importing the AppKit stuff correctly. It just seems that I'm doing something wrong with trying to expose the classes and their methods.</p>
  
  <p>Any chance someone can point me in the right direction?</p>