Can't compile Clion freetype2

Hello!

Think might be really dumb as I am both new to Cpp and JUCE but I am having trouble compiling on Windows, Clion using WSL Ubuntu 20 to compile. For context, this is the build command being ran by clion C:\Windows\system32\wsl.exe --distribution Ubuntu-20.04 --exec /bin/bash -c "export JUCE_USE_FREETYPE=0 && export CMAKE_COLOR_DIAGNOSTICS=ON && export CLION_IDE=TRUE && export DFREETYPE_INCLUDE_DIRS=/usr/include/freetype2/include && export DFREETYPE_LIBRARY=/usr/include/freetype2/freetype.so && export JETBRAINS_IDE=TRUE && cd /mnt/c/...r/Documents/Projects/fyp/JUCE_Tempometer/JUCE/cmake-build-debug && /usr/bin/cmake -DCMAKE_BUILD_TYPE=Debug -S /mnt/c/...Documents/Projects/fyp/JUCE_Tempometer/JUCE -B /mnt/c/.../Documents/Projects/fyp/JUCE_Tempometer/JUCE/cmake-build-debug"

The main issue is fatal error: ft2build.h: No such file or directory which I can get around, even though libfreetype6-dev is installed (along with all dependencies listed in the repo). I manually added the install directory both by using Findfreetype and manually adding the directory.

#include_directories (/usr/include/freetype2)

This solves the dependency issue but doesn’t seem to link correctly (see below).

CMake Error at extras/Build/juceaide/CMakeLists.txt:103 (message):
  Failed to build juceaide

  Scanning dependencies of target juce_lv2_helper

  [ 10%] Building CXX object
  modules/juce_audio_plugin_client/CMakeFiles/juce_lv2_helper.dir/LV2/juce_LV2TurtleDumpProgram.cpp.o


  [ 20%] Linking CXX executable juce_lv2_helper

  [ 20%] Built target juce_lv2_helper

  Scanning dependencies of target juceaide

  [ 30%] Building CXX object
  extras/Build/juceaide/CMakeFiles/juceaide.dir/Main.cpp.o

  [ 40%] Building CXX object
  extras/Build/juceaide/CMakeFiles/juceaide.dir/__/juce_build_tools/juce_build_tools.cpp.o


  [ 50%] Building CXX object
  extras/Build/juceaide/CMakeFiles/juceaide.dir/__/__/__/modules/juce_gui_basics/juce_gui_basics.cpp.o


  [ 60%] Building CXX object
  extras/Build/juceaide/CMakeFiles/juceaide.dir/__/__/__/modules/juce_graphics/juce_graphics.cpp.o


  [ 70%] Building CXX object
  extras/Build/juceaide/CMakeFiles/juceaide.dir/__/__/__/modules/juce_events/juce_events.cpp.o


  [ 80%] Building CXX object
  extras/Build/juceaide/CMakeFiles/juceaide.dir/__/__/__/modules/juce_core/juce_core.cpp.o


  [ 90%] Building CXX object
  extras/Build/juceaide/CMakeFiles/juceaide.dir/__/__/__/modules/juce_data_structures/juce_data_structures.cpp.o


  [100%] Linking CXX executable juceaide_artefacts/Debug/juceaide

  /usr/bin/ld:
  CMakeFiles/juceaide.dir/__/__/__/modules/juce_graphics/juce_graphics.cpp.o:
  in function `juce::FTLibWrapper::FTLibWrapper()':

  
  /mnt/c/.../Documents/Projects/fyp/JUCE_Tempometer/JUCE/modules/juce_graphics/native/juce_freetype_Fonts.cpp:33:
  undefined reference to `FT_Init_FreeType'

  /usr/bin/ld:
  CMakeFiles/juceaide.dir/__/__/__/modules/juce_graphics/juce_graphics.cpp.o:
  in function `juce::FTLibWrapper::~FTLibWrapper()':

  
  /mnt/c/.../Documents/Projects/fyp/JUCE_Tempometer/JUCE/modules/juce_graphics/native/juce_freetype_Fonts.cpp:43:
  undefined reference to `FT_Done_FreeType'

  /usr/bin/ld:
  CMakeFiles/juceaide.dir/__/__/__/modules/juce_graphics/juce_graphics.cpp.o:
  in function
  `juce::FTFaceWrapper::FTFaceWrapper(juce::ReferenceCountedObjectPtr<juce::FTLibWrapper>
  const&, juce::File const&, int)':

  
  /mnt/c/.../Documents/Projects/fyp/JUCE_Tempometer/JUCE/modules/juce_graphics/native/juce_freetype_Fonts.cpp:59:
  undefined reference to `FT_New_Face'

  /usr/bin/ld:
  CMakeFiles/juceaide.dir/__/__/__/modules/juce_graphics/juce_graphics.cpp.o:
  in function
  `juce::FTFaceWrapper::FTFaceWrapper(juce::ReferenceCountedObjectPtr<juce::FTLibWrapper>
  const&, void const*, unsigned long, int)':

  
  /mnt/c/.../Documents/Projects/fyp/JUCE_Tempometer/JUCE/modules/juce_graphics/native/juce_freetype_Fonts.cpp:66:
  undefined reference to `FT_New_Memory_Face'

  /usr/bin/ld:
  CMakeFiles/juceaide.dir/__/__/__/modules/juce_graphics/juce_graphics.cpp.o:
  in function `juce::FTFaceWrapper::~FTFaceWrapper()':

  
  /mnt/c/.../Documents/Projects/fyp/JUCE_Tempometer/JUCE/modules/juce_graphics/native/juce_freetype_Fonts.cpp:74:
  undefined reference to `FT_Done_Face'

  /usr/bin/ld:
  CMakeFiles/juceaide.dir/__/__/__/modules/juce_graphics/juce_graphics.cpp.o:
  in function
  `juce::FTTypefaceList::selectUnicodeCharmap(juce::FTFaceWrapper*)':

  
  /mnt/c/.../Documents/Projects/fyp/JUCE_Tempometer/JUCE/modules/juce_graphics/native/juce_freetype_Fonts.cpp:125:
  undefined reference to `FT_Select_Charmap'

  /usr/bin/ld:
  /mnt/c/.../Documents/Projects/fyp/JUCE_Tempometer/JUCE/modules/juce_graphics/native/juce_freetype_Fonts.cpp:126:
  undefined reference to `FT_Set_Charmap'

  /usr/bin/ld:
  CMakeFiles/juceaide.dir/__/__/__/modules/juce_graphics/juce_graphics.cpp.o:
  in function `juce::FreeTypeTypeface::loadGlyphIfPossible(wchar_t)':

  
  /mnt/c/.../Documents/Projects/fyp/JUCE_Tempometer/JUCE/modules/juce_graphics/native/juce_freetype_Fonts.cpp:318:
  undefined reference to `FT_Get_Char_Index'

  /usr/bin/ld:
  /mnt/c/.../Documents/Projects/fyp/JUCE_Tempometer/JUCE/modules/juce_graphics/native/juce_freetype_Fonts.cpp:320:
  undefined reference to `FT_Load_Glyph'

  /usr/bin/ld:
  CMakeFiles/juceaide.dir/__/__/__/modules/juce_graphics/juce_graphics.cpp.o:
  in function `juce::FreeTypeTypeface::addKerning(FT_FaceRec_*, unsigned int,
  unsigned int)':

  
  /mnt/c/.../Documents/Projects/fyp/JUCE_Tempometer/JUCE/modules/juce_graphics/native/juce_freetype_Fonts.cpp:436:
  undefined reference to `FT_Get_First_Char'

  /usr/bin/ld:
  /mnt/c/.../Documents/Projects/fyp/JUCE_Tempometer/JUCE/modules/juce_graphics/native/juce_freetype_Fonts.cpp:442:
  undefined reference to `FT_Get_Kerning'

  /usr/bin/ld:
  /mnt/c/.../Documents/Projects/fyp/JUCE_Tempometer/JUCE/modules/juce_graphics/native/juce_freetype_Fonts.cpp:446:
  undefined reference to `FT_Get_Next_Char'

  collect2: error: ld returned 1 exit status

  make[2]: *** [extras/Build/juceaide/CMakeFiles/juceaide.dir/build.make:174:
  extras/Build/juceaide/juceaide_artefacts/Debug/juceaide] Error 1

  make[1]: *** [CMakeFiles/Makefile2:178:
  extras/Build/juceaide/CMakeFiles/juceaide.dir/all] Error 2

  make: *** [Makefile:130: all] Error 2

I tried linking by `target_link_directory(JUCE /usr/include/freetype2) but it doesn’t like the target. Here is a repo with all the files being used, I am only trying to build JUCE currently. (GitHub - olindenbaum/JUCE_MVP)
Any pointers or guidance would be much appreciated!

If you’re new to C++, I’d recommend sticking to ‘native’ build tools to begin with, rather than trying to use WSL. On Windows, CMake should generate a working Visual Studio project without needing any additional configuration, provided you have a copy of Visual Studio installed.

I tried using VC but couldn’t stay with it as it didn’t support Variable Length Arrays in C99? Unless there is a way and I’d be open to hearing it!

I’m not sure, but perhaps those are supported by Clang.

You can install the Clang/LLVM tools for VS from the Visual Studio Installer (click the Modify button, then make sure that the Clang/LLVM tools are checked). To use Clang when building, pass “-T ClangCL” when configuring with CMake.

Thanks, I’ll do a bit more digging. Is there no simple way I can add linking options in the current state?

Not really - JUCE uses a tool called pkg-config to discover the correct link/include flags for external libraries like freetype. JUCE doesn’t support overriding these flags in the case that pkg-config gets it wrong (I think this is the first time I’ve actually seen it get the flags wrong!).

Also, just in case you’re not aware - by default, building under WSL will produce a Linux executable rather than a Windows executable. If you’re trying to build an app or plug-in to use on Windows, this will be very difficult with WSL, and much easier with native compilers like MSVC/Clang.

1 Like

Your build command contains export JUCE_USE_FREETYPE=0, This will likely prevent JUCE from bringing in the FreeType headers.