Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Heya James!
I'm giving this one more shot, in case you want to have one more guess at it.
I installed the Freetype library like you suggested and sure enough, the number of errors dropped. However, I now get different ones.
Here's what I've got in my "Other Linker Flags"
/opt/local/lib/libcairo.a
/opt/local/lib/libpng.a
/opt/local/lib/libfreetype.a
/opt/local/lib/libpixman-1.a
And this is what I've got in my "Header Search Paths"
/opt/local/include
/opt/local/include/freetype2
/opt/local/include/cairo
/opt/local/lib/cairo
/opt/local/lib
Finally, this is what I've got in my "Library Search Paths"
/opt/local/lib/cairo
/opt/local/lib
I'm not really sure if there's any other settings I need in XCode but the documentation I've read didn't specify it.
These are the errors I'm now getting. They still reference Freetype and LibCairo so could it be a version issue (like the ones I installed being too old or too new)?
Undefined symbols for architecture x86_64:
"_BZ2_bzDecompress", referenced from:
_ft_bzip2_file_fill_output in libfreetype.a(ftbzip2.o)
"_BZ2_bzDecompressEnd", referenced from:
_ft_bzip2_stream_io in libfreetype.a(ftbzip2.o)
_ft_bzip2_stream_close in libfreetype.a(ftbzip2.o)
"_BZ2_bzDecompressInit", referenced from:
_FT_Stream_OpenBzip2 in libfreetype.a(ftbzip2.o)
_ft_bzip2_stream_io in libfreetype.a(ftbzip2.o)
"_BrotliDecoderDecompress", referenced from:
_sfnt_open_font in libfreetype.a(sfnt.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)
"_adler32", referenced from:
_png_icc_set_sRGB in libpng.a(png.o)
"_crc32", referenced from:
_png_reset_crc in libpng.a(png.o)
_png_calculate_crc in libpng.a(png.o)
_png_icc_set_sRGB in libpng.a(png.o)
"_deflate", referenced from:
_png_compress_IDAT in libpng.a(pngwutil.o)
_png_text_compress in libpng.a(pngwutil.o)
"_deflateEnd", referenced from:
_png_destroy_write_struct in libpng.a(pngwrite.o)
_png_deflate_claim in libpng.a(pngwutil.o)
"_deflateInit2_", referenced from:
_png_deflate_claim in libpng.a(pngwutil.o)
"_deflateReset", referenced from:
_png_deflate_claim in libpng.a(pngwutil.o)
"_inflate", referenced from:
_FT_Gzip_Uncompress in libfreetype.a(ftgzip.o)
_ft_gzip_file_fill_output in libfreetype.a(ftgzip.o)
_png_zlib_inflate in libpng.a(pngrutil.o)
(maybe you meant: _png_zlib_inflate)
"_inflateEnd", referenced from:
_FT_Stream_OpenGzip in libfreetype.a(ftgzip.o)
_ft_gzip_stream_close in libfreetype.a(ftgzip.o)
_FT_Gzip_Uncompress in libfreetype.a(ftgzip.o)
_png_destroy_read_struct in libpng.a(pngread.o)
"_inflateInit2_", referenced from:
_FT_Stream_OpenGzip in libfreetype.a(ftgzip.o)
_FT_Gzip_Uncompress in libfreetype.a(ftgzip.o)
_png_inflate_claim in libpng.a(pngrutil.o)
"_inflateReset", referenced from:
_ft_gzip_file_io in libfreetype.a(ftgzip.o)
_png_reset_zstream in libpng.a(png.o)
_png_decompress_chunk in libpng.a(pngrutil.o)
"_inflateReset2", referenced from:
_png_inflate_claim in libpng.a(pngrutil.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
-Rich
Copy link to clipboard
Copied
Hi Rich
To my (limited) knowledge those extra dependencies are required on the newer versions of cairo. For my old mac build I just needed libpng.
When building the latest version of cairo (so I could get 32bpc support), I hit the same dependency wall you're experiencing.