Lion King
Lion King

Reputation: 33813

Qt error: LNK1181: cannot open input file 'debug\main.obj'

Qt creator was working well, but suddenly shows a problem error: LNK1181: cannot open input file 'debug\main.obj'.
This problem shows always with any type of application either GUI or console.
I've uninstall the Qt, and install again, but the problem still exists.
I did not do anything in the Qt creator settings, I left the default settings.

The following application is simple console application occur the same problem in it.

//main.cpp
#include <QCoreApplication>

int main(int argc, char *argv[]){
    QCoreApplication a(argc, argv);

    return a.exec();
}

Note: I'm using Qt 5.1.1 for Windows 32-bit (VS 2010, OpenGL).

Upvotes: 13

Views: 25158

Answers (9)

Igor Massao
Igor Massao

Reputation: 1

I solved the problem by removing the big path and space names in the directories. Try to create a folder in C:/ and copy or clone the project in this folder. Remove all builder folders and configure the project again. That solved it for me.

Upvotes: 0

Lion King
Lion King

Reputation: 33813

The problem has been solved.

The cause of the problem was when creating a new project (GUI or Console), all source files that belong to this new project take a wrong extension ex: main.cp, but the correct extension is supposed to be ex: main.cpp. And when changing all the source files extension from .cp to .cpp worked fine.

Or change the default source file extension from [Tools -> Option -> C++].

Upvotes: 1

Jakubek K.
Jakubek K.

Reputation: 31

What worked for me:

  1. Close the Qt Creator
  2. Delete the [filename].pro.user file in your project directory
  3. Open the project again and let Qt configure itself

Generally whenever I encounter an error like this, this is one of the first things I do as it solves a lot of problems with Qt.

Edit: This will of course reset your project build location.

Upvotes: 1

Hadi Navapour
Hadi Navapour

Reputation: 261

This problem occurs also if you have in the .pro or .pri files something like:

HEADERS += \ \

or

SOURCES += \ \

Upvotes: 9

Mikkel L
Mikkel L

Reputation: 31

I got the error because of this:

HEADERS += \ \
    $$PWD/QOakTreeViewRecursiveModel.h

instead of:

HEADERS += \
    $$PWD/QOakTreeViewRecursiveModel.h

Upvotes: 1

kayleeFrye_onDeck
kayleeFrye_onDeck

Reputation: 6968

Okay, we finally have a real answer for this generalized problem instead of the OP's typo problem if that didn't unblock you either.

Actual Problem (black-box perspective): The "Build directory" auto-filled entry breaks for projects inside whitespace directories. Qt Creator actually prohibits you and tells you not to use whitespace when making new Projects. You can still close a new project and re-name it to add whitespace, and Qt Creator will handle it gracefully. If you copy the build directory, even with whitespace in it, and paste that into the field replacing the broken auto-generated path (mine was using relative paths) then JOM will start working correctly, as QMake does not generate any errors. I can't speak for other Make tools.

  1. Make or clone down your project with whitespace
  2. Load it in Qt Creator
  3. Run QMAKE
  4. Select the "Project" button on the left-hand side
  5. Make sure you're in the "Build" tab
  6. Select "Browse", and then re-select the shadow directory QMAKE made

That should unblock you if it wasn't a simple issue for deleting the old QMAKE-generated folders, which is the most common problem people face with this specific error while developing within Qt Creator.

Upvotes: 3

Filip Hazubski
Filip Hazubski

Reputation: 1728

This problem also occurs if the path of your project (name of any folder) contains a white space.

Upvotes: 23

S.M.Mousavi
S.M.Mousavi

Reputation: 5226

Run Clean and qMake and rebuild.
I has like this problem and this helped me.

Upvotes: 0

Qnoobish
Qnoobish

Reputation: 178

hmm If I remember correctly when I faced this kind of problems using your similar setup (QtCreator and Windows) running QMAKE & rebuilding the project again helped me solve this linker errors.

Upvotes: 0

Related Questions