DEV Community

kojix2
kojix2

Posted on

1

How to Fix the 'argp.h' Not Found Error on macOS

When compiling a Linux-oriented tool written in C/C++ on macOS, you might encounter the following error:

fatal error: 'argp.h' file not found
#include <argp.h>
         ^~~~~~~~
1 error generated.
Enter fullscreen mode Exit fullscreen mode

This means that the library for parsing command-line arguments, argp.h, is missing.

Solution

Fortunately, you can install this library using Homebrew.

brew install argp-standalone
Enter fullscreen mode Exit fullscreen mode

After installing, verify the files:

brew ls argp-standalone
Enter fullscreen mode Exit fullscreen mode
/opt/homebrew/Cellar/argp-standalone/1.3/include/argp.h
/opt/homebrew/Cellar/argp-standalone/1.3/lib/libargp.a
/opt/homebrew/Cellar/argp-standalone/1.3/sbom.spdx.json
Enter fullscreen mode Exit fullscreen mode

Since there is no .pc file, you can't use pkg-config. Instead, you need to specify the paths directly.

cc hoge.c \
  -largp \
  -L /opt/homebrew/Cellar/argp-standalone/1.3/lib/ \
  -I /opt/homebrew/Cellar/argp-standalone/1.3/include/ \
  -o hoge
Enter fullscreen mode Exit fullscreen mode

With these steps, you should be able to resolve the issue of missing argp.h on macOS.

Speedy emails, satisfied customers

Postmark Image

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay