使用 conda 的 CMake 找不到包含目录

CMake using conda can't find include directory

我正在尝试使用 CMake 来编译 C++ 程序。我正在使用与 Anaconda(特别是 miniconda3)一起安装的 CMake。编译时,Anaconda 无法找到 /usr/include/

中包含的 header

我的主要 CPP 文件如下所示:

// Include standard headers
#include <stdio.h>
#include <stdlib.h>
#include <iostream>

#include "dna.h"
#include <GLFW/glfw3.h>

int main() {
  std::cout << "Version " << DNA_VERSION_MAJOR << "." << DNA_VERSION_MINOR << std::endl;
  return 0;
}

具体来说,我正在尝试访问名为 GL/gl.h 的 header,它位于 /usr/include/GL/gl.h

我的 CMakeList.txt 文件如下所示:

cmake_minimum_required(VERSION 3.11)
project(DNA VERSION 1.0)
# specify the C++ standard
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
configure_file(dna.h.in dna.h)
include_directories("/usr/include/")
add_executable(dna-viz main.cpp dna.h)
target_include_directories(
        dna-viz PUBLIC 
        "${PROJECT_BINARY_DIR}"
        "${CONDA_PREFIX}/include"
    )

我在运行mkdir build && cd build && cmake ..时的错误如下:

make[1]: Entering directory '/home/debesh/general/dna-vis/build'
make[2]: Entering directory '/home/debesh/general/dna-vis/build'
Scanning dependencies of target dna-viz
make[2]: Leaving directory '/home/debesh/general/dna-vis/build'
make[2]: Entering directory '/home/debesh/general/dna-vis/build'
[ 50%] Building CXX object CMakeFiles/dna-viz.dir/main.cpp.o
In file included from /home/debesh/general/dna-vis/build/dna.h:4:0,
                 from /home/debesh/general/dna-vis/main.cpp:6:
/home/debesh/miniconda3/include/GLFW/glfw3.h:210:12: fatal error: GL/gl.h: No such file or directory
   #include <GL/gl.h>
            ^~~~~~~~~
compilation terminated.
make[2]: *** [CMakeFiles/dna-viz.dir/build.make:80: CMakeFiles/dna-viz.dir/main.cpp.o] Error 1
make[2]: Leaving directory '/home/debesh/general/dna-vis/build'
make[1]: *** [CMakeFiles/Makefile2:93: CMakeFiles/dna-viz.dir/all] Error 2
make[1]: Leaving directory '/home/debesh/general/dna-vis/build'
make: *** [Makefile:101: all] Error 2

这是因为GL/gl.hGLFW/glfw3.h安装在不同的地方吗?

我已经使用 conda install 安装了大量不同的 xorg-*mesagl 软件包,但这仍然无法正常工作。

这些错误告诉您缺少库。

fatal error: GL/gl.h: No such file or directory #include <GL/gl.h> 您需要安装 mesalib.

对于 Linux 上的 Gl/gl.h 使用:

sudo apt install mesa-common-dev

或使用conda install mesalib