Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 90045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:48:42+00:00 2026-05-10T22:48:42+00:00

Is it possible to have a C static library API, which uses C++ internally

  • 0

Is it possible to have a C static library API, which uses C++ internally and hide this from users of the library?

I have writen a portable C++ library I wish to statically link to an iPhone application.

I have created an Xcode project using the Max OS X ‘static library’ template, and copied the source across, as well as writing a C wapper (to deal with exceptions) using (extern ‘C’).

I am trying to use the generated library (.a file) in another Cocoa iPhone application.

Everything works well if the I use (.mm) extentions on the calling ObjectiveC file and (.cpp) on the implementation class in the library.

But I get unresolved symbols on linking when I try and change the wrapper file to a (.c) extention, even though all the wrapper function files are only C functions.

Just becuase C++ is used internally in a library, does it mean that externally it still must be treated as a C++ program. Is there not anyway to enforce this abstraction?

Edit: Thanks for the replies,

I had been using extern ‘C’, I was just unsure about what configurations where needed in the calling project. ie. if the calling projected would require to know if it used C++ or could be ignorant and think its a purely C library.

It would seem I cannot, and I must use (.mm) files on my ObjectiveC classes.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T22:48:43+00:00Added an answer on May 10, 2026 at 10:48 pm

    It’s too hard to do this in comments, so I’m just going to demonstrate for you quickly what the linking issues are that you’re having. When Xcode encounters files, it uses build rules based on the suffix to decide which compiler to use. By default, gcc links the files to the standard C library, but does not link with the standard C++ library. Archive files (static libraries) have no linking resolution done at all. They are basically an archive of object files which need to be linked. Since you have no .mm or .cpp files in your project, g++ is never called and your files are never linked to the standard libraries. To correct this, just add the standard C++ libraries to your other linker flags in your Xcode project, or just simply add them to the pre-defined other flags option as -l (e.g., -lstdc++).

    Here is a quick demonstration:

    stw.h:

    #ifdef __cplusplus extern 'C' #endif void show_the_world(void); 

    stw.cpp:

    #include <iostream> #include 'stw.h' using namespace std;  extern 'C' void show_the_world() {   cout << 'Hello, world!\n'; } 

    Build the library:

    $ g++ -c stw.cpp -o stw.cpp -O0 -g $ ar rcs stw.a stw.o 

    Using the library from a C application:

    myapp.c:

    #include 'stw.h'  int main() {   show_the_world();   return 0; } 

    Building the C application:

    $ gcc -o myapp myapp.c stw.a -lstdc++ -g -O0 $ ./myapp Hello, world! $ 

    If you try to compile without the -lstdc++ you will get all the unresolved issues because the C compiler has absolutely NO idea that it should link to the C++ runtime (and why would it, right!?!?) so you have to add this manually. The other option you have is to change the build rule for your project… instead of having Xcode use gcc to build .c and .m files, tell it to use g++ and your issues will be resolved.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 57k
  • Answers 57k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer The last two are identical; 'atomic' is the default behavior… May 11, 2026 at 8:28 am
  • added an answer Not as simply as you'd like, I'm sorry. One way… May 11, 2026 at 8:28 am
  • added an answer I did: sudo gem install mechanize and the following seems… May 11, 2026 at 8:28 am

Top Members

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Related Questions

Loading...

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.