Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ Multiple Classes Cause Architecture Error
    text
    copied!<p>I am working on a project that requires me to use a variety of classes. For some reason, whenever I try compiling, I get an error that says:<br> <code>Undefined symbols for architecture x86_64:</code></p> <p>I originally was working on a class we can call <code>User</code> that had a declaration like this in <code>user.h</code>:</p> <pre><code>#ifndef USER_H #define USER_H ...other include statements class User { public: User(); public and private members and functions }; #endif </code></pre> <p>Definitions of the methods was housed in a separate file in the same directory, <code>user.cpp</code>.</p> <p>Whenever I would try to compile, I would get an error saying there were undefined symbols for the constructor and destructor. I had both of these defined in the <code>.cpp</code> file, but I couldn't get the error to go away.</p> <p>I include the User class in main with the following:</p> <pre><code>#include "user.h" </code></pre> <p>I managed to fix this by pasting all code from the <code>user.cpp</code> file into <code>user.h</code>, but now I am having issues with other classes whose code I am not allowed to modify.</p> <p>Right now, I have a class called GMLReader in <code>gmlreader.h</code> with a method I am calling statically. However, even though I am importing it for my main, I am getting the following error code whenever I try to call it:</p> <pre><code>Undefined symbols for architecture x86_64: "GMLReader::read(char const*, std::vector&lt;std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, std::allocator&lt;std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt; &gt;&amp;, std::vector&lt;std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt;, std::allocator&lt;std::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt; &gt; &gt; &gt;&amp;)", referenced from: _main in cchnzOEh.o ld: symbol(s) not found for architecture x86_64 collect2: ld returned 1 exit status </code></pre> <p>I am using the following to compile with <code>sn.cpp</code> housing my main:</p> <pre><code>g++ -g -Wall -o sn sn.cpp </code></pre> <p>Is there any reason an error like this would have occurred and how can I go about fixing it?</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