I am interested in taking my C++ program and cross compiling it into something that can run on an ARM MCU. To do this, I am required to have gcc-arm-none-eabi installed. I'm currently on a Windows 7 machine, and so I have installed GCC/make/g++/etc. via MinGW.
From the research I've done, it seems that MinGW does not support this toolchain, which leads me to believe that Windows-based ARM development isn't possible. So I ask: how does one use MinGW to install the gcc-arm-none-eabi toolchain locally?
You can use MinGW for this; you just need to swap out the C++ toolchain for your chosen one. You can still invoke it from the MSYS console, and all your other tools will still work. There's nothing inherent to MinGW or MSYS that makes this "not supported".
Personally I install GCC 4.9 gcc-arm-none-eabi from launchpad.net, mount the toolchain's directory in MSYS then export the paths I need:
mount 'C:\PROGRA~2\GNUTOO~1\4947E~1.920' /foo
mount 'C:\PROGRA~2\GNUTOO~1\4947E~1.920\ARM-NO~1' /foo_local
To discover the short name for the paths, write dir /X at the Windows command prompt. On my machine, the paths above are equivalent to the following, respectively:
C:\Program Files (x86)\GNU Tools ARM Embedded\4.9 2014q4
C:\Program Files (x86)\GNU Tools ARM Embedded\4.9 2014q4\arm-none-eabi
The mounting only needs to be done once; the export directives may be added to /etc/profile:
export CPPFLAGS="-I/foo_local/include"
export CFLAGS="-I/foo_local/include"
export CXXFLAGS="-I/foo_local/include"
export LDFLAGS="-L/foo_local/lib -mthreads"
export PATH=".:/foo_local/bin:/foo/bin:/bin:/opt/bin"
Then just run g++.
Or of course you can skip all the export business and just invoke your chosen GCC directly:
/foo/bin/g++
If you're using MSYS2, MinGW compliance, you'll be able to install arm-none-eabi-gcc through pacman
You can download it from here: https://www.msys2.org
Follow the instructions to properly setup the environments.
Then use this commands below
pacman -S mingw-w64-x86_64-arm-none-eabi-gcc mingw-w64-x86_64-libwinpthread-git
now you'll also need to add this into PATH,
echo "export PATH=$PATH:/mingw64/bin" >> ~/.bashrc
source ~/.bashrc
Then, you can now call arm-none-eabi-gcc with the MSYS2 shell.
See here for the details of this package https://packages.msys2.org/group/mingw-w64-x86_64-arm-none-eabi-toolchain
ELLCC is another option. You don't necessarily need mingw or mingw-64 installed to run it since it is statically linked. This post talks about using it to target Windows, but the same binary can also be used to target ARM and other processors. It's based on clang/LLVM though, not gcc.
Related
I develop c++ apps on linux and i use neovim with coc.nvim and coc-clangd plugins.
I want to develop an app for windows but i comfort with linux and neovim so i want to use them for it. But i get some include errors with some windows headers (etc. "windows.h").
I use linux only for writing the code and i'll compile the program on windows. How can i prevent this errors and use windows headers with coc.nvim?
i'll compile the program on windows
You can cross-compile it from Linux. It's only marginally more difficult than getting the code completion to work.
Get the standard library headers (and libraries, if you want to cross-compile) from MinGW.
Your package manager might have those, or you can get them from https://winlibs.com/.
I prefer getting those from MSYS2, and made scripts to automate this (since MSYS2 is otherwise Windows-only):
git clone https://github.com/holyblackcat/quasi-msys2
cd quasi-msys2/
make install _gcc
Figure out the Clang flags needed to cross-compile.
Unlike GCC, which for every target platform requires a separate compiler distribution, Clang is inherently a cross-compiler. You only need a single Clang distribution to compile for any supported platform.
Download Clang from your package manager, and point it to the freshly downloaded headers and libraries.
Following flags work for me: clang++-14 1.cpp --target=x86_64-w64-mingw32 --sysroot=/path/to/quasi-msys2/root/mingw64 -fuse-ld=lld-14 -pthread -stdlib=libstdc++ -femulated-tls -rtlib=libgcc.
--target and --sysroot are crucial. The latter needs to point to the files you've downloaded. The remaining flags are less important.
Running this should produce a.exe, runnable with wine a.exe.
Feed the same flags to Clangd.
There are several ways to set compiler flags for Clangd.
The easiest one is to create a file named compile_flags.txt in your project directory, and put the flags into it, one per line:
--target=x86_64-w64-mingw32
--sysroot=/path/to/quasi-msys2/root/mingw64
-fuse-ld=lld-14
-pthread
-stdlib=libstdc++
-femulated-tls
-rtlib=libgcc
Then Clangd should do the right thing for any source files in this directory.
Apparently, my Quasi-MSYS2 can somewhat automate this.
After running the commands above (make install _gcc and others), run make env/shell.sh, and run your editor from this shell.
Replace compiler_flags.txt with compiler_commands.json with following contents:
[
{
"directory": "/your/sources",
"file": "/your/sources/1.cpp",
"command": "win-clang++ 1.cpp"
}
]
Where win-clang++ is a Clang wrapper I ship, which automatically adds the flags I listed above.
Configure your editor to add following flag to Clangd: --query-driver=/path/to/win-clang++ (use which win-clang++ from quasi-msys2 shell to get the full path).
This makes Clangd obtain the right flags automatically from this wrapper.
You can't use windows.h while you're compiling a Linux native application. If want to make your application platform ready and you're using some kind of OS native cals, then you have to probably use defines like #if _WIN32/__linux__ and so on. At the end, you can cross-compile your application to Windows while you're running on Linux as well.
I am trying to build some open source library. I need a package management system to easily download the dependencies. At first I am using MinGW and MSYS. But the included packages are limited. Someone told me to use Mingw-w64 and MSYS2.
I downloaded the mingw-w64-install from here. When running, it reports the following error. How can I fix it?
And by the way, from the Mingw-w64 download page, I see a lot of download links. Even Cygwin is listed. How are Cygwin and Mingw-w64 related?
My current understanding is, in the time of MinGW and MSYS, MSYS is just a nice addon to MinGW, while in Mingw-w64 + MSYS2, MSYS2 is stand-alone and Mingw-w64 is just a set of libraries it can work with. Just like Cygwin can download many different packages.
Unfortunately, the MinGW-w64 installer you used sometimes has this issue. I myself am not sure about why this happens (I think it has something to do with Sourceforge URL redirection or whatever that the installer currently can't handle properly enough).
Anyways, if you're already planning on using MSYS2, there's no need for that installer.
Download MSYS2 from this page.
After the install completes, click on the MSYS2 UCRT64 in the Start menu (or C:\msys64\ucrt64.exe).
If done correctly, the terminal prompt will say UCRT64 in magenta letters, not MSYS.
Update MSYS2 using pacman -Syuu. If it closes itself during the update, restart it and repeat the same command to finish the update.
You should routinely update your installation.
Install the toolchain: (i.e. the compiler and some extra tools)
pacman -S mingw-w64-ucrt-x86_64-toolchain
Install any libraries/tools you may need. You can search the repositories by doing
pacman -Ss name_of_something_i_want_to_install
e.g.
pacman -Ss gsl
and install using
pacman -S package_name_of_something_i_want_to_install
e.g.
pacman -S mingw-w64-ucrt-x86_64-gsl
and from then on the GSL library will be automatically found by your compiler!
Make sure any compilers and libraries you install have this package prefix: mingw-w64-ucrt-x86_64-. Only use unprefixed packages for misc command-line utilities (such as grep, sed, make, etc), unless you know what you're doing.
Verify that the compiler is working by doing
gcc --version
If you want to use the toolchains (with installed libraries) outside of the MSYS2 environment, all you need to do is add C:/msys64/ucrt64/bin to your PATH.
MSYS2 provides several compiler flavors, UCRT64 being one of them. It should be a reasonable default.
MSYS has not been updated a long time. MSYS2 is more active, and you can download it from MSYS2. It has both the mingw and cygwin fork package.
To install the MinGW-w64 toolchain (reference):
Open the MSYS2 shell from the start menu
Run pacman -Sy pacman to update the package database
Reopen the shell, and run pacman -Syu to update the package database and core system packages
Reopen the shell, and run pacman -Su to update the rest
Install the compiler:
For a 32-bit target, run pacman -S mingw-w64-i686-toolchain
For a 64-bit target, run pacman -S mingw-w64-x86_64-toolchain
Select which package to install; the default is all
You may also need make. Run pacman -S make
You can now also get the stand-alone personal build of MinGW-w64 from https://winlibs.com/ which doesn't require any installation; just extract and its ready to use. This allow having multiple toolchains on the same system (e.g., one for Windows 32-bit and another for Windows 64-bit).
The most straightforward way, as far as I know, is to use Chocolatey to install MinGW:
choco install mingw
Then check with the command whereis gcc. It is going to be installed in C:\ProgramData\chocolatey\bin.
one more thing, to get make working, just copie (or rename if you wish)
with copy mingw32-make.exe make.exe in C:\ProgramData\chocolatey\bin.
I have been using the minGW64 compiler with Visual studio code on windows for some time. However, there are certain limitations to it when it comes to certain libraries. The absence of a make tool and the inability to execute a config script while compiling a c++ program being the main ones. I came to know of MSYS, a tool provides a UNIX environment that allows us to do certain things that are forbidden by the windows terminal. I installed it but I saw that I need to install mingw64 again, from within the terminal to use it with MSYS2.
My question is, is there no way I can use my earlier mingw copy with this installation of MSYS2? Is there some difference between the mingw64 that comes with MSYS2 and the standard installation?
I installed the C++ compiler MinGW following this tutorial, but when i used the consol commands:
> gcc --version
g++ (GCC) 4.8.1
......
> g++ --version
g++ (GCC) 4.8.1
......
> gdb --version
GNU gdb (GDB) 7.6.1
i dont receive any information and the console prints 'gcc is not recognizable as internal or external command'
When you execute step 3:
Setup environment variable PATH to include "<MINGW_HOME>/bin" where <MINGW_HOME> is the MinGW installed directory that you have chosen in the previous step.
Be aware that changes made to your path in the control panel don't affect existing consoles.
You need to open up a new console for the path to affect it.
The other possibility is that you've modified the path in a console you were working in but this is the wrong way to do it, since that path will not affect future consoles.
You most likely missed this step:
Setup environment variable PATH to include "<MINGW_HOME>/bin" where <MINGW_HOME> is the MinGW installed directory that you have chosen in the previous step.
What is the output of this command?
echo $PATH
If it does not include "<MINGW_HOME>/bin", you need to make the necessary adjustment.
Besides, that tutorial is somewhat dated. Cygwin Ports does include packages for MinGW, plus precompiled libraries, available from Cygwin's setup.exe. The packages are:
mingw64-i686-gcc
mingw64-i686-gcc-g++
or
mingw64-x86-gcc
mingw64-x86-gcc-g++
depending on your architecture. If you use those packages, the compiler will be installed in /usr/bin (which already is in your PATH), and you can access it (e.g. as i686-w64-mingw32-gcc) right away.
I've gone to http://sourceforge.net/project/showfiles.php?group_id=2435, downloaded the Automated MinGW Installer for MinGW 5.1.4 and at the same time the GNU Source-Level Debugger Release Candidate: GDB 6.8-3. I've then installed MinGW base tools into C:\MinGW. No problem so far.
However when I come to install the gdb debugger it has a lot of files and folders with the same names as some already installed but the files are different to those already installed. e.g C:\MinGW\include\bfd.h is 171 KB but gdb-6.8-mingw-3\include\bfd.h is 184 KB.
How do I add gdb to MinGW without breaking what's already installed?
In a command prompt I browsed to C:\MinGW\bin and ran:
mingw-get.exe install gdb
That fixed it for me. Not sure if it matters but I have C:\MinGW\bin in my path (guess I probably didn't need to browse to C:\MinGW\bin).
The Current Release (5.2.1) version of gdb at the project files page has always worked for me. The download is a stand-alone .exe, you don't need anything else.
But I'll bet the .exe in the 6.8 package will work, too. I'd try using just the .exe, and then if there are problems, try extracting the other files from the 6.8 package. (Though that may cause problems with the rest of the MinGW installation.)
Update: There seems to be a 7.something version. I haven't tested it thoroughly, but it seems to work, even with gcc 3.
Get Wascana Desktop Developer. It combines MinGW, gcc, Eclipse and gdb in one package.
You can safely overwrite the files prepackaged with MinGW with the (newer) ones from the gdb tarball. You can also choose not to overwrite them - just make sure to pick either one set, i.e. avoid mixing files from the older and the newer package.
Most of the offending files are probably not really relevant to you anyway. For example, the files belonging to the libbfd library aren't required for gdb's day to day operation, they're used if you want to extend the debugger or write debugging tools yourself.
At any rate, make a backup of the mingw directory before untarring the new release. It's very easy since MinGW is self-contained in that directory. That way, if anything should malfunction, you can just delete the directory and restore from the backup.
Usually for installing gdb in windows, You have to 2 ways to install:
1) use ready-made binaries that were build and compiled from GNU gdb by some provider (easy to install)
use TDM-GCC binaries provided from the following URL and that is including inturn the gcc complier and also gdb debugger.
http://tdm-gcc.tdragon.net/
use Equation package inside which GNU GDB was already compiled and built.
http://www.equation.com/servlet/equation.cmd?fa=gdb
2) use minimal mingw or cygwin package then after install gdb inside it.
Install either mingw or cygwin inside which GDB is already shipped
Open cygwin or mingw terminal and just type the following to make sure it is already installed
$ gdb --version
Hint: if you did not find gdb installed, simply open the cygwin or mingw package installer and make sure you already check gdb
Hint: getting and installing a debug build of the OHRRPGCE is providing useful information about crashes.
From cygwin or mingw terminal, Start gdb using the following
c:\mingw\bin\gdb.exe program_to_debug.exe
REF: http://rpg.hamsterrepublic.com/ohrrpgce/GDB_on_Windows
The TDM GCC/MinGW32 builds installer includes gdb. It's gcc 4.4.x with all the core binary packages required for basic Windows development, and is widely used without any unusual problems.