0

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 2

1

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.

NOTE: On 20.04, the package that contains the file is libfreetype-dev however, this package is a dependency of libfreetype6-dev so it should all work just the same.

Also, the path shown by apt-file is the same one requested by /usr/include/freetype2/ft2build.h on line 39 with respect to the working directory of that file. So you shouldn't have to tell cmake where to look for this file and you shouldn't have to put a copy in /usr/include/freetype2

0
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 : https://techoverflow.net/2019/06/11/how-to-fix-ft2build-h-no-such-file-or-directory/

  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
  • 1
    You should probably be using find_package and then setting target_include_directories with the found FREETYPE_INCLUDE_DIRS value, instead of hard-coding include_directories (/usr/include/freetype2) (that's kind of the point of cmake - to locate things in a system-agnostic way). See for example Linking freetype with cmake Jun 21, 2021 at 12:02
  • @steeldriver Thank you, I did proper modifications. I just did not use SET(CMAKE_CXX_FLAGS "-O2 -std=c++11") rest of that works without any problem. Jun 21, 2021 at 20:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .