Ubuntu 16.04编译PJSIP时遇‘EAGAIN未声明’错误求助
I’ve run into this exact issue before when compiling PJSIP on Ubuntu 16.04 LTS 64-bit—when you run make, the compiler throws an error saying EAGAIN is undeclared in the pj_ioqueue_recv function, linked to the PJ_BLOCKING_ERROR_VAL macro in os_auto.h. Let’s break down how to fix this:
Why this happens
Ubuntu 16.04 uses GCC 5, and there’s a small mismatch in PJSIP’s compatibility header logic. EAGAIN is typically defined in <unistd.h> or <errno.h>, but the include order in PJSIP’s source files isn’t pulling it in properly before the macro tries to reference it.
Solutions to try
1. Patch the PJSIP compatibility header
Edit the file ../include/pj/compat/os_auto.h:
- Scroll to the line where
#define PJ_BLOCKING_ERROR_VAL EAGAINis declared (around line 149 in your case). - Right above that line, add these lines to ensure
EAGAINis defined:
Alternatively, you can just add an include for#ifndef EAGAIN #define EAGAIN EWOULDBLOCK #endif<unistd.h>at the top of the file, since it reliably includes theEAGAINdefinition on Linux systems.
2. Pass the definition directly via configure
If you don’t want to modify the source files, you can define EAGAIN during the configure step:
./configure CFLAGS="-DEAGAIN=EWOULDBLOCK"
Then run make clean && make to rebuild from scratch. On Linux, EAGAIN and EWOULDBLOCK are functionally equivalent, so this works as a quick workaround.
3. Ensure system development packages are installed
Sometimes missing basic system headers can cause this issue. Make sure you have all the required build dependencies installed:
sudo apt-get update && sudo apt-get install build-essential libssl-dev libasound2-dev
This ensures you have the full set of standard C library headers and tools needed for compiling PJSIP.
After trying any of these steps, re-run make—the error should be gone, and compilation should proceed normally.
内容的提问来源于stack exchange,提问作者Rashed

