How to build a window executable bin for linux project - mingw-w64

I have a project writen with C99. It links to libcurl, generate makefile with cmake. Now, i want to explore the project to window env. I tried cygwin first, everything works except that final user need to install cygwin too.
After some search, mingw64 may archive my goal (build and use directly in window), but i could not find a full use guild for how to build linux project with mingw64 in ubuntu(linux).
Thanks for the help.

After some research, a solutions works:
install window cmake
install mingw-w64
mkdir build && cd build && cmake -G "MinGW Makefiles" ..
mingw32-make
MinGW may not support all API, some compatible job should be done.

Related

Golang: How to cross compile on Linux for Windows

How do I cross compile a Go project on Linux to generate an executable for running on Windows?
To build from Linux to Windows, you need to set the environment variables GOOS to Windows and GOARCH to amd64.
On Bash or ZSH:
% GOOS=windows GOARCH=amd64 go build
For more details see: https://dave.cheney.net/2015/08/22/cross-compilation-with-go-1-5
A description of possible values for GOOS and GOARCH is available here: https://golang.org/doc/install/source#environment
If your package requires CGO then you need to use the mingw-w64 compiler:
sudo apt-get install gcc-multilib
sudo apt-get install gcc-mingw-w64
GOOS=windows GOARCH=386 \
CGO_ENABLED=1 CXX=i686-w64-mingw32-g++ CC=i686-w64-mingw32-gcc \
go build
Introduction
During your production process you may want to build your go program to support a windows architecture, but this is not always easy but here's a guide to help you building your go program for windows
CGO
Cgo is an element of go that allow Go packages to call C code.
But whether you're using CGO or not is not as easy as "did I called C code?" because while you may not have called C code in you Go program, a package that you're using probably does.
To figure it out the easiest thing is to try without and if it's not working try the second option. (But you can also try this if you want to)
If you don't need CGO
if you don't need CGO, building your go program to another platform is pretty easy as go natively support cross-platform compiling.
all you need to do is this:
x64
#Compile your go program to the windows x64 platform
env GOOS=windows GOARCH=amd64 go build package-import-path
x32
#Compile your go program to the windows x32 platform
env GOOS=windows GOARCH=386 go build package-import-path
Tip: Since go natively support cross compiling, you can easily build your program to other platform as well, further reading here
If you need CGO
if you need CGO, building your program will be a little bit more complicated since C doesn't support native cross-platform compiling..
But don't worry! It is still pretty easy using the MinGW64 project.
Requirements
Since we will be using mingw64 to build our project, we'll need to make sure mingw is installed.
If it's not here's how you can install it:
Ubuntu
On ubuntu simply run:
sudo apt-get install gcc-mingw-w64
Fedora
On fedora simply run:
sudo dnf install mingw64-gcc
Build
Now that we met the requirements, we can now build our project
For windows x64 architecture
To build your program on a windows x64 architecture run:
GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CXX=x86_64-w64-mingw32-g++ CC=x86_64-w64-mingw32-gcc go build package-import-path
For windows x32 architecture
To build your program on a windows x32 architecture run:
GOOS=windows GOARCH=386 CGO_ENABLED=1 CXX=i686-w64-mingw32-g++ CC=i686-w64-mingw32-gcc go build package-import-path

How to uninstall LLVM?

I installed LLVM from source (using CMake and make install) but I am unable to uninstall it because there is no make uninstall avalaible.
This is LLVM version 3.5.2.
I use ArchLinux.
How can I uninstall LLVM in an automated way?
From the CMake FAQ / Can I do "make uninstall" with CMake :
...Unix users could enter this command in the shell:
xargs rm < install_manifest.txt
(after you cd to the LLVM build directory).

How do I run GNU Typist/gtypist on a Mac?

I'm a little familiar with command line but I'm still having problems running GNU Typist/gtypist. http://www.gnu.org/software/gtypist/
Can anyone give me really basic step-by-step instructions for a Mac?
Install using Homebrew
brew install gnu-typist
gtypist
You can also install it directly from the sources (note that for building from the sources you have to install XCode - it's free and you can download it from App Store):
Get the source of gnu typist
http://ftp.gnu.org/gnu/gtypist/gtypist-2.9.tar.gz
Get the source of ncurses
I am downloading it from GNU pages here:
ftp://ftp.gnu.org/gnu/ncurses//ncurses-6.0.tar.gz.sig
But you can get most recent version directly from maintainer's page:
ftp://ftp.invisible-island.net/ncurses/ncurses.tar.gz
Create place where you want to have all the stuff
mkdir ~/opt/usr
Build ncurses - pay attention to --enable-widec
./configure --enable-widec --with-shared --prefix=$HOME/opt/usr/
make; make install
Build gnutypist
export LDFLAGS="-L$HOME/opt/usr/lib"
export CFLAGS="-I$HOME/opt/usr/include"
./configure --prefix=$HOME/opt/usr/
make; make install
Run gnutypist
cd $HOME/opt/usr/bin
./gtypist
Alternatively to brew you can use MacPorts (macos package manager)
Installation command:
sudo port install gtypist
Link to the port summary page:
https://ports.macports.org/port/gtypist/summary

How can I install MinGW-w64 and MSYS2?

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.

cygwin newbie compiling and running c program files

I just installed cygwin, latest version. wanted to compile and run a simple file. when i open cygwin terminal and type any of the commands :gcc,cc,g++ it says command not found. what am I missing here
You're missing the gcc, cc, and g++ commands.
Not all packages are installed by default. You need to run setup.exe again and select gcc and gcc-g++ for installation. You'll find them under the Devel (development) category.

Resources