Gregg's MOTD

Tips & Tricks that I've Encountered Over the Years...

Setting Up Git to Ignore ELF Binaries (C/C++ Output on Linux)

August 16, 2023 — Gregg Szumowski

The starting point for this experiment was from here

An Example using C Program Source

Let’s say we have a pre-existing directory of some C source code files:

$ ls
Makefile print print.c print.h print.o

And we initialize a new git repository in that directory:

$ git init
Initialized empty Git repository in /home/user/tmp/printer/.git/

$ cat .gitignore
# Ignore all
*

# Unignore all with extensions
!*.*

# Unignore all dirs
!*/

# Unignore make files
!Makefile

# Ignore .o files
*.o

# Ignorebindir
bin/
# or
*/bin/*

Let’s see how we did:

$ git status
On branch master

No commits yet

Untracked files:
(use "git add <file>..." to include in what will be committed)
.gitignore
Makefile
print.c
print.h

nothing added to commit but untracked files present (use "git add" to track)

So the print and the print.o files are not showing up, which was our initial goal.

You may have to tweak the settings in the above .gitignore file to your own situation, but as you can see it is possible to setup git to ignore the ELF binaries output by gcc. I would probably also add a.out to the list of unignored files just to cover those times when you’re not using a Makefile. YMMV.

Tags: cli, git, gcc, motd

GCC can’t find stdio.h in Alpine Linux

June 29, 2023 — Gregg Szumowski

A while ago, I installed the iSH app on my iPad which made it possible for me to develop Python and C code as well as use it as an SSH client. However, I ran into an issue when trying to compile C code because the compiler couldn’t resolve stdio.h. The following excerpt from StackOverflow resolves the issue:

Install libc-dev in addition to GCC, or just install build-base for everything (alpine-sdk is probably an overkill). To install run the following command:

# apk add libc-dev

You need to install it separately because in Alpine Linux, the package GCC doesn’t depend on libc-dev for good reason: You can use gcc to compile things without libc, for example hypervisors firmware etc.

Tags: gcc, alpine-linux, ipad, ish, motd