Issue
I am trying to use CMake to compile a C++ program. I am using CMake installed with Anaconda (specifically miniconda3). When compiling, Anaconda isn't able to find headers contained in /usr/include/
My main CPP file looks like this:
// 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;
}
Specifically, I am trying to access the header called GL/gl.h
which is found at /usr/include/GL/gl.h
My CMakeList.txt
file looks like this:
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"
)
My error when running mkdir build && cd build && cmake ..
is as follows:
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
Is this because GL/gl.h
and GLFW/glfw3.h
are installed in different places?
I have installed a load of different xorg-*
and also mesagl
packages using conda install
but this still isn't working.
Solution
Those errors are telling you that you are missing a library.
fatal error: GL/gl.h: No such file or directory #include <GL/gl.h>
You need to install mesalib
.
For Gl/gl.h
on Linux use:
or sudo apt install mesa-common-dev
or use conda install mesalib
Answered By - Geno C Answer Checked By - Marilyn (WPSolving Volunteer)