QtCreator build returns collect2: ld returned exit

2019-04-26 21:56发布

While building several different projects in QtCreator, I have run across the following build error:

collect2: ld returned 1 exit status

After only changing a few things (that should not change anything significant in the build), it will go away if it has already appeared, or it will appear if it's not there.

In my current program for a school project, I am trying to compile rock03.cpp. It's the only file in the build, and has the main() method. I had just run it successfully, and went back to change the order of some if()s, now, I get only two relevant warnings:

overriding commands for target 'rock03.o'

and

ignoring old commands for target 'rock03.o'

along with the error in question.

Does anyone know why this would happen? I cannot seem to reproduce the error with any reasonable certainty, and QtCreator is not complaining about any thing before I build.

Thanks

10条回答
孤傲高冷的网名
2楼-- · 2019-04-26 22:36

I had the same problem. My resolution is - implement all virtual functions and all slots declarations.

查看更多
我命由我不由天
3楼-- · 2019-04-26 22:41

This happens to me because I make a declaration in the header file, then delete the function in the cpp file and I forget to delete the decleration in the header. For example...

 //header file
class CLASS : public Q_OBJECT
{
...
protected:
void mouseMoveEvent(QMouseEvent*);
}

//source file

void CLASS::mouseMoveEvent(QMouseEvent*e)
{
...
}
    //I'll delete this, then forget to delete "void mouseMoveEvent(QMouseEvent*);" in the header file
查看更多
乱世女痞
4楼-- · 2019-04-26 22:41

This error may also occur because of problems with linkage, for example, you forgot to declare some static variables from header file using 'extern' directive.

查看更多
Luminary・发光体
5楼-- · 2019-04-26 22:47

In my case it was declaring the clear virtual function.

void virtual Func(MouseEvent*); // Error.
void virtual Func(MouseEvent*) = 0; // Well!
查看更多
登录 后发表回答