侧边栏壁纸
  • 累计撰写 185 篇文章
  • 累计创建 77 个标签
  • 累计收到 17 条评论

目 录CONTENT

文章目录

qt creator编译时出现了错误:error: LNK1181: cannot open input file 'debug\main.obj'

码峰
2023-09-24 / 0 评论 / 0 点赞 / 1,008 阅读 / 416 字 / 正在检测是否收录...
广告 广告

问题描述

error: LNK1181: cannot open input file ‘debug\main.obj’。无法打开输入文件"debug\main.obj"
image
This is most likely caused by an error in the project settings. Source files (.cpp) are compiled into object files (.o) which are then all linked together. Somehow the linker is failing to find the object files compiled from your source files. I can tell it is looking into debug, but they are being stored somewhere else. Do you have write permissions to that directory?
This problem also occurs if the path of your project (name of any folder) contains a white space.
'The error occurs because the linker in VS2015 can not find the file or the file path defined in the project properties. However, the file path or file in the properties is correct because the linker can handle space character in the file path.
To solve the issue, you just avoid to use space character in the file path or add quotation around file path in project properties.

解决方法

方法一

构建->清理项目,因为一些配置qmake等与源目录相关,直接运行的话会在原来的拷贝目录下生成debug目录和调试文件,切若原目录不存在的话也将重新创建。而不是在当前新文件夹下生成调试文件。

方法二

如果“方法一”不管用,使用重新构建、清楚等命令也无法解决。
当.pro或者.pri文件中的头文件出现如下情况(两个反斜杠)时会出现该问题。
删除一个\即可解决。

HEADERS += \ \
    XX1.h \
    xx2
# OR 
SOURCES += \ \
    XX1.cpp \
    xx2.cpp \
    yy.cpp

方法三

如果“方法一、二”都不管用,可以试试在“项目”设置页面中,取消勾选Shadow build,然后对项目执行qmake”再“构建”,应该能解决。

0
广告 广告

评论区