msys2 / MSYS2-packages

Package scripts for MSYS2.
https://packages.msys2.org
BSD 3-Clause "New" or "Revised" License
1.3k stars 490 forks source link

collect2.exe: error: ld returned 116 exit status #4617

Closed wv1124 closed 5 months ago

wv1124 commented 5 months ago

Description / Steps to reproduce the issue

win11

  1. install msys2
  2. pacman -S --needed base-devel mingw-w64-ucrt-x86_64-toolchain
  3. add E:\msys64\usr\bin, E:\msys64\ucrt64\bin to path.
  4. main.cpp
    #include <iostream>
    using namespace std;
    int main(void)
    {
    cout << "test";
    return 0;
    }
  5. open windows power shell
  6. g++ .\main.cpp -o main
  7. collect2.exe: error: ld returned 116 exit status

more refer: https://stackoverflow.com/questions/78477174/collect2-exe-error-ld-returned-116-exit-status-when-using-g-with-git-bash/78521930#78521930

g++ --version g++.exe (Rev6, Built by MSYS2 project) 13.2.0 Copyright (C) 2023 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

gcc --version gcc.exe (Rev6, Built by MSYS2 project) 13.2.0 Copyright (C) 2023 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Expected behavior

compile success

Actual behavior

collect2.exe: error: ld returned 116 exit status

Verification

Windows Version

MINGW64_NT-10.0-22631

Are you willing to submit a PR?

No response

MehdiChinoune commented 5 months ago

Please, update your installation before filling any bug. (I have verified that my MSYS2 is up-to-date before submitting the report)

jeremyd2019 commented 5 months ago
  1. add E:\msys64\usr\bin, E:\msys64\ucrt64\bin to path.

Kind of a wild guess based on limited information, but if you put both on the PATH, you should put ucrt64\bin first. Otherwise you could be accidentally using eg msys binutils with ucrt64 gcc, and I'm sure that would be a recipe for disaster.

Koehle commented 2 months ago

I had the same problem and the solution for me was a change in the Windows system environment variables.

In my case, only the path “C:\msys64\ucrt64\bin” and its position relative to the other system environment variables was relevant.

Meld, PuTTY, TortoiseGit and Git are installed on my computer and their paths were also entered in the environment variables.

At first I had entered the path “C:\msys64\ucrt64\bin” after the entries for Meld, PuTTY etc. and had the error described.

After I moved the path to MSYS2 to the top, i.e. before the paths of the other programs, compiling the source code worked without the error.