Nominate our 2022 Qt Champions!

Compile error, cannot open output file, invalid argument

  • After working with my project today, I came across a wierd error:

    @:-1: error: cannot open output file debug\program.exe: Invalid argument
    collect2.exe:-1: error: error: ld returned 1 exit status@

    I've gotten rid of the message by "doing it all", cleaning, rebuilding, deleting the whole project/debug folder, even delete the whole output folder and then rebuild... The error might go away, but it will come back soon enough, and nothing seems to work. Then it just magically compiles.

    Needless to say I can't work like this, so has anyone ran into a similiar problem? Any suggestions?

    I'm working with client <> server communication atm, with sockets. I'm not sure if that has anything to do with anything.

    EDIT: Oh, almost forgot. I been looking at the debug folder while Qt Creator builds the project. Qt Creator never creates the .exe, only .tmp file, with random name for example trz81F0.tmp. Sometimes, earlier today, when I encountered the same problem, it sometimes created the .exe but it was 0 KB in size.

  • Hmm, now this is very bizarre!

    I've now pinpointed the cause. In my main() I have:

    QStringList files;
    QStringList hashed = connection->addHashes(files);

    In requestFiles the files stringlist is updated with filenames and addHashed returns another QStringList, using the files list's data.

    Now, if I compile my application with these lines, I get and .tmp file instead of the .exe, and so it doesn't work (compiler gives no errors). If I comment out the line:

    @QStringList hashed = connection->addHashes(files);@

    It compiles fine! Now this ofcouse got me thinking, and I created a new function my in connection -object (class patchServerConnection):

    @QStringList patchServerConnection::test(QStringList test)
    QStringList list;
    return list;

    And so I ran:

    QStringList files;
    QStringList hashed = connection->test(files);

    And the problem again rises! Again, just a randomly named .tmp file in the output folder instead of the .exe. I've played around this alot, and have noticed now that every time I call a function from connection -object with QStringList as parameter, the compiler doesn't compile the exe correctly. If I create a function which returns a QStringList, but doesn't take a stringlist as parameter, it works. Also:

    1. I've tried with a different QStringList, I mean not using the files -named object.
    2. I tried with void test(QStringList test = QStringList()); and then calling only connection->test(); Still doesn't work.

    Now, I can go around this problem for now it seems, by changing addHashes to take a QStringList as a pointer instead of returning the list. But still, whaaaaat on earth causes this behavior? Anyone have any clues??

    EDIT: Well, actually I can't go around it, as I ofcourse do have to pass the files -QStringlist to addHashes... Damn it! Please, I need help :(

    EDIT2: Well, I don't think it has anything to do with anything really. I do a workaround of some sort, get it to compile. Start working like normal again, and again at random time it hangs up with the error

    @:-1: error: cannot open output file debug\program.exe: Invalid argument
    collect2.exe:-1: error: error: ld returned 1 exit status@

    And yet again if I change some random thing here or there it starts to work. What the hell?!

  • Lifetime Qt Champion


    What version of Qt are you using ? On which OS with which compiler ?
    What is the complete error log ? Also are you sure you are including QStringList properly where needed ?

  • Phew, I wrote just a long post (again...), and just before hitting post reply I noticed something. I hadn't added a file that I had included, in to my project. The file is basic globals type file, constant QStrings mostly. It's strange the compiler didn't give any error about it though.

    After adding it to my project, I've now been able to go forward without errors for some time. I'm pretty positive that was the cause.

    Thank you SGaist, you guided me toward the solution with your comment about QStringList includes. I played a lot with includes for QStringList, but as it seems, it wasn't actually QStringList that was causing the problem, although it seemed likely at first.

    This is now probably solved, I'll update the topic header after some more testing, just to be sure..

Log in to reply