September 22, 2011

szuzsq szuzsq
Lab Rat
28 posts

[Solved]Qt Mac: can not link ffmpeg library

 

I want to link ffmpeg library using Qt under Mac OS X, but fail.

My environment are:
Mac OS X 10.6.4
xCode 3.2.3
Qt_SDK_Mac64_offline_v1_1_3_en.dmg
ffmpeg-0.7.4.tar.bz2

———————————-
My step are:
1). run terminal
2). type “sudo -s”, to administrator privileges

these steps followed are to compile and install ffmpeg.
3). type “cd /Volumes/Mac_OS_5/tools/Components/ffmpeg/ffmpeg-0.7.4”
4). type “./configure —disable-yasm”
5). type “make”
6). type “make install”

after ffmpeg installed, there are directories and files under /usr/local as below:

  1. /usr/local/include/libavcodec
  2.                              /avcodec.h
  3.                              /... ...
  4.                   /libavdevice
  5.                              /avdevice.h
  6.                              /... ...
  7.                   /libavfilter
  8.                              /avfilter.h
  9.                              /... ...
  10.                   /libavformat
  11.                              /avformat.h
  12.                              /... ...
  13.                   /libavutil
  14.                              /avutil.h
  15.                              /... ...
  16.                   /libswscale
  17.                              /swscale.h
  18.                              /... ...
  19.  
  20. /usr/local/lib/libavcodec.a
  21.               /libavdevice.a
  22.               /libavfilter.a
  23.               /libavformat.a
  24.               /libavutil.a
  25.               /libswscale.a
  26.               /pkgconfig/libavcodec.pc
  27.                         /libavdevice.pc
  28.                         /libavfilter.pc
  29.                         /libavformat.pc
  30.                         /libavutil.pc
  31.                         /libswscale.pc

and then I type “ffmpeg”, the message is:
—————————————-
ffmpeg version 0.7.4, Copyright © 2000-2011 the FFmpeg developers built on Sep 22 2011 16:12:41 with gcc 4.2.1 (Apple Inc. build 5664) configuration: —disable-yasm libavutil 50. 43. 0 / 50. 43. 0 libavcodec 52.122. 0 / 52.122. 0 libavformat 52.110. 0 / 52.110. 0 libavdevice 52. 5. 0 / 52. 5. 0 libavfilter 1. 80. 0 / 1. 80. 0 libswscale 0. 14. 1 / 0. 14. 1
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]… {[outfile options] outfile}…
—————————————-
it means install ffmpeg successfully.

these steps followed are to build a test console link with ffmpeg using Qt:
7). create a “Qt Console Application” save at “/Volumes/Mac_OS_4/test/ffmpeg_test”
8). copy the ffmpeg headers and libraries to “/Volumes/Mac_OS_4/test/ffmpeg_test”, in the same directories with “ffmpeg_test.pro”, “main.cpp”:

  1. /Volumes/Mac_OS_4/test/ffmpeg_test/include/libavcodec/avcodec.h
  2. /... ...
  3.  
  4. /Volumes/Mac_OS_4/test/ffmpeg_test/lib/libavcodec.a
  5. /... ...
  6. /Volumes/Mac_OS_4/test/ffmpeg_test/lib/pkgconfig/libavcodec.pc
  7. /... ...

My code are:

  1. #*************ffmpeg_test.pro********************
  2. QT       += core
  3. QT       -= gui
  4.  
  5. TARGET = ffmpeg_test
  6. CONFIG   += console
  7. CONFIG   -= app_bundle
  8.  
  9. TEMPLATE = app
  10.  
  11. SOURCES += main.cpp
  12.  
  13. INCLUDEPATH += include
  14.  
  15. LIBS += -Llib
  16. LIBS += -lavcodec
  17. LIBS += -lavdevice
  18. LIBS += -lavfilter
  19. LIBS += -lavformat
  20. LIBS += -lavutil
  21. LIBS += -lswscale

  1. //************main.cpp*********************
  2. extern "C" {
  3.     #include "libavcodec/avcodec.h"
  4.     //#include "libavformat/avformat.h"
  5. };
  6.  
  7. int main() {
  8.     avcodec_version();
  9.     return 0;
  10. }

———————————
But when I try to build, it output build issues:
symbol(s) not found
collect2: Id returned 1 exit status

———————————-
BTW, when I type “lipo -info libavcodec.a”, the message are:
input file libavcodec.a is not a fat file
Non-fat file: libavcodec.a is architecture: x86_64

6 replies

September 22, 2011

p-himik p-himik
Lab Rat
263 posts

You shouldn’t copy headers from /usr to your project’s folder. Instead you should add following line in the project’s .pro file:

  1. INCLUDEPATH += /usr/local/include

Also you could just change default prefix from /usr/local to /usr in the forth step.

For successful linking replace in your .pro file this

  1. LIBS += -Llib

with this
  1. LIBS += -L/usr/local/lib

September 22, 2011

szuzsq szuzsq
Lab Rat
28 posts

thx all the same.

though I replace with in the .pro file

  1. INCLUDEPATH += /usr/local/include
  2. LIBS += -L/usr/local/lib

but the error are exist:
——————————————
symbol(s) not found
collect2: Id returned 1 exit status

September 22, 2011

p-himik p-himik
Lab Rat
263 posts

And what if you replace

  1. LIBS += -L/usr/local/lib

with
  1. LIBS += -L/usr/local/lib/pkgconfig

?

September 22, 2011

uranusjr uranusjr
Lab Rat
93 posts

If you look into the compile messages, there should be some lines detailing why the linker (ld) gave you the error. Can you post those too? It may also be useful you give the last few lines (right before the linker error) in the compile output.

September 23, 2011

Volker Volker
Ant Farmer
5428 posts

Of particular interest is which symbols are not found, these are listed in the compiler output tab.

September 23, 2011

szuzsq szuzsq
Lab Rat
28 posts

I have resolved this problem.
by step 4, try to generate share library but no static:

  1. ./configure --disable-static --enable-shared --disable-yasm

———————
Thank you all the same!

 
  ‹‹ [SOlved]Simpel BarDiagram      [solved] Custom QGraphicsPixmapItem ››

You must log in to post a reply. Not a member yet? Register here!