Note that there are some explanatory texts on larger screens.

plurals
  1. PO"undefined reference to" linking on Ubuntu
    primarykey
    data
    text
    <p>I'm relatively new to C &amp; C++ and stuck at compiling (or should I say linking) for the whole 2 days. Anyone gives me an idea would be appreciated. Error message and 3 code files are below. These are what I cut down to minimum from I'm actually working on so that you guys can take a better glimpse at.</p> <p>Env: Ubuntu 10.10, Eclipse Indigo CDT, g++ (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5</p> <p>Error message:</p> <pre class="lang-none prettyprint-override"><code>**** Build of configuration Debug for project SceneRec2 **** make all Building file: ../src/AdaBoost.cpp Invoking: GCC C++ Compiler g++ -I"/home/ubuntuLove/Documents/workspace_eclipse/SceneRec2/Includes" -I/usr/src/linux-headers-2.6.35-30/arch/um/include/shared -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/AdaBoost.d" -MT"src/AdaBoost.d" -o "src/AdaBoost.o" "../src/AdaBoost.cpp" Finished building: ../src/AdaBoost.cpp Building file: ../src/AdaMain.cpp Invoking: GCC C++ Compiler g++ -I"/home/ubuntuLove/Documents/workspace_eclipse/SceneRec2/Includes" -I/usr/src/linux-headers-2.6.35-30/arch/um/include/shared -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/AdaMain.d" -MT"src/AdaMain.d" -o "src/AdaMain.o" "../src/AdaMain.cpp" ../src/AdaMain.cpp: In function ‘int main(int, char**)’: ../src/AdaMain.cpp:6: warning: deprecated conversion from string constant to ‘char*’ Finished building: ../src/AdaMain.cpp Building target: SceneRec2 Invoking: GCC C++ Linker g++ -o "SceneRec2" ./src/AdaBoost.o ./src/AdaMain.o ./src/AdaMain.o: In function `main': /home/ubuntuLove/Documents/workspace_eclipse/SceneRec2/Debug/../src/AdaMain.cpp:5: undefined reference to `AdaBoost&lt;double&gt;::AdaBoost()' /home/ubuntuLove/Documents/workspace_eclipse/SceneRec2/Debug/../src/AdaMain.cpp:6: undefined reference to `AdaBoost&lt;double&gt;::readFromFile(char*)' /home/ubuntuLove/Documents/workspace_eclipse/SceneRec2/Debug/../src/AdaMain.cpp:8: undefined reference to `AdaBoost&lt;double&gt;::~AdaBoost()' /home/ubuntuLove/Documents/workspace_eclipse/SceneRec2/Debug/../src/AdaMain.cpp:8: undefined reference to `AdaBoost&lt;double&gt;::~AdaBoost()' collect2: ld returned 1 exit status make: *** [SceneRec2] Error 1 **** Build Finished **** </code></pre> <p>Note-1. I receive the same result when I execute g++ on terminal.</p> <p>Note-2. The path of .o files in the argument for linker should be correct (./src/###.o).</p> <p>AdaBoost.h</p> <pre><code>#ifndef _ADABOOST_H #define _ADABOOST_H #include &lt;iostream&gt; const double eps = 2.2204e-16; template&lt;class T&gt; class AdaBoost { int N; //Number of Instances int D; //Number of Dimensions int nL; //Number of Learners / Classifiers / Rules T** fVectors; int* labels; void learnRule(int t, double* dist); double genRule(int t, int* L, double* dist); public: //Default Constructor AdaBoost(); //Constructor AdaBoost(T** data, int* labels, int n, int d, int nL); //Train function void train(); //Test function void test(double** data, double* pMap); void test(double** data, double* pMap, int n); int writeToFile(char* fName); int readFromFile(char* fName); //Destructor ~AdaBoost(); }; #endif </code></pre> <p>AdaBoost.cpp</p> <pre><code>#include "AdaBoost.h" #include &lt;fstream&gt; using namespace std; template class AdaBoost&lt;double&gt; ; template&lt;class T&gt; int AdaBoost&lt;T&gt;::readFromFile(char* fName) { ifstream inFile; int temp; int d, dir; float thr, wt; inFile.open(fName); if (!inFile) return 0; inFile &gt;&gt; temp; this-&gt;nL = temp; int k = 0; while (!inFile.eof() &amp;&amp; k &lt; nL) { inFile &gt;&gt; d; inFile &gt;&gt; thr; inFile &gt;&gt; dir; inFile &gt;&gt; wt; k++; } inFile.close(); return 1; } </code></pre> <p>AdaMain.cpp</p> <pre><code>#include "AdaBoost.h" using namespace std; int main(int argc, char** argv) { AdaBoost&lt;double&gt; rdClass; rdClass.readFromFile("Naerer"); return 0; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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