QtCreator构建返回collect2:ld返回退出状态1
在 QtCreator 中构建几个不同的项目时,我遇到了以下构建错误:
collect2: ld returned 1 exit status
仅更改了一些内容(不应更改构建中的任何重要内容)后,如果它已经出现,它将消失,或者如果它已经出现,它将出现它不在那里。
在我当前的学校项目中,我正在尝试编译 rock03.cpp。它是构建中的唯一文件,并且具有 main() 方法。我刚刚成功运行它,然后返回更改一些 if()
的顺序,现在,我只收到两个相关警告:
overriding commands for target 'rock03.o'
以及
ignoring old commands for target 'rock03.o'
有问题的错误。
有谁知道为什么会发生这种情况?我似乎无法以任何合理的确定性重现该错误,并且 QtCreator 在构建之前不会抱怨任何事情。
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
如果唯一的消息错误是与链接器有关的这一错误,原因可能是您的程序仍在运行并且链接器无法访问二进制文件。确保您的应用程序已停止,如果仍在运行,则将其终止。
Qtcreator 在编译之前从不检查先前的运行是否已停止。
If the only message error is this one concerning linker, the reason can be that your program is still running and linker can not access to the binary file. Be sure your application was stopped or kill it if still running.
Qtcreator never checks if previous run was stopped before compiling.
我遇到这种情况是因为我在头文件中做了声明,然后删除了cpp文件中的函数,而我忘记删除头文件中的声明。例如...
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...
如果您只是将其视为错误,则编译器输出确实很有帮助,但第一个候选者可能是您仍然打开输出程序,并且它无法写入文件,因为这会给您像这样的孤立的collect2错误
The compiler output is really helpful if you're just getting this as an error, but the first candidate is probably that you've still got the output program open, and it can't write to the file, because that'll give you a solitary collect2 error like this
由于链接问题也可能会出现此错误,例如,您忘记使用“extern”指令从头文件中声明一些静态变量。
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.
就我而言,文件夹权限是问题所在。 检查“编译输出”窗口对于找出到底是什么问题至关重要。(QtCreator 在这方面与 Visual Studio 相反,因此需要一些时间来适应。)我尝试设置权限正确,但之后似乎不起作用,最后我停用了影子构建,然后转到“工具/选项/构建和运行/常规/项目目录”并将“目录”设置为“。”。然后终于编译通过了。 “它”是 Qt 5.11 中的 kmap2qmap 项目。
只是我的 2 美分,以防有人发现它们有用。
In my case, folder permissions were the problem. Checking the "Compile Output" window is crucial for finding out what exactly the problem is. (QtCreator is the opposite of Visual Studio in that regard, so it takes some getting used to.) I tried setting the permissions properly, but after that didn't seem to work, in the end I deactivated shadow build and then I went to "Tools/Options/Build&Run/General/Projects Directory" and set "Directory" to ".". Then it finally compiled. "It" being the kmap2qmap project in Qt 5.11.
Just my 2 cents in case anyone might find them useful.
当您不关闭主应用程序时会发生这种情况(因此输出可执行文件仍在运行,但没有任何可见窗口)。一个示例:
当您关闭主窗口时,此应用程序会正常结束,但当
您关闭对话框时,此代码不会关闭应用程序(至少对我来说)。
解决方案是始终创建主窗口并确保关闭它。
This happens when you do not close your main app (so the output executable is still running, but without any visible window). An example:
This app ends fine when you close the main window, but this code
doesn't close the app when you close the dialog (at least for me).
A solution is to create always your main window and make sure you close it.
就我而言,它声明了明确的虚拟函数。
In my case it was declaring the clear virtual function.
导致该错误的原因可能还有很多。但对我来说,从班级中删除未使用的插槽后,问题就解决了。
There could be many more reasons for the error. But for me, on removing of unused SLOTS from the class the problem was solved.
我也有同样的问题。我的解决方案是 - 实现所有虚拟函数和所有插槽声明。
I had the same problem. My resolution is - implement all virtual functions and all slots declarations.
检查“编译输出”窗格显示 .pro 文件试图链接同一个 .cpp 文件两次。
Checking the "Compile Output" pane reveals that the .pro file was trying to link the same .cpp file twice.