Netbeans and MinGW-w64

2019-01-11 21:32发布

I'm trying to configure my NetBeans on win7 64bit, to work with the MinGW-w64.
So I put in the %PATH% variable the following paths of the compiler:
C:\mingw-w64-bin_i686\mingw\bin
C:\minGw-MSYS\msys\bin
C:\mingw-w64-bin_i686\libexec\gcc\x86_64-w64-mingw32\4.7.0

Then I opened NetBeans and this was configured:

The configuration in NetBeans

I tried to compile a little test program but I received this error:

g++.exe: fatal error: -fuse-linker-plugin, but liblto_plugin-0.dll not found compilation terminated. make[2]: * [dist/Debug/MinGW-Windows/test.exe] Error 1 make1: [.build-conf] Error 2 make: ** [.build-impl] Error 2

BUILD FAILED (exit value 2, total time: 1s)

I do have this file in C:\mingw-w64-bin_i686\libexec\gcc\x86_64-w64-mingw32\4.7.0

what am I missing?

3条回答
相关推荐>>
2楼-- · 2019-01-11 21:45

With some searching via your favorite Internet search engine, I have come across a better approach to quickly add MinGW-x64 to a Windows 64-bit system. On the Sourceforge site is MSYS2.

While following the installation directions and obtaining the most up to date packages, there may be a time out at the primary mirror site on Sourceforge. If so, follow the mirror site update directions and update the three pacman text files in the respective MSYS2 directory (e.g. /etc/pacman.d). Then proceed to complete the package updates from the MSYS2 installation directions.

Within the MSYS2 packages are things like gcc, llvm, make, dmake, etc. Here is the command used from the MSYS2 command line shell (e.g. bash) to install the GNU make utility:

$ pacman -S msys/make

The executable location it will be placed is: /usr/bin inside the MSYS2 command shell. As far as configuring Netbeans for where make.exe is located, the Windows path is:

MSYS2 installation directory\usr\bin\make.exe

(e.g. C:\msys64\usr\bin\make.exe).

To successfully build C++ with Netbeans, I used the GNU make package (e.g. msys/make). Then in order to use the default make files that Netbeans manages, and to not interfere with other C++ compilers within your Windows installation (e.g. Visual Studio, Intel, CLang from Visual Studio, etc.), run Netbeans from the MinGW-x64 command shell provided by MSYS2. In this way, the environment variables and other things like:

ls
rm
mkdir

will indicate successful execution and compilation within the Netbeans internal terminal window. I opened the MinGW-w64 Win64 Shell by navigating to the installed shortcut from MSYS2's installation. Then pasted into the MinGW-x64 shell command line, the Target property value from the Netbeans Windows desktop shortcut:

$ "C:\Program Files (x86)\NetBeans 7.4\bin\netbeans.exe"

And then could finally create the respective debug and release object and executable files. I also modified the Netbeans project output to be within the MSYS2 directory structure. Then run the executable within the MSYS2 MinGW-x64 shell. Running from the Netbeans IDE produces this error message:

Unable to start pty process: The application failed with exit code -1073741515 (0xc0000135).

If the MSYS2 path were in the computer system's PATH environment variable, then perhaps this error would not happen.

查看更多
Fickle 薄情
3楼-- · 2019-01-11 21:49

I have just downloaded the latest automated build, unzipped it, added the main bin directory to path, and run:

x86_64-w64-mingw32-gcc test.cpp -o test.exe

and

x86_64-w64-mingw32-gcc -fuse-linker-plugin test.cpp -o test.exe

and it works. The same for the i686 variant. Your IDE is doing something wrong. Or you shouldn't have messed with the files. Or you shouldn't have removed the prefixes. Seriously.

PS: You only have to add the main "bin" directory to PATH, all the rest is wrong.

查看更多
我想做一个坏孩纸
4楼-- · 2019-01-11 21:52

Right, after months of putting this off I've finally sat down and done it. I'll probably make a more detailed post on my blog with pretty pictures but here is a trimmed down SO version which will hopefully be enough for you (and everyone else) to get going with.

Prerequisites

Remove MinGW, MSYS and CMake if you have them and can afford to lose them (we will reinstall MinGW (obv.) and MSYS but not CMake as it doesn't appear to be needed.)

  • Netbeans or other suitable IDE
  • 64bit Windows.
  • EnvMan (optional but handy for managing Windows Environment variables.)

Installation

MinGW-W64 C compiler and MSYS

Setup

  • Add 'C:\MinGW-W64\bin' to your Windows PATH variable.
  • Add 'C:\MSys\msys\bin' to your Windows PATH variable.
  • Start Netbeans and go to Tools -> Options -> C/C++.
    • Click 'Add' under 'Tool Collection' and select the base directory of MinGW-W64 (C:\MinGW-W64\bin).
    • Select 'MinGW' from 'Tool Collection Family' if it isn't auto-detected and click 'OK'.
    • Set the 'C Compiler to C:\MinGW-W64\bin\x86_64-w64-mingw32-gcc.exe.
    • Set the 'C++ Compiler to C:\MinGW-W64\bin\x86_64-w64-mingw32-g++.exe.
    • Set the 'Make Command' to C:\MSys\msys\bin\make.exe.

And that should be it!

I should note that I am using the system to compile a library file to be use via JNI so have some additional steps for that which I missed out as they weren't needed here. However I made a quick 'Hello World' program and it compiled and ran nicely.

Happy coding!

查看更多
登录 后发表回答