Tutorials/Compiling
Ah, so you've downloaded a search software but don't know what to do with that jumble of code. For this example, we will use gfind
Getting a Unix-ish command line for Windows Users
- Skip this section if you're using a Unix-compatible system.
Before you dive into compiling and you don't have a Unix-ish command line, you'll want to consider getting one like Cygwin or WSL.
Cygwin
Download Cygwin, the 64-bit one, click that link and then open the installer. While in the setup for packages, make sure to select the gcc-g++ and make and include their dependencies when asked.
Next you want to make a folder for your stuff. For this, make a folder in your (Your Cygwin root directory)\home\YourUsername folder (Where YourUsername is whatever username you use on your PC), let's call it C, and make a folder for the program in the C folder called gfind. Now put your gfind.c file there. Now moving on!
WSL2
If you are using Windows 10, there is a better alternative for Cygwin called Windows Subsystem for Linux (or WSL for short). Some reports indicate that WSL has shown better performance for apgsearch, for example. So let's set up a WSL instead — but wait a moment! WSL cannot work on computers that are too old. Specifically, WSL (or rather WSL 2) requires your system to be:
- For x64 systems: Version 1903 or higher, with Build 18362 or higher.
- For ARM64 systems: Version 2004 or higher, with Build 19041 or higher.
To check this out, open Command Prompt and enter systeminfo, which after a while will give you a list of information. The line starting with "System Type" tells whether your system is x64 or ARM64, and "OS Version" shows the version and build of your Windows 10. For some reason to be explained later, you need to note the total amount of physical memory (RAM) that is in the list as well.
Satisfying the aforementioned conditions, you can proceed to install WSL with internet connection. I followed the instructions here, which can be summarized as the step 1~5:
1. To enable WSL, open PowerShell (not Command Prompt!) as Administrator and run:
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
2. Following that, to enable Virtual Machine feature, run this and then restart your machine:
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
3. Download the Linux kernel update package here for x64 systems or here for ARM64 systems, and then execute it to install WSL 2 (select "yes" whenever required).
4. Back in PowerShell (this time not necessarily as admin), run this to set WSL as WSL 2:
wsl --set-default-version 2
5. Go to Microsoft Store for WSL and pick a Linux distribution to get and install. (For me, Ubuntu 20.04 works well.) Open it from the Start menu; wait a moment for completing some installations at first time, and then create a username and a password for Linux distribution.
- Note: here the username and password are both independent from that for Windows. Upper case is not allowed in the username. Password is invisible when typing — this is normal, don't simply close the window for that! It will be needed later, so make sure to memorize what have been typed.
If nothing is wrong, WSL should be ready. The next step is to download tools to prepare for future compiling.
6. In the console, run these commands one by one (with password just created)
sudo apt update
sudo apt upgrade
sudo apt-get install build-essential
The last one above contains many useful programs such as make, git, gcc-g++, and so on. In case of apgsearch, python3 is required as well so:
sudo apt-get install python3
Technically we are done now, but it may be handy to have a shortcut to get access to the files.
7. In the console, run:
explorer.exe .
(Note the space and period at the end!) Soon a Windows file explorer will pop up and provide a view of the relevant files. Later everything from git clone will end up at the home/<username> directory, so make a desktop shortcut or something similar for that.
Finally, there is an important precaution that is worth mentioning here.
8. Caveat: the virtual machine inside WSL may consume a whopping amount of memory in prolonged runs per this github issue. To prevent that, go to the Windows user directory (like C:\Users\<username>) and create a .wslconfig file including several settings:
[wsl2] memory=4GB swap=0 localhostForwarding=true
In this example, the virtual machine is limited to fetch at most 4GB memory. The number should be modified according to the available physical memory on your computer. The effect of this setting should be visible with command free -h.
Congratulations! You are now equipped with the WSL. The rest of things to do is similar to that for Cygwin.
Compiling the Code
Now we can actually compile. In the terminal, type in the following:
cd /C/gfind
You should now see a yellow little thing that says "~/gfind", this means you are in the folder. Now, to compile, type:
gcc -O3 -o gfind gfind.c
It will pause for a while, there might be some warnings, but don't worry. After the command line comes back... done! You've compiled gfind. To use it, do
./gfind
You can do this for any other C program, just replace gfind with the program (e.g. zfind). Some programs have different commands for compilation, those commands are usually available in the README.
Examples you can try
- gfind.c
- ntzfind
- gencols.c
- afind (Note: This is C++, compile command in the file)
- ofind
- torus
- zfind (Note: This is the zfind thread)
| |||||||||||||||||