Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>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 <em>need to be linked</em>. 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++).</p> <p>Here is a quick demonstration:</p> <p>stw.h:</p> <pre><code>#ifdef __cplusplus extern "C" #endif void show_the_world(void); </code></pre> <p>stw.cpp:</p> <pre><code>#include &lt;iostream&gt; #include "stw.h" using namespace std; extern "C" void show_the_world() { cout &lt;&lt; "Hello, world!\n"; } </code></pre> <p>Build the library:</p> <pre><code>$ g++ -c stw.cpp -o stw.cpp -O0 -g $ ar rcs stw.a stw.o </code></pre> <p>Using the library from a C application:</p> <p>myapp.c:</p> <pre><code>#include "stw.h" int main() { show_the_world(); return 0; } </code></pre> <p>Building the C application:</p> <pre><code>$ gcc -o myapp myapp.c stw.a -lstdc++ -g -O0 $ ./myapp Hello, world! $ </code></pre> <p>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.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload