Ask Your Question
0

Undefined freetype symbols when building openCV 3.2.0

asked 2017-01-07 12:01:06 -0600

saulspatz gravatar image

openCV: 3.2.0

OS: Yosemite 10.10.5

compiler: Apple LLVM version 7.0.2 (clang-700.1.81)

I built openCV 3.2.0 successfully, but then I found out that I needed ffmpeg support. I installed ffmpeg with homebrew, and when I tried to build openCV again, the build failed because of undefined symbols in freetype libraries. I then tried to build openCV again without ffmpeg, and the build failed with the same errors. Before I installed ffmpeg I ran brew upgrade and I saw that it upgraded freetype, so this may be the source of the problem, but if so I don't know what to do about it. Here's the command I'm running

PYTHON3_DIR=`python3-config --prefix` # Get python 3 path
VIRTUAL_ENV=`python3-config --prefix`
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=$VIRTUAL_ENV \
-D PYTHON_EXECUTABLE=$VIRTUAL_ENV/bin/python3 \
-D PYTHON3_PACKAGES_PATH=$VIRTUAL_ENV/lib/python3.5/site-packages \
-D PYTHON3_INCLUDE_DIR=$VIRTUAL_ENV/include/python3.5m \
-D PYTHON3_LIBRARY=$PYTHON3_DIR/lib/libpython3.5m.dylib \
-D PYTHON3_NUMPY_INCLUDE_DIRS=$VIRTUAL_ENV/lib/python3.5/site-packages/numpy/core/include/ \
-D INSTALL_C_EXAMPLES=ON \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D BUILD_EXAMPLES=ON \
-D BUILD_opencv_python3=ON \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules ..

This produces no errors, but when I run make I get

[ 26%] Building CXX object modules/freetype/CMakeFiles/opencv_freetype.dir/src/freetype.cpp.o
[ 26%] Linking CXX shared library ../../lib/libopencv_freetype.dylib
Undefined symbols for architecture x86_64:
  "_FT_Done_Face", referenced from:
      cv::freetype::FreeType2Impl::~FreeType2Impl() in freetype.cpp.o
      cv::freetype::FreeType2Impl::loadFontData(cv::String, int) in freetype.cpp.o
  "_FT_Done_FreeType", referenced from:
      cv::freetype::FreeType2Impl::~FreeType2Impl() in freetype.cpp.o
  "_FT_Init_FreeType", referenced from:
      cv::freetype::FreeType2Impl::FreeType2Impl() in freetype.cpp.o
      cv::freetype::FreeType2Impl::FreeType2Impl() in freetype.cpp.o
      cv::freetype::createFreeType2() in freetype.cpp.o

and a bunch of other missing symbols. When I run nm freetype.cpp.o those symbols are listed as undefined all right, but I can successfully install openCV 3.2.0 (with ffmpeg support) on Ubuntu 16.04 using gcc 5.4, and those same symbols are undefined in freetype.cpp.o, so I guess it's trying to link them from another file, but I have no clue which.

I really need installed it on the Mac. I only installed in on Ubuntu as a temporary stopgap. Can you give me any advice?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-01-21 01:39:21 -0600

Hi, I had this problem while linking opencv_freetype module from contrib modules. I found the problem lies in the library names used by cmake config file. I don't know the proper way to fix it but modifying the cmakelists.txt file has worked for me.

The specific modification I did:

  1. find CMakeLists.txt file under <contrib_module_dir>/modules/freetype/CMakeLists.txt
  2. find the line ocv_define_module(freetype opencv_core...)
  3. locate the library variable ${freetype2_LIBRARIES} and change it to ${FREETYPE_LIBRARIES}
  4. locate the variable ${harfbuzz_LIBRARIES} and change it to ${HARFBUZZ_LIBRARIES}

BTW I had both freetype and harfbuzz installed homebrew, it seems the configuration file has found both libraries, just the libraries' names got messed up.

and try compile again see if it resolves your problem.

edit flag offensive delete link more

Comments

@shin1987 may be you should report an issue

LBerger gravatar imageLBerger ( 2017-01-21 02:43:55 -0600 )edit

I had the same problem. This works great, thanks!

zrbarrita gravatar imagezrbarrita ( 2017-03-31 15:12:41 -0600 )edit

Same problem for me. Thanks for posting the fix!

khanh gravatar imagekhanh ( 2017-07-11 00:33:38 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-01-07 12:01:06 -0600

Seen: 2,721 times

Last updated: Jan 21 '17