求助大神这是什么歌undefined reference to xxx'的问题

求助打包APK编译时遇到undefined reference to的问题_百度知道
求助打包APK编译时遇到undefined reference to的问题
我有更好的答案
一般是由于#include 包含路径不对请认真检查。祝你愉快,满意请采纳。
为您推荐:
其他类似问题
等待您来回答error: undefined reference to `vtable for - 必应error: undefined reference to `vtable for必应网典为您找到以下相关问题问问题描述:I have the code:#include &iostream& #include &QThread& #include &unistd.h& #include &stdlib.h& #include &QApplication& using std:: using std:: class Thread : public QThread { Q_OBJECT public: Thread(); ~Thread();
void setMessage(const QString &_message); void stop(); protected: void run(); private: QS
v }; Thread::Thread() { stopped = run(); } Thread::~Thread() { } void Thread::run() {
while(!stopped){ cerr && qPrintable(message); sleep(1); } stopped = cerr && } void Thread::stop() { stopped = } void Thread::setMessage(const QString &_message) { message = _ } int main(int argc, char *argv[]) { QApplication app(argc, argv); Thread *A,*B; A = new Thread(); B = new Thread(); A-&setMessage(&Thread A\n&); B-&setMessage(&Thread B\n&); //.run(); //.run(); sleep(10); A-&stop(); B-&stop(); return 0; }and i have errorg++ -Wl,--hash- style=gnu -Wl,--as-needed -Wl,-O1 -o
tmp main.o -L/usr/lib -lQtGui -lQtCore -lpthread main.o: In function `Thread::~Thread()': main. cpp:(.text+0xa): undefined reference to `vtable for Thread' main.o: In function `Thread::Thread()': main.cpp:(.text+0x1da): undefined reference to `vtable for Thread' collect2: ld returned 1 exit status make: *** [tmp] Error 1 图片:/questions/tagged/c%2b%2b 图片:/questions/tagged/multithreading 图片:/questions/tagged/ qt答You must generate a header with moc. This can be done automatically with the Qt build system. Instead of using gcc directly, you should use a qmake file.Also you should probably separate the declaration and code into header file and
file.Here is a description of what moc does: http://../latest/moc.htmlAnd a similar question (with answers) here on stackoverflow: Undefined reference to vtable. Trying to compile a Qt project来自问问题描述:I have the code:#include &iostream& #include &QThread& #include &unistd.h& #include &stdlib.h& #include &QApplication& using std:: using std:: class Thread : public QThread { Q_OBJECT public: Thread(); ~Thread();
void setMessage(const QString &_message); void stop(); protected: void run(); private: QS
v }; Thread::Thread() { stopped = run(); } Thread::~Thread() { } void Thread::run() {
while(!stopped){ cerr && qPrintable(message); sleep(1); } stopped = cerr && } void Thread::stop() { stopped = } void Thread::setMessage(const QString &_message) { message = _ } int main(int argc, char *argv[]) { QApplication app(argc, argv); Thread *A,*B; A = new Thread(); B = new Thread(); A-&setMessage(&Thread A\n&); B-&setMessage(&Thread B\n&); //.run(); //.run(); sleep(10); A-&stop(); B-&stop(); return 0; }and i have errorg++ -Wl,--hash- style=gnu -Wl,--as-needed -Wl,-O1 -o
tmp main.o -L/usr/lib -lQtGui -lQtCore -lpthread main.o: In function `Thread::~Thread()': main. cpp:(.text+0xa): undefined reference to `vtable for Thread' main.o: In function `Thread::Thread()': main.cpp:(.text+0x1da): undefined reference to `vtable for Thread' collect2: ld returned 1 exit status make: *** [tmp] Error 1 图片:/questions/tagged/c%2b%2b 图片:/questions/tagged/multithreading 图片:/questions/tagged/ qt答You must generate a header with moc. This can be done automatically with the Qt build system. Instead of using gcc directly, you should use a qmake file.Also you should probably separate the declaration and code into header file and
file.Here is a description of what moc does: http://../latest/moc.htmlAnd a similar question (with answers) here on stackoverflow: Undefined reference to vtable. Trying to compile a Qt project来自问问题描述:I have the code:#include &iostream& #include &QThread& #include &unistd.h& #include &stdlib.h& #include &QApplication& using std:: using std:: class Thread : public QThread { Q_OBJECT public: Thread(); ~Thread();
void setMessage(const QString &_message); void stop(); protected: void run(); private: QS
v }; Thread::Thread() { stopped = run(); } Thread::~Thread() { } void Thread::run() {
while(!stopped){ cerr && qPrintable(message); sleep(1); } stopped = cerr && } void Thread::stop() { stopped = } void Thread::setMessage(const QString &_message) { message = _ } int main(int argc, char *argv[]) { QApplication app(argc, argv); Thread *A,*B; A = new Thread(); B = new Thread(); A-&setMessage(&Thread A\n&); B-&setMessage(&Thread B\n&); //.run(); //.run(); sleep(10); A-&stop(); B-&stop(); return 0; }and i have errorg++ -Wl,--hash- style=gnu -Wl,--as-needed -Wl,-O1 -o
tmp main.o -L/usr/lib -lQtGui -lQtCore -lpthread main.o: In function `Thread::~Thread()': main. cpp:(.text+0xa): undefined reference to `vtable for Thread' main.o: In function `Thread::Thread()': main.cpp:(.text+0x1da): undefined reference to `vtable for Thread' collect2: ld returned 1 exit status make: *** [tmp] Error 1 图片:/questions/tagged/c%2b%2b 图片:/questions/tagged/multithreading 图片:/questions/tagged/ qt答You must generate a header with moc. This can be done automatically with the Qt build system. Instead of using gcc directly, you should use a qmake file.Also you should probably separate the declaration and code into header file and
file.Here is a description of what moc does: http://../latest/moc.htmlAnd a similar question (with answers) here on stackoverflow: Undefined reference to vtable. Trying to compile a Qt project来自问问题描述:There is some linking error here. I looked that online, yet still I couldn't
find the problem.. can you please help me?g++ test. cpp -o test / tmp/ccDfCj4N.o: In function `Interval::Interval()': test.cpp:(.text._ZN8IntervalC2Ev[Interval::Interval()]+0x9): un defined reference to `vtable for Interval' /tmp/ccDfCj4N.o: In function `IntInterval::~IntInterval()': test.cpp:(.text._ZN11IntIntervalD0Ev[IntInterval::~IntInterval()]+0x1d): undefined reference to `Interval::~Interval()' /tmp/ccDfCj4N.o: In function `IntInterval::~IntInterval()': test.cpp:(.text._ZN11IntIntervalD1Ev[IntInterval::~IntInterval()]+0x1d): undefined reference to `Interval::~Interval()' /tmp/ccDfCj4N.o:(.rodata._ZTI11IntInterval[typeinfo for IntInterval]+0x10): undefined reference to `typeinfo for Interval' collect2: ld returned 1 exit statusHere is the code! All classes are in a same file for a pilot program.#include &iostream& #include & vector& #include &utility& #define MAX_IP_RANGE
class Interval{ public: virtual Interval * interval_ copy()=0; virtual unsigned long get_begin()=0; virtual unsigned long get_end()=0; virtual unsigned long get_length()=0; virtual Interval* get_intersect(Interval *interval)=0; // examine whether two intervals have intersection virtual Interval* copy()=0; virtual ~Interval(); virtual bool is_equal(Interval *interval){ unsigned long b1 = this-&get_begin(); unsigned long e1 = this-&get_end(); unsigned long b2 = interval-&get_begin(); unsigned long e2 = interval-&get_end(); if(b1 == b2 && e1 == e2) } virtual bool is_within(Interval *interval){ unsigned long b1 = this-&get_begin(); unsigned long e1 = this-&get_end(); unsigned long b2 = interval-&get_begin(); unsigned long e2 = interval-&get_end(); if(b1 &= b2 && e1 &= e2) } virtual bool contains(Interval *interval){ // examine whether this interval contains another interval unsigned long b1 = this-&get_begin(); unsigned long e1 = this-&get_end(); unsigned long b2 = interval-&get_begin(); unsigned long e2 = interval-&get_end(); if(b1 &= b2 && e1 &= e2) } virtual bool is_empty() { return (get_end()&get_begin())?true: } virtual bool is_intersect(Interval *interval){ unsigned long b1 = this-&get_begin(); unsigned long e1 = this-&get_end(); unsigned long b2 = interval-&get_begin(); unsigned long e2 = interval-&get_end(); if(b1&e2) if(b2&e1) } virtual
void print() { cout&&'('&&get_begin()&&','&&get_end()&&& )\n&; } }; class IntInterval : public Interval{ private: IntInterval(); public: virtual Interval * interval_copy(){return new IntInterval(begin,end);} IntInterval(unsigned long a,unsigned long b): begin (a), end (b) {} void set_value(unsigned long a,unsigned long b) {begin = end =} void set_begin(unsigned long a) {begin = } void set_end(unsigned long b) { end =} virtual Interval* copy() { Interval *new_interval = new IntInterval(begin,end); return new_ } virtual unsigned long get_begin() {} virtual unsigned long get_length() {return end-begin+1;} virtual unsigned long get_end() {} virtual Interval* get_intersect(Interval *interval); // get the intersect part of two intervals virtual ~IntInterval() {}; }; Interval* IntInterval::get_intersect(Interval *interval) { unsigned long begin2 = interval-&get_begin(); unsigned long end2 = interval-&get_end(); if(end & begin2 || begin & end2){ return new IntInterval(1,0); } return new IntInterval((begin&begin2)?begin:begin2, (end&end2)?end:end2); } IntInterval * parse_ip(const
char * _str) { unsigned long _begin=0; unsigned long _end=0;
string input(_str); if(input.find('-') != string::npos){ string begin = input.substr(0,input.find('-')); string end = input.substr(input.find('-')+1); unsigned int ip1 = 0, ip2 = 0; unsigned int ip3 = 0, ip4 = 0;
sscanf(begin.c_str(),&%u.%u.%u.%u&,&ip1,&ip2,&ip3,&ip4); _begin = (ip1 && 24) + (ip2 && 16) + (ip3 && 8) + ip4; ip1 = 0; ip2 = 0; ip3 = 0; ip4 = 0; sscanf(end.c_str(),&%u.%u.%u.%u&,&ip1,&ip2,&ip3,&ip4); _end = (ip1 && 24) + (ip2 && 16) + (ip3 && 8) + ip4; if ((_begin & _end) || (_end & MAX_IP_RANGE)){ cout&&&ERROR: The IP INTERVAL IS WRONG The range is &&&begin&&&-&&&end&& exit(0); } } return new IntInterval(_begin,_end); } bool compFunc (Interval * i, Interval * j) { return (i-&get_begin() & j-&get_begin()); } int main () { vector &vector&pair&string,string& & & vector&pair&string,string& & vector&pair&string,string& & x.push_back(make_pair(&1.1.1.1&,&3.0.0.0&)); x.push_back(make_pair(&10.2.5.3&,&30.2.5.0&)); x.push_back(make_pair(&100.2.25.2&,&130.2.25.2&)); y.push_back(make_pair(&41.0.2.2&,&43.2.2.5&)); y.push_back(make_pair(&131.2.2.2&,&135.5.5.2&)); nets.push_back(x); nets.push_back(y); vector &IntInterval *& _ for(int i=0;i&(int)nets.size();i++) for(int j=0;j&(int)nets[i].size();j++){ string s = nets[i][j].first+'-'+nets[i][j]. _nets.push_back(parse_ip(s.c_str())); } sort (_nets.begin(), _nets.end(), compFunc); if (_nets.size()&1) for(vector&IntInterval *&:: iterator it = _nets.begin()+1 ;it& _nets.end();) { if ((*it)-&get_begin()-1 == (*(it-1))-&get_end()){ (*(it-1))-&set_end((*it)-&get_end()); _nets.erase(it); }else if ((*it)-&get_begin()-1 & (*(it-1))-&get_end()){ it++; cout&&&ERROR: Network address overlapping!&&& }else it++; } for(int i=0;i&(int)_nets.size();i++) cout&&_nets[i]-&get_begin()&&& &&&_nets[i]-&get_end()&& return 0; }I really appreciate it! 图片:/questions/tagged/c%2b%2b 图片:/questions/tagged/g%2b%2b答You never provided an implementation for virtual ~Interval(); and several other functions. You must provide an implementation for all non-pure virtual functions you declare. In particular, G++ emits the vtable along with the implementation of the first-declared non- function in a class. Omitting its implementation means you won't have a vtable, and thus won't be able to construct the class (hence these errors).In short,
every function you declare, except for pure virtuals. There are some cases where it's justified to leave out the definition for a declared function, but they are very rare.来自其他类似问题更多关于define的热门话题000000

我要回帖

更多关于 金毛走丢报警求助 的文章

 

随机推荐