What is the reason of cmake error when using freetype2 header?

I build a simple glfw, glad project on vs code successfully. My issue is. I add <freetype2/ft2build.h> header to my project and I do those commands in my project folder:

sudo su
cd build
cmake ..
make

normally that works without error.

I get error called:

 In file included from /home/gomi/Documents/ubuntuProject/main.c:3: /usr/include/freetype2/ft2build.h:39:10: fatal error: freetype/config/ftheader.h: No such file or directory 39 | #include <freetype/config/ftheader.h> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~compilation terminated.

I went to usr/include/freetype2 path from terminal. If I remember correctly I seen only ft2build.h in directory no other config folder. I downloaded freetype2 files and I copied freetype folder to this directory and I got same error. In the end of I deleted copied freetype folder. I am not sure if they were already there and I damaged freetype2.

What I should do ?

4

2 Answers

As I stated, you shouldn't be running cmake and make as root but that appears to be a different issue.

As for your problem, first delete the file you added manually. Then, you can install the following package to fix the issue:

sudo apt update
sudo apt install --reinstall libfreetype6-dev

You can locate files like this using the apt-file command.

sudo apt update
sudo apt install apt-file
sudo apt-file update
apt-file search ftheader.h

This will return which package contains the file you need.

0

After searching for hours. I think I found it. First, that tries to search it in wrong directory unless you tell it to cmake.

I found it on this page :

  1. I just added to vs code's include directories /usr/include/freetype2

  2. I put header #include <ft2build.h> and FT_FREETYPE_H just after it, to my main.c file.

  3. I used pkg-config --cflags freetype2 command to ensure its location -I/usr/include/freetype2

  4. I went to CMakeLists.txt file then I added include_directories (/usr/include/freetype2) line. Final CMakeLists.txt file looks like this:

    cmake_minimum_required(VERSION 3.20.3)
    project(gomi)
    include_directories (/usr/include/freetype2)
    add_executable(${PROJECT_NAME} glad.c main.c)
    target_link_libraries(${PROJECT_NAME} GL dl glfw)
  5. My commands to re-build it:

    cd ../ # one path pack from build folder)
    rm -r build/* # delete all files in build)
    cd build
    cmake ..
    make
    ./myprogramname # runs
2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like