Note that there are some explanatory texts on larger screens.

plurals
  1. POError linking source file with static library C++
    text
    copied!<p>I'm trying to use the static library however when I add the reference and include directories to the project I get strange compiler errors, this including only any header file.</p> <p>The static library project builds successful. I don't know where the error may be, but I suppose it may be in some file of the static library.</p> <p>The static library files are the following:</p> <p>header:</p> <pre><code>#ifndef UTIL_H_ #define UTIL_H_ #include &lt;string&gt; #include &lt;iostream&gt; #include &lt;vector&gt; #include &lt;stdlib.h&gt; namespace Kaczmarz { class Util { public: Util(); static void split(std::vector&lt;std::string&gt; &amp;tokens, const std::string &amp;text, char sep); static double random(int rangeMin,int rangeMax); virtual ~Util(); }; } #endif </code></pre> <p>cpp:</p> <pre><code>#include "Util.h" namespace Kaczmarz { Util::Util() { // TODO Auto-generated constructor stub } void Util::split(std::vector&lt;std::string&gt; &amp;tokens, const std::string &amp;text, char sep) { unsigned int start = 0, end = 0; while ((end = text.find(sep, start)) != std::string::npos) { tokens.push_back(text.substr(start, end - start)); start = end + 1; } tokens.push_back(text.substr(start)); } double Util::random(int rangeMin,int rangeMax){ return (double) static_cast&lt;double&gt;( rand() ) * rangeMax / static_cast&lt;double&gt;( RAND_MAX ) + rangeMin; } Util::~Util() { // TODO Auto-generated destructor stub } } </code></pre> <p>the file that tries to use the static library:</p> <pre><code>#include &lt;iostream&gt; using namespace std; //using namespace Kaczmarz; int main(){ cout &lt;&lt; "Started.." &lt;&lt; endl; return 0; } </code></pre> <p>Note that I'm not calling yet any function from the library.</p> <p>The errors that I got are the following:</p> <pre><code>1&gt;c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(21): error C2143: syntax error : missing ';' before '&lt;' 1&gt;c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(21): error C2433: 'basic_string' : 'inline' not permitted on data declarations 1&gt;c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(21): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1&gt;c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(21): error C2988: unrecognizable template declaration/definition 1&gt;c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(21): error C2059: syntax error : '&lt;' 1&gt;c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(38): error C2143: syntax error : missing ';' before '{' 1&gt;c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(38): error C2447: '{' : missing function header (old-style formal list?) 1&gt;c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(49): error C2143: syntax error : missing ';' before '&lt;' 1&gt;c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(49): error C2433: 'basic_string' : 'inline' not permitted on data declarations 1&gt;c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(49): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1&gt;c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(49): error C2086: 'int std::basic_string' : redefinition 1&gt; c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(21) : see declaration of 'std::basic_string' 1&gt;c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(49): error C2988: unrecognizable template declaration/definition 1&gt;c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(49): error C2059: syntax error : '&lt;' 1&gt;c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(66): error C2143: syntax error : missing ';' before '{' 1&gt;c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(66): error C2447: '{' : missing function header (old-style formal list?) 1&gt;c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(77): error C2143: syntax error : missing ';' before '&lt;' 1&gt;c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(77): error C2433: 'basic_string' : 'inline' not permitted on data declarations 1&gt;c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(77): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1&gt;c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(77): error C2086: 'int std::basic_string' : redefinition 1&gt; c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(21) : see declaration of 'std::basic_string' 1&gt;c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(77): error C2988: unrecognizable template declaration/definition 1&gt;c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(77): error C2059: syntax error : '&lt;' 1&gt;c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(94): error C2143: syntax error : missing ';' before '{' 1&gt;c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(94): error C2447: '{' : missing function header (old-style formal list?) 1&gt;c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(101): error C2143: syntax error : missing ';' before '&lt;' 1&gt;c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(101): error C2433: 'basic_string' : 'inline' not permitted on data declarations 1&gt;c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(101): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1&gt;c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(101): error C2086: 'int std::basic_string' : redefinition 1&gt; c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(21) : see declaration of 'std::basic_string' 1&gt;c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(101): error C2988: unrecognizable template declaration/definition 1&gt;c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(101): error C2059: syntax error : '&lt;' 1&gt;c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(114): error C2143: syntax error : missing ';' before '{' 1&gt;c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(114): error C2447: '{' : missing function header (old-style formal list?) 1&gt;c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(125): error C2143: syntax error : missing ';' before '&lt;' 1&gt;c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(125): error C2433: 'basic_string' : 'inline' not permitted on data declarations 1&gt;c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(125): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1&gt;c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(125): error C2086: 'int std::basic_string' : redefinition 1&gt; c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(21) : see declaration of 'std::basic_string' 1&gt;c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(125): error C2988: unrecognizable template declaration/definition 1&gt;c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(125): error C2059: syntax error : '&lt;' 1&gt;c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(138): error C2143: syntax error : missing ';' before '{' 1&gt;c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(138): error C2447: '{' : missing function header (old-style formal list?) 1&gt;c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(145): error C2143: syntax error : missing ';' before '&lt;' 1&gt;c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(145): error C2433: 'basic_string' : 'inline' not permitted on data declarations 1&gt;c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(145): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1&gt;c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(145): error C2086: 'int std::basic_string' : redefinition 1&gt; c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(21) : see declaration of 'std::basic_string' 1&gt;c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(145): error C2988: unrecognizable template declaration/definition 1&gt;c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(145): error C2059: syntax error : '&lt;' 1&gt;c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(158): error C2143: syntax error : missing ';' before '{' 1&gt;c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(158): error C2447: '{' : missing function header (old-style formal list?) 1&gt;c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(166): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1&gt;c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(166): error C2143: syntax error : missing ',' before '&lt;' 1&gt;c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(170): error C2803: 'operator ==' must have at least one formal parameter of class type 1&gt;c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(170): error C2805: binary 'operator ==' has too few parameters 1&gt;c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(177): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1&gt;c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(177): error C2143: syntax error : missing ',' before '&lt;' 1&gt;c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(180): error C2803: 'operator ==' must have at least one formal parameter of class type 1&gt;c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(186): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int 1&gt;c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(186): error C2143: syntax error : missing ',' before '&lt;' 1&gt;c:\program files (x86)\microsoft visual studio 11.0\vc\include\string(190): fatal error C1903: unable to recover from previous error(s); stopping compilation </code></pre> <p>Note that the errors mention the std string class.</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