{"id":3744,"date":"2014-03-30T05:08:00","date_gmt":"2014-03-30T05:08:00","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/wrapping-a-c-library-in-objective-c-is-not-hiding-the-c-symbols-collection-of-common-programming-errors\/"},"modified":"2014-03-30T05:08:00","modified_gmt":"2014-03-30T05:08:00","slug":"wrapping-a-c-library-in-objective-c-is-not-hiding-the-c-symbols-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/wrapping-a-c-library-in-objective-c-is-not-hiding-the-c-symbols-collection-of-common-programming-errors\/","title":{"rendered":"Wrapping a C++ library in Objective-C is not hiding the C++ symbols-Collection of common programming errors"},"content":{"rendered":"<p>I am trying to wrap a C++ library (for Sybase Ultralite) with Objective-C so that the library can be imported into MonoTouch. I have created an Objective-C library and included the compiled C++ library in this project, <em>libulrt.a<\/em>. To get my project to compile I set the path to the <em>User Header Search Path<\/em> to point to the directory where the C++ header files are located. I then had to set <em>compile source as<\/em> to <em>Objective-C++<\/em>.<\/p>\n<p>The problem now is that, although the wrapper library compiles correctly, once I include it in another Xcode project I have to <strong>again<\/strong> set <em>compile source as<\/em> to <em>Objective-C++<\/em> otherwise the project consuming my wrapper library gives linking errors. I don&#8217;t understand why this is, because the header file for my wrapper library contains only Objective-C code and not C++ code at all. C++ code is only found in the <em>implementation<\/em> (*.mm file) of the wrapper library. What do I need to do to make the C++ implementation completely transparent to the project consuming the wrapper library? In other words, I want to be able to include my wrapper library and compile with <em>compile source as<\/em> set to <em>Objective-C<\/em>. Anyone got any ideas how to do this?<\/p>\n<p>The linking errors that I am getting when compiling the project consuming my wrapper are as follows: (I have abridged the error listing because it is LONG!)<\/p>\n<pre><code>\"operator delete(void*)\", referenced from:\nzc3db40339fee::~zc3db40339fee()in libUltralite.a(ee39bf4763.o)\nzb4297ee7d543::~zb4297ee7d543()in libUltralite.a(747e80fdad.o)\nz33836a0a6f46::~z33836a0a6f46()in libUltralite.a(f240efda30.o)\n\"___cxa_pure_virtual\", referenced from:\nvtable for ze78b0ec59364in libUltralite.a(2c50e8e8ff.o)\nvtable for ze78b0ec59364in libUltralite.a(2c50e8e8ff.o)\nvtable for ze78b0ec59364in libUltralite.a(2c50e8e8ff.o)\n<\/code><\/pre>\n<p>The header file for my wrapper library is as follows:<\/p>\n<pre><code>#import \n\n@interface DataAccess : NSObject {}\n\n\/\/ Release objects.\n- (void)dealloc;\n\n\/\/ Singleton instance of the DataAccess class. \n+ (DataAccess*)sharedInstance; \n\n\/\/ Finalize the Database Manager when done with the DB.\n+ (void)fini;\n\n\/\/ Adds the given name to the database. \n- (void)addName:(NSString *)name;\n@end \n<\/code><\/pre>\n<p>Anyone have any idea how I can compile this as Objective-C++ but still have the projects consuming this library see it as Objective-C?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I am trying to wrap a C++ library (for Sybase Ultralite) with Objective-C so that the library can be imported into MonoTouch. I have created an Objective-C library and included the compiled C++ library in this project, libulrt.a. To get my project to compile I set the path to the User Header Search Path to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3744","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3744","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=3744"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3744\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=3744"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=3744"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=3744"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}