简体   繁体   English

将ffmpeg的libswresample与MacOS X 10.9与C ++链接起来

[英]Linking ffmpeg's libswresample from MacOS X 10.9 with C++

I am trying to link to ffmpeg's libswresample from a C++ application. 我试图从C ++应用程序链接到ffmpeg的libswresample。 I have installed ffmpeg through Homebrew on Mac OS X 10.9. 我在Mac OS X 10.9上通过Homebrew安装了ffmpeg。 A simple test application links if it's compiled as C, but not if it's compiled as C++. 一个简单的测试应用程序链接,如果它被编译为C,但如果它被编译为C ++则不会。 Here is the sample code: 以下是示例代码:

#include <stdio.h>
#include <libswresample/swresample.h>

int main()
{
  swr_alloc();
  printf("Hello world\n");
  return 0;
}

When compiled as C with clang -I/usr/local/include -L/usr/local/lib -lswresample -o hello hello.c this creates the application as expected. 当使用clang -I/usr/local/include -L/usr/local/lib -lswresample -o hello hello.c编译为C时,这将按预期创建应用程序。 When compiled with C++ using clang++ -I/usr/local/include -L/usr/local/lib -lswresample -o hello hello.cc it results in an error like the following: 当使用clang++ -I/usr/local/include -L/usr/local/lib -lswresample -o hello hello.cc使用C ++编译时,会导致如下错误:

Undefined symbols for architecture x86_64:
  "swr_alloc()", referenced from:
      _main in hello-9jqOY4.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

But running nm -a /usr/local/lib/libswresample.dylib includes 000000000000d8a9 T _swr_alloc and file /usr/local/lib/libswresample.dylib shows /usr/local/lib/libswresample.dylib: Mach-O 64-bit dynamically linked shared library x86_64 which I assume is expected. 但运行nm -a /usr/local/lib/libswresample.dylib包括000000000000d8a9 T _swr_allocfile /usr/local/lib/libswresample.dylib显示/usr/local/lib/libswresample.dylib: Mach-O 64-bit dynamically linked shared library x86_64我假设是预期的。 I have the same issue compiling the example with gcc/g++, and I also have the same issue when compiling ffmpeg with either clang or gcc, which leads me to think that there is just something I don't know about linking that should be obvious, but I haven't found any references suggesting that it should be different linking a library in C++ vs. C, and linking other libraries (sox, for example) presents no difficulties with an identical setup. 我用gcc / g ++编译这个例子也有同样的问题,在使用clang或gcc编译ffmpeg时我也遇到同样的问题,这让我认为只有一些我不知道的关于链接的东西应该是显而易见的,但我没有找到任何引用,表明它应该是不同的链接C ++与C的库,并且链接其他库(例如,sox)对于相同的设置没有任何困难。

I have seen posts related to linking issues in Mac OS X 10.9 because of the change from libstdc++ to libc++, but adding -stdlib=libstdc++ or -stdlib=libc++ seems to make no difference. 我已经看到与Mac OS X 10.9中的链接问题有关的帖子,因为从libstdc ++到libc ++的更改,但添加-stdlib=libstdc++-stdlib=libc++似乎没有任何区别。 It also makes no difference to add -mmacosx-version-min=10.6 or 10.9 . 添加-mmacosx-version-min=10.610.9也没有区别。

Any help is greatly appreciated. 任何帮助是极大的赞赏。

You must inform the compiler that it should use C style name mangeling. 您必须通知编译器它应该使用C样式名称mangeling。 http://en.m.wikipedia.org/wiki/Name_mangling http://en.m.wikipedia.org/wiki/Name_mangling

extern "C"
{
#include <libswresample/swresample.h>
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM