You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

树莓派C++ Web项目编译GNU CGI库报错:找不到CgiDefs.h

Fixing "cgicc/CgiDefs.h no such file" and Library Linking Issues on Raspberry Pi

Hey there, let's work through this problem together. The root cause here is that you've only installed the runtime library (libcgicc3) for CGI C++, but you're missing the development files needed to compile code against this library. Here's how to resolve it step by step:

Step 1: Install the CGI C++ Development Package

On Debian-based systems like Raspberry Pi OS, runtime libraries and their corresponding development files are split into separate packages. To get the missing header files (like CgiDefs.h) and linker-friendly library files, install the libcgicc-dev package:

sudo apt-get update && sudo apt-get install libcgicc-dev

Step 2: Verify the Files Are Now Available

After installation, confirm the missing header file exists:

ls /usr/include/cgicc/CgiDefs.h

You should see the file listed. To locate the library files, run:

sudo find / -name "libcgicc.*"

On Raspberry Pi's ARM architecture, you'll likely find them in /usr/lib/arm-linux-gnueabihf/—either as a dynamic library (libcgicc.so) or static library (libcgicc.a).

Step 3: Compile Your Code Correctly

Now you have two reliable ways to compile your CGI program:

pkg-config automatically handles header paths and library links for you. Run this command:

g++ -o cform.cgi cform.cpp `pkg-config --cflags --libs cgicc`

The backticks (`) tell the shell to execute the pkg-config command and pass its output as arguments to g++. This will include the correct header directories and link against the cgicc library without manual path hunting.

Option 2: Manual Compilation Flags

If you prefer to specify paths manually, use the -I flag to point to the header directory and -l to link the library:

g++ -o cform.cgi cform.cpp -I/usr/include/cgicc -lcgicc
  • -I/usr/include/cgicc: Tells g++ where to find the cgicc header files.
  • -lcgicc: Links against the cgicc library (the linker will automatically locate the appropriate .so or .a file).

Why This Worked

The original libcgicc3 package only includes files needed to run existing CGI programs, not to compile new ones. The libcgicc-dev package adds the header files, static libraries, and configuration files required for development.

内容的提问来源于stack exchange,提问作者user3525290

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.09 10:27:46