Ubuntu 16.4下编译Libigl Example 102遇错误求助
Hey there, let’s work through this compilation issue step by step—Libigl can be picky with dependencies and setup, so we’ll cover the most common pitfalls first.
First, Verify Core Dependencies
1. Check Eigen Compatibility
Libigl relies heavily on Eigen, and Ubuntu 16.04’s default Eigen version (3.2.x) might be too old for newer Libigl commits. Let’s confirm your installed version:
grep "#define EIGEN_WORLD_VERSION" /usr/local/include/Eigen/src/Core/util/Macros.h
If the output shows EIGEN_MAJOR_VERSION < 3 (or a full version older than 3.3.x), you’ll need to upgrade Eigen. You can download the latest 3.3.x+ release, extract it, and either:
- Copy the
Eigenfolder to/usr/local/include(overwriting the old version if safe) - Or specify its parent directory explicitly during CMake configuration (we’ll cover this next)
2. Ensure Libigl Submodules Are Fully Initialized
Even with git clone --recursive, network issues can leave submodules like GLFW, ImGui, or TetGen incomplete. Fix this by navigating to your Libigl root directory and running:
git submodule update --init --recursive
This ensures all example-specific dependencies are pulled correctly—critical for Example 102’s viewer component.
Correct Compilation Workflow for Example 102
The official note says examples can be compiled independently, but let’s follow the most reliable out-of-source build workflow:
- Navigate to the Example 102 directory:
cd libigl/examples/102_Viewer - Create a dedicated build folder (avoids clutter and build cache conflicts):
mkdir build && cd build - Run CMake with explicit flags to eliminate ambiguity:
cmake .. -DCMAKE_BUILD_TYPE=Release -DEIGEN_INCLUDE_DIR=/usr/local/include -DCMAKE_CXX_STANDARD=11-DEIGEN_INCLUDE_DIR=/usr/local/include: Forces CMake to use your installed Eigen (points to the folder containing theEigensubdirectory)-DCMAKE_CXX_STANDARD=11: Ensures compatibility with Ubuntu 16.04’s GCC 5.4.0 (which supports C++11 but requires explicit enabling)
- Compile with parallel jobs to speed things up:
make -j$(nproc)
Fix Common Linker/Compiler Errors
- "Undefined reference to GLFW functions": If you hit this, install system-wide GLFW as a fallback:
Re-run CMake and make after installation.sudo apt-get install libglfw3-dev libglfw3 - "Eigen/Core: No such file or directory": Double-check the
-DEIGEN_INCLUDE_DIRpath—it should point to the parent folder of theEigendirectory (e.g.,/usr/local/include, not/usr/local/include/Eigen). If issues persist, add the path to your environment temporarily:
Then re-run CMake.export CMAKE_PREFIX_PATH=/usr/local/include:$CMAKE_PREFIX_PATH source ~/.bashrc
If you still run into errors, sharing the exact compiler output will help narrow things down—but these steps resolve 90% of common Libigl compilation issues on Ubuntu 16.04.
内容的提问来源于stack exchange,提问作者Allens

