I'm getting an undefined references linker error only when linking optimized objects files, not when linking unoptimized object files. I don't understand what the problem is or could be.
Here is my unoptimized build:
Building file: ../COMPASS.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -pg -Wall -c -fmessage-length=0 -Wno-sign-compare -fopenmp -MMD -MP -MF"COMPASS.d" -MT"COMPASS.d" -o"COMPASS.o" "../COMPASS.cpp"
Finished building: ../COMPASS.cpp
Building file: ../PSA.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -pg -Wall -c -fmessage-length=0 -Wno-sign-compare -fopenmp -MMD -MP -MF"PSA.d" -MT"PSA.d" -o"PSA.o" "../PSA.cpp"
Finished building: ../PSA.cpp
Building file: ../SAR.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -pg -Wall -c -fmessage-length=0 -Wno-sign-compare -fopenmp -MMD -MP -MF"SAR.d" -MT"SAR.d" -o"SAR.o" "../SAR.cpp"
Finished building: ../SAR.cpp
Building file: ../constraints.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -pg -Wall -c -fmessage-length=0 -Wno-sign-compare -fopenmp -MMD -MP -MF"constraints.d" -MT"constraints.d" -o"constraints.o" "../constraints.cpp"
Finished building: ../constraints.cpp
Building file: ../genetic.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -pg -Wall -c -fmessage-length=0 -Wno-sign-compare -fopenmp -MMD -MP -MF"genetic.d" -MT"genetic.d" -o"genetic.o" "../genetic.cpp"
Finished building: ../genetic.cpp
Building file: ../globals.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -pg -Wall -c -fmessage-length=0 -Wno-sign-compare -fopenmp -MMD -MP -MF"globals.d" -MT"globals.d" -o"globals.o" "../globals.cpp"
Finished building: ../globals.cpp
Building file: ../logging.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -pg -Wall -c -fmessage-length=0 -Wno-sign-compare -fopenmp -MMD -MP -MF"logging.d" -MT"logging.d" -o"logging.o" "../logging.cpp"
Finished building: ../logging.cpp
Building file: ../main.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -pg -Wall -c -fmessage-length=0 -Wno-sign-compare -fopenmp -MMD -MP -MF"main.d" -MT"main.d" -o"main.o" "../main.cpp"
Finished building: ../main.cpp
Building file: ../sampling.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -pg -Wall -c -fmessage-length=0 -Wno-sign-compare -fopenmp -MMD -MP -MF"sampling.d" -MT"sampling.d" -o"sampling.o" "../sampling.cpp"
Finished building: ../sampling.cpp
Building file: ../simulation1.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -pg -Wall -c -fmessage-length=0 -Wno-sign-compare -fopenmp -MMD -MP -MF"simulation1.d" -MT"simulation1.d" -o"simulation1.o" "../simulation1.cpp"
../globals.h: At global scope:
../globals.h:43: warning: inline function 'double showDecimals(const double&, const int&)' used but never defined
Finished building: ../simulation1.cpp
Building file: ../test_function.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -pg -Wall -c -fmessage-length=0 -Wno-sign-compare -fopenmp -MMD -MP -MF"test_function.d" -MT"test_function.d" -o"test_function.o" "../test_function.cpp"
Finished building: ../test_function.cpp
Building target: pc2
Invoking: GCC C++ Linker
g++ -pg -fopenmp -pg -o"pc2" ./COMPASS.o ./PSA.o ./SAR.o ./constraints.o ./genetic.o ./globals.o ./logging.o ./main.o ./sampling.o ./simulation1.o ./test_function.o
Finished building target: pc2
Here is my optimized build:
Building file: ../COMPASS.cpp
Invoking: GCC C++ Compiler
g++ -O3 -Wall -c -fmessage-length=0 -Wno-sign-compare -fopenmp -MMD -MP -MF"COMPASS.d" -MT"COMPASS.d" -o"COMPASS.o" "../COMPASS.cpp"
Finished building: ../COMPASS.cpp
Building file: ../PSA.cpp
Invoking: GCC C++ Compiler
g++ -O3 -Wall -c -fmessage-length=0 -Wno-sign-compare -fopenmp -MMD -MP -MF"PSA.d" -MT"PSA.d" -o"PSA.o" "../PSA.cpp"
Finished building: ../PSA.cpp
Building file: ../SAR.cpp
Invoking: GCC C++ Compiler
g++ -O3 -Wall -c -fmessage-length=0 -Wno-sign-compare -fopenmp -MMD -MP -MF"SAR.d" -MT"SAR.d" -o"SAR.o" "../SAR.cpp"
Finished building: ../SAR.cpp
Building file: ../constraints.cpp
Invoking: GCC C++ Compiler
g++ -O3 -Wall -c -fmessage-length=0 -Wno-sign-compare -fopenmp -MMD -MP -MF"constraints.d" -MT"constraints.d" -o"constraints.o" "../constraints.cpp"
Finished building: ../constraints.cpp
Building file: ../genetic.cpp
Invoking: GCC C++ Compiler
g++ -O3 -Wall -c -fmessage-length=0 -Wno-sign-compare -fopenmp -MMD -MP -MF"genetic.d" -MT"genetic.d" -o"genetic.o" "../genetic.cpp"
Finished building: ../genetic.cpp
Building file: ../globals.cpp
Invoking: GCC C++ Compiler
g++ -O3 -Wall -c -fmessage-length=0 -Wno-sign-compare -fopenmp -MMD -MP -MF"globals.d" -MT"globals.d" -o"globals.o" "../globals.cpp"
Finished building: ../globals.cpp
Building file: ../logging.cpp
Invoking: GCC C++ Compiler
g++ -O3 -Wall -c -fmessage-length=0 -Wno-sign-compare -fopenmp -MMD -MP -MF"logging.d" -MT"logging.d" -o"logging.o" "../logging.cpp"
Finished building: ../logging.cpp
Building file: ../main.cpp
Invoking: GCC C++ Compiler
g++ -O3 -Wall -c -fmessage-length=0 -Wno-sign-compare -fopenmp -MMD -MP -MF"main.d" -MT"main.d" -o"main.o" "../main.cpp"
Finished building: ../main.cpp
Building file: ../sampling.cpp
Invoking: GCC C++ Compiler
g++ -O3 -Wall -c -fmessage-length=0 -Wno-sign-compare -fopenmp -MMD -MP -MF"sampling.d" -MT"sampling.d" -o"sampling.o" "../sampling.cpp"
Finished building: ../sampling.cpp
Building file: ../simulation1.cpp
Invoking: GCC C++ Compiler
g++ -O3 -Wall -c -fmessage-length=0 -Wno-sign-compare -fopenmp -MMD -MP -MF"simulation1.d" -MT"simulation1.d" -o"simulation1.o" "../simulation1.cpp"
../globals.h: At global scope:
../globals.h:43: warning: inline function 'double showDecimals(const double&, const int&)' used but never defined
Finished building: ../simulation1.cpp
Building file: ../test_function.cpp
Invoking: GCC C++ Compiler
g++ -O3 -Wall -c -fmessage-length=0 -Wno-sign-compare -fopenmp -MMD -MP -MF"test_function.d" -MT"test_function.d" -o"test_function.o" "../test_function.cpp"
Finished building: ../test_function.cpp
Building target: pc2
Invoking: GCC C++ Linker
g++ -fopenmp -o"pc2" ./COMPASS.o ./PSA.o ./SAR.o ./constraints.o ./genetic.o ./globals.o ./logging.o ./main.o ./sampling.o ./simulation1.o ./test_function.o
./logging.o: In function `LOG_COMPASS_display_points_MATLAB(int const&, VisitedSet&)':
logging.cpp:(.text+0x686): undefined reference to `VisitedSet::getSize()'
collect2: ld returned 1 exit status
make: *** [pc2] Error 1
make: Leaving directory `/home/djunderw/ncsu/workspace/pc2/release'
Any ideas?
[FIXED ISSUE WITH showDecimals() FUNCTION]
The file COMPASS.h includes this class template:
template<class T> class VisitedSet {
public:
VisitedSet(const T& soln);
int getSize();
void addSolution(const T& soln);
void evaluate();
void sample(const int& numNewSolutions, Constraints& space);
void CSBiased_generateDistribution();
void constructMPA(Constraints& space);
vector<T> vec;
double bestValue;
int bestIndex;
/* used to implement biased coordinate sampling */
double CSBiased_coefficient;
vector< vector<double> > lastSampledPoints;
vector<int> lastSampledPointsIndex;
vector< vector<double> > newSampledPoints;
vector<int> newSampledPointsIndex;
vector<double> CSBiased_distribution;
private:
int iteration;
int dimension;
int SAR(); // simulation allocation rule
};
And COMPASS.cpp include the following code:
template<class T>
int VisitedSet<T>::getSize() {
return vec.size();
}
The logging.cpp files includes the following code:
#include "COMPASS.h"
void LOG_COMPASS_display_points_MATLAB(const int& iteration, VisitedSet<Policy>& visited) {
cout << "points{"<<iteration+1<<"} = [\n"
<< visited.vec[visited.bestIndex].x[0] << "\t" << visited.vec[visited.bestIndex].x[1] << "\t" << visited.vec[visited.bestIndex].meanQALY() << ";" << endl;
for(int i=0; i<visited.getSize(); i++) {
if(i != visited.bestIndex)
cout << visited.vec[i].x[0] << "\t" << visited.vec[i].x[1] << "\t" << visited.vec[i].meanQALY() << ";" << endl;
}
cout << "];\n";
}
int VisitedSet<T>::getSize() is a templated function, so its definition should be in a header file like COMPASS.h, not in COMPASS.cpp.
Here's why: http://www.parashift.com/c++-faq/templates-defn-vs-decl.html
Related
I am trying to compile a Pybind11 module in C++ which calls several header files (.h) on top. As I have a lot of header files, I decided to do a Makefile, which works without problem, EXCEPT for creating the target shared object file (s.o). I need this shared object file in order to be able to call the Pybind module in Python.
However, when compiling, I get:
g++ -shared -fPIC neat.o network.o nnode.o link.o trait.o gene.o innovation.o organism.o species.o genome.o population.o example.o -o example.so
/usr/bin/ld: example.o: relocation R_X86_64_PC32 against symbol `_ZTI3Pet' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status
Makefile:2: recipe for target 'example.so' failed
make: *** [example.so] Error 1
My question is basically: What I am doing wrong when compiling the object files in order to create a target ?
Makefile
example.so: neat.o network.o nnode.o link.o trait.o gene.o innovation.o organism.o species.o genome.o population.o example.o
g++ neat.o network.o nnode.o link.o trait.o gene.o innovation.o organism.o species.o genome.o population.o example.o -shared -o example.so
neat.o: neat.cpp neat.h
g++ -c -O3 -Wall -fPIC neat.cpp
network.o: network.cpp network.h
g++ -c -O3 -Wall -fPIC network.cpp
nnode.o: nnode.cpp nnode.h
g++ -c -O3 -Wall -fPIC nnode.cpp
link.o: link.cpp link.h
g++ -c -O3 -Wall -fPIC link.cpp
trait.o: trait.cpp trait.h
g++ -c -O3 -Wall -fPIC trait.cpp
gene.o: gene.cpp gene.h
g++ -c -O3 -Wall -fPIC gene.cpp
innovation.o: innovation.cpp innovation.h
g++ -c -O3 -Wall -fPIC innovation.cpp
organism.o: organism.cpp organism.h genome.h genome.cpp species.h species.cpp
g++ -c -O3 -Wall -fPIC organism.cpp
species.o: species.h species.cpp organism.cpp organism.h genome.h genome.cpp
g++ -c -O3 -Wall -fPIC species.cpp
genome.o: genome.cpp genome.h
g++ -c -O3 -Wall -fPIC genome.cpp
population.o: population.cpp population.h organism.h
g++ -c -O3 -Wall -fPIC population.cpp
experiments.o: experiments.cpp experiments.h
g++ -c -O3 -Wall -fPIC experiments.cpp
example.o:
g++ -O3 -Wall -std=c++11 -fopenmp -I -fPIC `python3 -m pybind11 --includes` -c example.cpp
clean:
rm *.o *.so
example.cpp
#include <pybind11/pybind11.h>
#include <iostream>
#include <string>
#include "population.h"
namespace py = pybind11;
int create_neat(){
Population *the_pop=0;
return 0;
}
PYBIND11_MODULE(example, m){
m.def("create_neat", &create_neat, "create a pop object");
}
The standard doesn't completely define the difference between #include "..." and #include <...>, but in all compilers I'm familiar with the <> syntax for include typically means, "this is a system-type header file" and the "" syntax means "this is a local-type header file".
In practice this usually means that "" are looked for in the working directory, then in directories specified by -I options to the compiler and finally in system default directories, while <> is the same except it does not look in the working directory.
So, you either need to change your code to use:
#include "population.h"
or else you need to add -I. to your compile line so the compiler knows to look in the current directory:
population.o: population.cpp population.h organism.h
g++ -I. -c population.cpp
Personally I would do both, because it's good hygiene to add the directories you need to your compile line, and because it's good practice to use "" for local headers so people reading the code understand immediately that this is your header and not a system header.
For your second question, Is the compilation in order to make a shared object file with the object files correct I'm sorry but I don't understand what you're asking.
If you're asking about the order of targets defined in the makefile, then they can be in any order at all except that the first target will be the default target (if you run make with no target name then make will build the first target--and any prerequisites needed for the first target).
ETA
OK, now that we can see that the actual error is that example.o does not exist. Why does it not exist? Again, because you've removed important details from the example in your question we can't say for sure. When you write in your question:
example.so: //some .o files which are not important// HERE IS THE PROBLEM
what exactly are the .o files that appear as prerequisites of example.so?
You must list the file example.o as a prerequisite of example.so if you want make to build example.o before trying to build example.so. You need to list all the object files that are needed to create the shared library. So this should be:
example.so: population.o example.o neat.o network.o nnode.o link.o trait.o gene.o innovation.o organism.o species.o genome.o
It doesn't matter what order they appear in the prerequisites list, but they must all be there.
After several hours of reading, trying, and also thanks to the hints of MadScientist, I got it working but the reasons why are still unclear. I just changed the order of the prerequisites in the compilation of the target, by putting the -shared -o example.so in front and not at the end of the line, and it worked.
The whole file is as follows:
example.so: neat.o network.o nnode.o link.o trait.o gene.o innovation.o organism.o species.o genome.o population.o example.o
g++ -shared -o example.so neat.o network.o nnode.o link.o trait.o gene.o innovation.o organism.o species.o genome.o population.o example.o
neat.o: neat.cpp neat.h
g++ -c -O3 -Wall -fPIC neat.cpp
network.o: network.cpp network.h
g++ -c -O3 -Wall -fPIC network.cpp
nnode.o: nnode.cpp nnode.h
g++ -c -O3 -Wall -fPIC nnode.cpp
link.o: link.cpp link.h
g++ -c -O3 -Wall -fPIC link.cpp
trait.o: trait.cpp trait.h
g++ -c -O3 -Wall -fPIC trait.cpp
gene.o: gene.cpp gene.h
g++ -c -O3 -Wall -fPIC gene.cpp
innovation.o: innovation.cpp innovation.h
g++ -c -O3 -Wall -fPIC innovation.cpp
organism.o: organism.cpp organism.h genome.h genome.cpp species.h species.cpp
g++ -c -O3 -Wall -fPIC organism.cpp
species.o: species.h species.cpp organism.cpp organism.h genome.h genome.cpp
g++ -c -O3 -Wall -fPIC species.cpp
genome.o: genome.cpp genome.h
g++ -c -O3 -Wall -fPIC genome.cpp
population.o: population.cpp population.h organism.h
g++ -c -O3 -Wall -fPIC population.cpp
experiments.o: experiments.cpp experiments.h
g++ -c -O3 -Wall -fPIC experiments.cpp
example.o:
g++ -O3 -Wall -std=c++11 -fopenmp `python3 -m pybind11 --includes` -fPIC -c example.cpp
clean:
rm *.o *.so
I am trying to add -std=c++0x into the eclipse Ubuntu but I do not know how to add it.
My original set up:
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/copy2.d" -MT"src/copy2.d" -o "src/copy2.o" "../src/copy2.cpp"
Does not include -std=c++0x that's why giving me the error when I run std::stoi:
error: stoi is not a member of std
My expectation:
g++ -std=c++0x -O0 -g3 -Wall -c -fmessage-length=0 MMD -MP -MF"src/copy2.d" -MT"src/copy2.d" -o "src/copy2.o" "../src/copy2.cpp"
Operating System: CentOS 6.8
Compiler: gcc 4.8.2 and g++4.8.2
Steps to reproduce
Just follow the steps at installation guide
My steps
git clone --recursive https://github.com/dmlc/xgboost
git submodule init
git submodule update
cd xgboost
make -j4
Then I get the error below
[root#xxx]# make -j4
g++ -std=c++0x -Wall -O3 -msse2 -Wno-unknown-pragmas -funroll-loops -Iinclude -Idmlc-core/include -Irabit/include -fPIC -fopenmp -MM -MT build/learner.o src/learner.cc >build/learner.d
g++ -std=c++0x -Wall -O3 -msse2 -Wno-unknown-pragmas -funroll-loops -Iinclude -Idmlc-core/include -Irabit/include -fPIC -fopenmp -MM -MT build/logging.o src/logging.cc >build/logging.d
g++ -std=c++0x -Wall -O3 -msse2 -Wno-unknown-pragmas -funroll-loops -Iinclude -Idmlc-core/include -Irabit/include -fPIC -fopenmp -MM -MT build/c_api/c_api.o src/c_api/c_api.cc >build/c_api/c_api.d
g++ -std=c++0x -Wall -O3 -msse2 -Wno-unknown-pragmas -funroll-loops -Iinclude -Idmlc-core/include -Irabit/include -fPIC -fopenmp -MM -MT build/c_api/c_api_error.o src/c_api/c_api_error.cc >build/c_api/c_api_error.d
g++ -c -std=c++0x -Wall -O3 -msse2 -Wno-unknown-pragmas -funroll-loops -Iinclude -Idmlc-core/include -Irabit/include -fPIC -fopenmp src/c_api/c_api_error.cc -o build/c_api/c_api_error.o
g++ -c -std=c++0x -Wall -O3 -msse2 -Wno-unknown-pragmas -funroll-loops -Iinclude -Idmlc-core/include -Irabit/include -fPIC -fopenmp src/learner.cc -o build/learner.o
g++ -c -std=c++0x -Wall -O3 -msse2 -Wno-unknown-pragmas -funroll-loops -Iinclude -Idmlc-core/include -Irabit/include -fPIC -fopenmp src/logging.cc -o build/logging.o
g++ -c -std=c++0x -Wall -O3 -msse2 -Wno-unknown-pragmas -funroll-loops -Iinclude -Idmlc-core/include -Irabit/include -fPIC -fopenmp src/c_api/c_api.cc -o build/c_api/c_api.o
g++ -std=c++0x -Wall -O3 -msse2 -Wno-unknown-pragmas -funroll-loops -Iinclude -Idmlc-core/include -Irabit/include -fPIC -fopenmp -MM -MT build/common/common.o src/common/common.cc >build/common/common.d
g++ -c -std=c++0x -Wall -O3 -msse2 -Wno-unknown-pragmas -funroll-loops -Iinclude -Idmlc-core/include -Irabit/include -fPIC -fopenmp src/common/common.cc -o build/common/common.o
g++ -std=c++0x -Wall -O3 -msse2 -Wno-unknown-pragmas -funroll-loops -Iinclude -Idmlc-core/include -Irabit/include -fPIC -fopenmp -MM -MT build/data/data.o src/data/data.cc >build/data/data.d
g++ -c -std=c++0x -Wall -O3 -msse2 -Wno-unknown-pragmas -funroll-loops -Iinclude -Idmlc-core/include -Irabit/include -fPIC -fopenmp src/data/data.cc -o build/data/data.o
g++ -std=c++0x -Wall -O3 -msse2 -Wno-unknown-pragmas -funroll-loops -Iinclude -Idmlc-core/include -Irabit/include -fPIC -fopenmp -MM -MT build/data/simple_csr_source.o src/data/simple_csr_source.cc >build/data/simple_csr_source.d
g++ -c -std=c++0x -Wall -O3 -msse2 -Wno-unknown-pragmas -funroll-loops -Iinclude -Idmlc-core/include -Irabit/include -fPIC -fopenmp src/data/simple_csr_source.cc -o build/data/simple_csr_source.o
/tmp/ccNp7oXM.s: Assembler messages:
/tmp/ccNp7oXM.s:148: Error: expecting string instruction after `rep'
/tmp/ccNp7oXM.s:1796: Error: expecting string instruction after `rep'
/tmp/ccNp7oXM.s:4394: Error: expecting string instruction after `rep'
make: *** [build/data/simple_csr_source.o] Error 1
make: *** Waiting for unfinished jobs....
/tmp/ccnxYuhm.s: Assembler messages:
/tmp/ccnxYuhm.s:44: Error: expecting string instruction after `rep'
/tmp/ccnxYuhm.s:272: Error: expecting string instruction after `rep'
/tmp/ccnxYuhm.s:276: Error: expecting string instruction after `rep'
/tmp/ccnxYuhm.s:316: Error: expecting string instruction after `rep'
/tmp/ccnxYuhm.s:29012: Error: expecting string instruction after `rep'
make: *** [build/learner.o] Error 1
/tmp/ccyHo0ol.s: Assembler messages:
/tmp/ccyHo0ol.s:331: Error: expecting string instruction after `rep'
/tmp/ccyHo0ol.s:386: Error: expecting string instruction after `rep'
/tmp/ccyHo0ol.s:555: Error: expecting string instruction after `rep'
/tmp/ccyHo0ol.s:11407: Error: expecting string instruction after `rep'
/tmp/ccyHo0ol.s:17712: Error: expecting string instruction after `rep'
make: *** [build/c_api/c_api.o] Error 1
/tmp/cc3gD7Gv.s: Assembler messages:
/tmp/cc3gD7Gv.s:82: Error: expecting string instruction after `rep'
make: *** [build/data/data.o] Error 1
Is any suggestion for the root cause?
I am not familiar with xgboost, however from the error it seems obvious that some ASM code is not getting generated properly:
expecting string instruction after `rep'
The REP keyword prefix in ASM means "repeat this instruction a number of times (defined by the C register)".
However it could also be a problem with your toolchain. Actually, if the code that generates this error is not relying on inline ASM, it would seem likely that this is a toolchain error.
Some versions of binutils consider rep ret to be invalid, while it is in fact a valid x86-64 instruction.
Try upgrading to binutils 2.23.52.0.1
I already read everything Make: *** [] Error 1 and I am returning a 0 in my main method.
I've tried switching up parsers, but that doesn't work either. I've tried the internal build, that doesn't work (and even if it did I want to work with makefile's).
Here's an example of the error being given. I believe this is what's preventing me from creating the binary files which is a must have in order to run my app.
Error image link -> http://upit.cc/i/c6b2db81.png
Here's the console bit. I did a refresh and then build.
23:52:19 **** Build of configuration Debug for project Lab1 ****
make all
Building file: ../src/Run.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/Run.d" -MT"src/Run.d" -o "src/Run.o" "../src/Run.cpp"
Finished building: ../src/Run.cpp
Building file: ../shared-src/EndToken.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"shared-src/EndToken.d" -MT"shared-src/EndToken.d" -o "shared-src/EndToken.o" "../shared-src/EndToken.cpp"
Finished building: ../shared-src/EndToken.cpp
Building file: ../shared-src/ErrorToken.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"shared-src/ErrorToken.d" -MT"shared-src/ErrorToken.d" -o "shared-src/ErrorToken.o" "../shared-src/ErrorToken.cpp"
Finished building: ../shared-src/ErrorToken.cpp
Building file: ../shared-src/Token.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"shared-src/Token.d" -MT"shared-src/Token.d" -o "shared-src/Token.o" "../shared-src/Token.cpp"
Finished building: ../shared-src/Token.cpp
Building file: ../server-src/server-token/SToken.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"server-src/server-token/SToken.d" -MT"server-src/server-token/SToken.d" -o "server-src/server-token/SToken.o" "../server-src/server-token/SToken.cpp"
Finished building: ../server-src/server-token/SToken.cpp
Building file: ../server-src/server-token/StartSToken.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"server-src/server-token/StartSToken.d" -MT"server-src/server-token/StartSToken.d" -o "server-src/server-token/StartSToken.o" "../server-src/server-token/StartSToken.cpp"
Finished building: ../server-src/server-token/StartSToken.cpp
Building file: ../server-src/Message.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"server-src/Message.d" -MT"server-src/Message.d" -o "server-src/Message.o" "../server-src/Message.cpp"
Finished building: ../server-src/Message.cpp
Building file: ../server-src/Server.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"server-src/Server.d" -MT"server-src/Server.d" -o "server-src/Server.o" "../server-src/Server.cpp"
Finished building: ../server-src/Server.cpp
Building file: ../server-src/User.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"server-src/User.d" -MT"server-src/User.d" -o "server-src/User.o" "../server-src/User.cpp"
Finished building: ../server-src/User.cpp
Building target: Lab1
Invoking: GCC C++ Linker
g++ -o "Lab1" ./src/Run.o ./shared-src/EndToken.o ./shared-src/ErrorToken.o ./shared-src/Token.o ./server-src/server-token/SToken.o ./server-src/server-token/StartSToken.o ./server-src/Message.o ./server-src/Server.o ./server-src/User.o
./shared-src/Token.o:(.rodata._ZTV5Token[_ZTV5Token]+0x20): undefined reference to `Token::getNextToken(char*)'
./shared-src/Token.o:(.rodata._ZTV5Token[_ZTV5Token]+0x28): undefined reference to `Token::processToken(char*)'
collect2: error: ld returned 1 exit status
make: *** [Lab1] Error 1
23:52:20 Build Finished (took 904ms)
As you can see from the image, Lab1 has no Binaries and it's showing the make error.
Solution found thanks to guys commenting
I'm including this code as reference to the comments to this question.
/*
* Token.h
*
* Created on: Sep 12, 2013
* Author: cam
*/
#pragma once
class Token {
public:
Token();
virtual ~Token();
enum TOKEN_TYPE {START, MIDDLE, END, ERROR};
/**
* #pre processToken must be ran first!
*/
virtual Token getNextToken(char*);
virtual bool processToken(char*);
};
/*
* Token.cpp
*
* Created on: Sep 12, 2013
* Author: cam
*/
#include "Token.h"
Token::Token() {
}
Token::~Token() {
}
Token Token::getNextToken(char* buff) {
}
bool Token::processToken(char * buff) {
}
Ultimately I wasn't including two virtual method definitions in my base class. While this got it to compile, I'm curious to know why this is necessary as they are defined as virtual.
I've just tried to debug my C++ program after upgrading to Ubuntu 11.10 and it appears the gdb version I'm running (7.3) is broken for debug output.
What happens:
I hit debug, Console window pops up, Message appears at the top:
warning: GDB: failed to set controlling terminal: Operation not permitted
I get no output from std::cout calls, even just a
std::cout << "hi" << std::endl;
Anyone able to help? I tried to google the subject and came up with a lot of similar issues, but not ones related to this particular symptom, and how to fix it. I've made sure I have the latest version of GDB, etc.
Addendum: I am using Code::Blocks as my ide.
A rebuild of my project with full commandline output gives:
-------------- Clean: Debug in DungeonCrawlerCPP ---------------
Cleaned "DungeonCrawlerCPP - Debug"
-------------- Build: Debug in DungeonCrawlerCPP ---------------
g++ -Wall -fexceptions -g -fpermissive -std=gnu++0x -Iinclude -c /home/reedja/CPPProjects/DungeonCrawlerCPP/main.cpp -o obj/Debug/main.o
g++ -Wall -fexceptions -g -fpermissive -std=gnu++0x -Iinclude -c /home/reedja/CPPProjects/DungeonCrawlerCPP/src/ActionableObject.cpp -o obj/Debug/src/ActionableObject.o
/home/reedja/CPPProjects/DungeonCrawlerCPP/src/ActionableObject.cpp:1:9: warning: #pragma once in main file [enabled by default]
g++ -Wall -fexceptions -g -fpermissive -std=gnu++0x -Iinclude -c /home/reedja/CPPProjects/DungeonCrawlerCPP/src/AppSettings.cpp -o obj/Debug/src/AppSettings.o
/home/reedja/CPPProjects/DungeonCrawlerCPP/src/AppSettings.cpp:1:9: warning: #pragma once in main file [enabled by default]
/home/reedja/CPPProjects/DungeonCrawlerCPP/src/AppSettings.cpp: In member function ‘void AppSettings::load(const char*)’:
/home/reedja/CPPProjects/DungeonCrawlerCPP/src/AppSettings.cpp:98:23: warning: statement has no effect [-Wunused-value]
/home/reedja/CPPProjects/DungeonCrawlerCPP/src/AppSettings.cpp:114:29: warning: statement has no effect [-Wunused-value]
g++ -Wall -fexceptions -g -fpermissive -std=gnu++0x -Iinclude -c /home/reedja/CPPProjects/DungeonCrawlerCPP/src/Container.cpp -o obj/Debug/src/Container.o
/home/reedja/CPPProjects/DungeonCrawlerCPP/src/Container.cpp:1:9: warning: #pragma once in main file [enabled by default]
g++ -Wall -fexceptions -g -fpermissive -std=gnu++0x -Iinclude -c /home/reedja/CPPProjects/DungeonCrawlerCPP/src/Entity.cpp -o obj/Debug/src/Entity.o
g++ -Wall -fexceptions -g -fpermissive -std=gnu++0x -Iinclude -c /home/reedja/CPPProjects/DungeonCrawlerCPP/src/Item.cpp -o obj/Debug/src/Item.o
/home/reedja/CPPProjects/DungeonCrawlerCPP/src/Item.cpp:1:9: warning: #pragma once in main file [enabled by default]
g++ -Wall -fexceptions -g -fpermissive -std=gnu++0x -Iinclude -c /home/reedja/CPPProjects/DungeonCrawlerCPP/src/Monster.cpp -o obj/Debug/src/Monster.o
/home/reedja/CPPProjects/DungeonCrawlerCPP/src/Monster.cpp:1:9: warning: #pragma once in main file [enabled by default]
g++ -Wall -fexceptions -g -fpermissive -std=gnu++0x -Iinclude -c /home/reedja/CPPProjects/DungeonCrawlerCPP/src/Player.cpp -o obj/Debug/src/Player.o
/home/reedja/CPPProjects/DungeonCrawlerCPP/src/Player.cpp: In member function ‘void Player::attackMonster(std::string)’:
/home/reedja/CPPProjects/DungeonCrawlerCPP/src/Player.cpp:36:43: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
g++ -Wall -fexceptions -g -fpermissive -std=gnu++0x -Iinclude -c /home/reedja/CPPProjects/DungeonCrawlerCPP/src/Room.cpp -o obj/Debug/src/Room.o
/home/reedja/CPPProjects/DungeonCrawlerCPP/src/Room.cpp:1:9: warning: #pragma once in main file [enabled by default]
g++ -Wall -fexceptions -g -fpermissive -std=gnu++0x -Iinclude -c /home/reedja/CPPProjects/DungeonCrawlerCPP/src/tinystr.cpp -o obj/Debug/src/tinystr.o
g++ -Wall -fexceptions -g -fpermissive -std=gnu++0x -Iinclude -c /home/reedja/CPPProjects/DungeonCrawlerCPP/src/tinyxml.cpp -o obj/Debug/src/tinyxml.o
g++ -Wall -fexceptions -g -fpermissive -std=gnu++0x -Iinclude -c /home/reedja/CPPProjects/DungeonCrawlerCPP/src/tinyxmlerror.cpp -o obj/Debug/src/tinyxmlerror.o
g++ -Wall -fexceptions -g -fpermissive -std=gnu++0x -Iinclude -c /home/reedja/CPPProjects/DungeonCrawlerCPP/src/tinyxmlparser.cpp -o obj/Debug/src/tinyxmlparser.o
g++ -o bin/Debug/DungeonCrawlerCPP obj/Debug/main.o obj/Debug/src/ActionableObject.o obj/Debug/src/AppSettings.o obj/Debug/src/Container.o obj/Debug/src/Entity.o obj/Debug/src/Item.o obj/Debug/src/Monster.o obj/Debug/src/Player.o obj/Debug/src/Room.o obj/Debug/src/tinystr.o obj/Debug/src/tinyxml.o obj/Debug/src/tinyxmlerror.o obj/Debug/src/tinyxmlparser.o
Output size is 674.11 KB
Process terminated with status 0 (0 minutes, 6 seconds)
0 errors, 9 warnings
If that helps?...
I found the answer - for some reason C::B doesn't set global -g as default, so I had no debugging symbols. I still get the weird error message, but at least I now get console output :)