编译bottledwater时avro-c检测失败及Makefile相关问题咨询
1. How does the shell expand PG_CONFIG in your Makefile?
Let's break this down simply:
- Your Makefile first sets
PG_CONFIG = pg_config— this creates a variable pointing to PostgreSQL's built-in configuration tool,pg_config. - When the line
PGXS := $(shell $(PG_CONFIG) --pgxs)runs, the shell does two key things:- It resolves
$(PG_CONFIG)to the actualpg_configexecutable by searching your system'sPATHenvironment variable. - It runs
pg_config --pgxsdirectly in the shell, which outputs the full file path to PostgreSQL'spgxsmakefile (this is a standard extension that handles all the build rules for PostgreSQL add-ons).
- It resolves
- The output of that command gets saved to the
PGXSvariable, andinclude $(PGXS)pulls in that makefile to use PostgreSQL's official extension build setup.
To see this in action yourself, just run pg_config --pgxs directly in your terminal — it will print the exact path the Makefile is using.
2. How to configure your setup so Bottledwater detects your avro-c directory?
The error pops up because pkg-config can't find avro-c.pc — a metadata file it uses to locate libraries and headers. Since your compiled avro-c doesn't generate this file by default, here are three reliable fixes:
Option 1: Hardcode avro-c paths directly in the Makefile
Skip pkg-config entirely by replacing the AVRO_CFLAGS and AVRO_LDFLAGS lines with your actual avro-c paths:
AVRO_CFLAGS = -I/home/jholmes/avro-c-1.8.2/build/avrolib/include AVRO_LDFLAGS = -L/home/jholmes/avro-c-1.8.2/build/avrolib/lib -lavro
-Itells the compiler where to find avro-c's header files-Ltells the linker where to find avro-c's compiled libraries, and-lavrolinks against the avro library itself
Before running make, you may also need to set a temporary environment variable to ensure the linker can find the library at runtime:
export LD_LIBRARY_PATH=/home/jholmes/avro-c-1.8.2/build/avrolib/lib:$LD_LIBRARY_PATH
Option 2: Create a custom avro-c.pc file and point pkg-config to it
- First, make a
pkgconfigdirectory inside your avro-c lib folder:
mkdir -p /home/jholmes/avro-c-1.8.2/build/avrolib/lib/pkgconfig
- Create an
avro-c.pcfile in that directory with this content:
prefix=/home/jholmes/avro-c-1.8.2/build/avrolib exec_prefix=${prefix} libdir=${exec_prefix}/lib includedir=${prefix}/include Name: avro-c Description: Apache Avro C library Version: 1.8.2 Cflags: -I${includedir} Libs: -L${libdir} -lavro
- Tell
pkg-configwhere to find this file by setting thePKG_CONFIG_PATHenvironment variable:
export PKG_CONFIG_PATH=/home/jholmes/avro-c-1.8.2/build/avrolib/lib/pkgconfig:$PKG_CONFIG_PATH
- Now run
makeas usual —pkg-configshould locate avro-c without issues.
Option 3: Recompile avro-c with installation support
For a more permanent setup, recompile avro-c and install it to a dedicated path:
- Navigate to your avro-c source directory:
cd /home/jholmes/avro-c-1.8.2
- Run cmake with an installation prefix (adjust the path to your preference):
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/avro-c-1.8.2 .
- Compile and install:
make && sudo make install
This will generate an official avro-c.pc file in /usr/local/avro-c-1.8.2/lib/pkgconfig. Just add that directory to PKG_CONFIG_PATH before running make for Bottledwater.
内容的提问来源于stack exchange,提问作者MikiBelavista

