Skip to main content
Richard Rosenman
Inspiring
May 28, 2024
Question

How to set up Cairo in Xcode for SDK

  • May 28, 2024
  • 1 reply
  • 976 views

Hi gang;

 

I have used Cairo on Windows for SDK development and it works great.

 

However, I am struggling to get it set up on a Mac in order to compile a Mac version. I am wondering if someone can help getting it to work. These are the steps I've done:

 

1 - Installed MacPorts

2 - Installed Cairo through MacPorts by going to this website: https://ports.macports.org/port/cairo/ and entering the sudo command in my terminal.

3 - Confirmed Cairo is installed by typing "port contents cairo". It is installed in my /opt/local/lib/ folder.

4 - In the Xcode project navigator, under "Search Paths", I added the Cairo folder entries under "Header Search Paths": 

/opt/local/lib/

/opt/local/lib/cairo

/opt/local/include

I also added the path here as well for my cairo.h file and added the include to my .cpp file: 

#include <cairo.h>

5 - In the Xcode project navigator, under "Linking", I added "-libcairo.a" entry under "Other Linking Flags"

 

But when I compile, I get 

ld: library not found for -libcairo.a

clang: error: linker command failed with exit code 1 (use -v to see invocation)

 

Did I miss a step? I find it to be an extremely complicated set up to get this to work. It also doesn't help that I am not good with Macs (nor do I particularly like them). Any help or advice would be highly appreciated.

 

Thanks,

Richard

 

This topic has been closed for replies.

1 reply

James Whiffin
Legend
May 31, 2024

Hi Rich

From that error message it sounds like Xcode can't find your cairo lib. Did you tell Xcode where to find the library? A foolproof method would be to set the hardcoded path into the "other linker flags" setting. When that works then you can just put the name of the lib in the other linker flags, and put the path directory into the library search paths. 

Cairo on mac may also need the pixman lib, but it will give you an error about missing symbols if that is the case for your setup. 

Richard Rosenman
Inspiring
May 31, 2024

Heya James!

 

Thank you as always for your suggestions.

 

I did as you suggested and used the full path of the cair library in the "Other Linker Flags". Like so:

/opt/local/lib/libcairo.a

/opt/local/lib/libcairo.dylib

 

And sure enough, I no longer get the "library not found" error. So that seems to have found it. However, I now get a ton of "Undefined Symbol Errors". I noted what you said about the possibility of requiring the pixman library but these errors seem to point to libcairo.a:

 

Undefined symbols for architecture x86_64:
  "_FT_Bitmap_Convert", referenced from:
      __get_bitmap_surface in libcairo.a(cairo-ft-font.o)
  "_FT_Bitmap_Done", referenced from:
      __get_bitmap_surface in libcairo.a(cairo-ft-font.o)
  "_FT_Bitmap_New", referenced from:
      __get_bitmap_surface in libcairo.a(cairo-ft-font.o)
  "_FT_Done_Face", referenced from:
      __cairo_ft_unscaled_font_lock_face in libcairo.a(cairo-ft-font.o)
      __cairo_ft_unscaled_font_destroy in libcairo.a(cairo-ft-font.o)
      __cairo_ft_unscaled_font_map_pluck_entry in libcairo.a(cairo-ft-font.o)
  "_FT_Done_FreeType", referenced from:
      __cairo_ft_font_reset_static_data in libcairo.a(cairo-ft-font.o)
  "_FT_Done_MM_Var", referenced from:
      _cairo_ft_apply_variations in libcairo.a(cairo-ft-font.o)
      __cairo_ft_is_synthetic in libcairo.a(cairo-ft-font.o)
      __cairo_ft_unscaled_font_create_internal in libcairo.a(cairo-ft-font.o)
  "_FT_Get_Color_Glyph_Layer", referenced from:
      __cairo_ft_scaled_glyph_init_surface in libcairo.a(cairo-ft-font.o)
  "_FT_Get_First_Char", referenced from:
      __cairo_ft_index_to_ucs4 in libcairo.a(cairo-ft-font.o)
  "_FT_Get_Glyph_Name", referenced from:
      __cairo_index_to_glyph_name in libcairo.a(cairo-ft-font.o)
  "_FT_Get_MM_Var", referenced from:
      _cairo_ft_apply_variations in libcairo.a(cairo-ft-font.o)
      __cairo_ft_is_synthetic in libcairo.a(cairo-ft-font.o)
      __cairo_ft_unscaled_font_create_internal in libcairo.a(cairo-ft-font.o)
  "_FT_Get_Next_Char", referenced from:
      __cairo_ft_index_to_ucs4 in libcairo.a(cairo-ft-font.o)
  "_FT_Get_Var_Blend_Coordinates", referenced from:
      __cairo_ft_is_synthetic in libcairo.a(cairo-ft-font.o)
  "_FT_Get_Var_Design_Coordinates", referenced from:
      _cairo_ft_apply_variations in libcairo.a(cairo-ft-font.o)
      __cairo_ft_unscaled_font_create_internal in libcairo.a(cairo-ft-font.o)
  "_FT_Get_X11_Font_Format", referenced from:
      __cairo_ft_load_type1_data in libcairo.a(cairo-ft-font.o)
  "_FT_GlyphSlot_Embolden", referenced from:
      __cairo_ft_scaled_glyph_load_glyph in libcairo.a(cairo-ft-font.o)
  "_FT_GlyphSlot_Oblique", referenced from:
      __cairo_ft_scaled_glyph_load_glyph in libcairo.a(cairo-ft-font.o)
  "_FT_Init_FreeType", referenced from:
      __cairo_ft_unscaled_font_map_lock in libcairo.a(cairo-ft-font.o)
  "_FT_Library_SetLcdFilter", referenced from:
      __cairo_ft_scaled_glyph_init_surface in libcairo.a(cairo-ft-font.o)
  "_FT_Load_Glyph", referenced from:
      __cairo_ft_scaled_glyph_load_glyph in libcairo.a(cairo-ft-font.o)
  "_FT_Load_Sfnt_Table", referenced from:
      __cairo_ft_load_truetype_table in libcairo.a(cairo-ft-font.o)
  "_FT_New_Face", referenced from:
      __cairo_ft_unscaled_font_lock_face in libcairo.a(cairo-ft-font.o)
  "_FT_Outline_Decompose", referenced from:
      __cairo_ft_scaled_glyph_init in libcairo.a(cairo-ft-font.o)
  "_FT_Outline_Get_CBox", referenced from:
      __cairo_ft_scaled_glyph_init_surface in libcairo.a(cairo-ft-font.o)
  "_FT_Outline_Transform", referenced from:
      __cairo_ft_scaled_glyph_init in libcairo.a(cairo-ft-font.o)
  "_FT_Outline_Translate", referenced from:
      __cairo_ft_scaled_glyph_load_glyph in libcairo.a(cairo-ft-font.o)
  "_FT_Palette_Set_Foreground_Color", referenced from:
      __cairo_ft_scaled_glyph_init_surface in libcairo.a(cairo-ft-font.o)
  "_FT_Render_Glyph", referenced from:
      __cairo_ft_scaled_glyph_init_surface in libcairo.a(cairo-ft-font.o)
  "_FT_Set_Char_Size", referenced from:
      __cairo_ft_unscaled_font_set_scale in libcairo.a(cairo-ft-font.o)
  "_FT_Set_Transform", referenced from:
      __cairo_ft_unscaled_font_set_scale in libcairo.a(cairo-ft-font.o)
  "_FT_Set_Var_Design_Coordinates", referenced from:
      _cairo_ft_apply_variations in libcairo.a(cairo-ft-font.o)
  "_FT_Vector_Transform", referenced from:
      __cairo_ft_scaled_glyph_load_glyph in libcairo.a(cairo-ft-font.o)
  "_FcConfigGetCurrent", referenced from:
      __cairo_ft_font_face_get_implementation in libcairo.a(cairo-ft-font.o)
  "_FcConfigSubstitute", referenced from:
      __cairo_ft_font_face_get_implementation in libcairo.a(cairo-ft-font.o)
  "_FcDefaultSubstitute", referenced from:
      __cairo_ft_font_face_get_implementation in libcairo.a(cairo-ft-font.o)
  "_FcFontMatch", referenced from:
      __cairo_ft_font_face_get_implementation in libcairo.a(cairo-ft-font.o)
  "_FcFreeTypeCharIndex", referenced from:
      __cairo_ft_ucs4_to_index in libcairo.a(cairo-ft-font.o)
  "_FcInitBringUptoDate", referenced from:
      __cairo_ft_font_face_get_implementation in libcairo.a(cairo-ft-font.o)
  "_FcPatternAddBool", referenced from:
      __cairo_ft_font_options_substitute in libcairo.a(cairo-ft-font.o)
  "_FcPatternAddDouble", referenced from:
      __cairo_ft_font_face_get_implementation in libcairo.a(cairo-ft-font.o)
  "_FcPatternAddInteger", referenced from:
      __cairo_ft_font_face_create_for_toy in libcairo.a(cairo-ft-font.o)
      __cairo_ft_font_options_substitute in libcairo.a(cairo-ft-font.o)
  "_FcPatternAddString", referenced from:
      __cairo_ft_font_face_create_for_toy in libcairo.a(cairo-ft-font.o)
  "_FcPatternCreate", referenced from:
      __cairo_ft_font_face_create_for_toy in libcairo.a(cairo-ft-font.o)
  "_FcPatternDel", referenced from:
      __cairo_ft_font_options_substitute in libcairo.a(cairo-ft-font.o)
  "_FcPatternDestroy", referenced from:
      __cairo_ft_font_face_create_for_toy in libcairo.a(cairo-ft-font.o)
      __cairo_ft_font_face_destroy in libcairo.a(cairo-ft-font.o)
      __cairo_ft_font_face_get_implementation in libcairo.a(cairo-ft-font.o)
  "_FcPatternDuplicate", referenced from:
      __cairo_ft_font_face_get_implementation in libcairo.a(cairo-ft-font.o)
      __cairo_ft_font_face_create_for_pattern in libcairo.a(cairo-ft-font.o)
  "_FcPatternGet", referenced from:
      __cairo_ft_font_options_substitute in libcairo.a(cairo-ft-font.o)
  "_FcPatternGetBool", referenced from:
      __get_pattern_ft_options in libcairo.a(cairo-ft-font.o)
  "_FcPatternGetFTFace", referenced from:
      __cairo_ft_unscaled_font_create_for_pattern in libcairo.a(cairo-ft-font.o)
  "_FcPatternGetInteger", referenced from:
      __cairo_ft_unscaled_font_create_for_pattern in libcairo.a(cairo-ft-font.o)
      __get_pattern_ft_options in libcairo.a(cairo-ft-font.o)
  "_FcPatternGetString", referenced from:
      __cairo_ft_unscaled_font_create_for_pattern in libcairo.a(cairo-ft-font.o)
      __get_pattern_ft_options in libcairo.a(cairo-ft-font.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

 

 

Showing Recent Issues
Undefined symbol: _FT_Bitmap_Convert

Undefined symbol: _FT_Bitmap_Done

Undefined symbol: _FT_Bitmap_New

Undefined symbol: _FT_Done_Face

Undefined symbol: _FT_Done_FreeType

Undefined symbol: _FT_Done_MM_Var

Undefined symbol: _FT_Get_Color_Glyph_Layer

Undefined symbol: _FT_Get_First_Char

Undefined symbol: _FT_Get_Glyph_Name

Undefined symbol: _FT_Get_MM_Var

Undefined symbol: _FT_Get_Next_Char

Undefined symbol: _FT_Get_Var_Blend_Coordinates

Undefined symbol: _FT_Get_Var_Design_Coordinates

Undefined symbol: _FT_Get_X11_Font_Format

Undefined symbol: _FT_GlyphSlot_Embolden

Undefined symbol: _FT_GlyphSlot_Oblique

Undefined symbol: _FT_Init_FreeType

Undefined symbol: _FT_Library_SetLcdFilter

Undefined symbol: _FT_Load_Glyph

Undefined symbol: _FT_Load_Sfnt_Table

Undefined symbol: _FT_New_Face

Undefined symbol: _FT_Outline_Decompose

Undefined symbol: _FT_Outline_Get_CBox

Undefined symbol: _FT_Outline_Transform

Undefined symbol: _FT_Outline_Translate

Undefined symbol: _FT_Palette_Set_Foreground_Color

Undefined symbol: _FT_Render_Glyph

Undefined symbol: _FT_Set_Char_Size

Undefined symbol: _FT_Set_Transform

Undefined symbol: _FT_Set_Var_Design_Coordinates

Undefined symbol: _FT_Vector_Transform

Undefined symbol: _FcConfigGetCurrent

Undefined symbol: _FcConfigSubstitute

Undefined symbol: _FcDefaultSubstitute

Undefined symbol: _FcFontMatch

Undefined symbol: _FcFreeTypeCharIndex

Undefined symbol: _FcInitBringUptoDate

Undefined symbol: _FcPatternAddBool

Undefined symbol: _FcPatternAddDouble

Undefined symbol: _FcPatternAddInteger

Undefined symbol: _FcPatternAddString

Undefined symbol: _FcPatternCreate

Undefined symbol: _FcPatternDel

Undefined symbol: _FcPatternDestroy

Undefined symbol: _FcPatternDuplicate

Undefined symbol: _FcPatternGet

Undefined symbol: _FcPatternGetBool

Undefined symbol: _FcPatternGetFTFace

Undefined symbol: _FcPatternGetInteger

Undefined symbol: _FcPatternGetString

Any suggestions?

 

Thanks,

-Rich

James Whiffin
Legend
June 1, 2024

Hi Rich

That error looks like freetype which can be a dependency of some cairo builds to render fonts. You might be able to build cairo without that dependency, or download/build the freetype lib and add it to your project. There may be more dependencies if Xcode is just feeding you one missing lib at a time, such as the pixman or png lib.