June 26, 2011

mirswith mirswith
Lab Rat
132 posts

64bit osx (part II) linking

 

I am trying to link the libx264 library to one of my apps but I am getting linking errors saying it can not find various symbols for the x86_64 architecture:

Undefined symbols for architecture x86_64: “x264_param_default_preset(x264_param_t*, char const*, char const*)”, referenced from:

I have verified that I compiled the libx264 library using x86_64:

>lipo -info libx264.a
input file libx264.a is not a fat file
Non-fat file: libx264.a is architecture: x86_64

I also checked to see if the missing symbols exist in the library:

> nm libx264.a | grep x264_param_default_preset
0000000000001710 T _x264_param_default_preset
0000000000005e88 S _x264_param_default_preset.eh

I am trying to link as a static library.

Are there some additional parameters I need to set when compiling libraries to get them to be compatible with Qt or can someone point me in the right direction?

Thanks again.

-=ben

5 replies

June 26, 2011

loladiro loladiro
Lab Rat
596 posts

Could you post the part of your .pro file, where you are linking your libs?
Also, there was a similar thread before (maybe you have the same problem):
http://developer.qt.nokia.com/forums/viewthread/5665

June 26, 2011

mirswith mirswith
Lab Rat
132 posts

Sure thing:

  1. TARGET = myLib
  2. TEMPLATE = lib
  3.  
  4. ... headers/source removed for readability ...
  5.  
  6. macx {
  7.  
  8.  LIBS += /Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/AppKit.framework/Versions/Current/AppKit \
  9.                 /Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/OpenGL.framework/Versions/Current/OpenGL \
  10.                 ../../../common/x264/libx264.a \
  11.                 ../../../common/ffmpeg/libswscale/libswscale.a
  12.  
  13.         QMAKE_LFLAGS_SONAME = -Wl,-install_name,@executable_path/../Frameworks/
  14.  
  15. }

Thanks for the other posting link, unfortunately it has not helped me.

Thanks.

-=ben

June 27, 2011

Volker Volker
Ant Farmer
5428 posts

I can reproduce the problem. It’s nothing Qt specific, though.

The x264 library does not support C++ out of the box. It is a pure C library, so it uses the C style name mangling [en.wikipedia.org], if you just include the headers in a C++ source, the compiler wants to apply C++ style name mangling – so it tries to link different names which are not available in the lib.

So, the solution simple: Wrap the #include with extern “C” this way:

  1. #include <stdint.h>
  2.  
  3. // enforce C style name mangling
  4. extern "C" {
  5. #include "x264.h"
  6. }

This switches on C name mangling for the functions in this header file.

June 27, 2011

mirswith mirswith
Lab Rat
132 posts

That was it! You made my day and I learned something to boot. :)

Are there any ways to tell what type of name mangling is being used to help troubleshoot this in the future?

Thanks again!

-=ben

June 27, 2011

Volker Volker
Ant Farmer
5428 posts

If you do not setup anything, then the default name mangling is used. If you have a C library that is usesful from C++ as well, it is good practice to put that extern stuff into the header of your libraray. The usual pattern is:

  1. #ifdef __cplusplus
  2. extern "C" {
  3. #endif
  4.  
  5. // your actual header files goes here
  6.  
  7. #ifdef __cplusplus
  8. }
  9. #endif

See the C++ FAQ on ‘How to mix C and C++’ [parashift.com] for some more details.

Unfortunately there is no easy way to tell if the header has the “extern” other than actually looking into it.

 
  ‹‹ [Solved] QGraphicsView mousePressEvent and selection behavior?      [SOLVED] Eliminating main window transition (resize) "jump" ››

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