Score:0

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

pr flag

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 ?

Knud Larsen avatar
by flag
File list 18.04 https://packages.ubuntu.com/bionic/amd64/libfreetype6-dev/filelist .... File list 20.04 https://packages.ubuntu.com/focal/amd64/libfreetype-dev/filelist
mchid avatar
bo flag
You shouldn't be using `sudo` or root for `cmake` or `make`. You only need root permission for the install part of the process. If you've already used root permission to try and build, the best thing to do would be to start over, delete the directory and redownload the source to start fresh. Alternatively, you could try running `sudo make clean` but there's no guarantee this will work.
pr flag
yes you are correct @mchid, I somehow wrote it write protected when I first did. At this time I deleted content of build then rebuild it. Without becoming root now that builds. However, this strange header issue remains.
pr flag
here is a similar issue: https://stackoverflow.com/questions/34910660/fatal-error-freetype-config-ftheader-h
Score:0
pr flag

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
    
hr flag
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](https://stackoverflow.com/a/23888557/4440445)
pr flag
@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.
Score:0
bo flag

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.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.