G ++ Mac communication error while compiling FFMPEG

g ++ on Snow Leopard throws binding errors to the next code snippet

test.cpp

#include <iostream>
using namespace std;
#include <libavcodec/avcodec.h>    // required headers
#include <libavformat/avformat.h>
int main(int argc, char**argv) {
    av_register_all();             // offending library call
    return 0;
}

When I try to compile this using the following command

g++ test.cpp -I/usr/local/include -L/usr/local/lib \
-lavcodec -lavformat -lavutil -lz -lm -o test

I get the error Undefined characters: "av_register_all ()" referenced: _main in ccUD1ueX.o ld: character not found collect2: ld returned 1 exit status

I wonder if I have equivalent c code, test.c

#include <stdio.h>
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
int main(int argc, char**argv) {
    av_register_all();
    return 0;
}

gcc compiles it just fine

gcc test.c -I/usr/local/include -L/usr/local/lib \
-lavcodec -lavformat -lavutil -lz -lm -o test

I am using Mac OS X 10.6.5

$ g++ --version
i686-apple-darwin10-g++-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5664)
$ gcc --version
i686-apple-darwin10-gcc-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5664)

FFMPEG libavcodec, libavformat, etc. are the C libraries, and I created them on my machine, for example:

./configure --enable-gpl --enable-pthreads --enable-shared \
--disable-doc --enable-libx264
make && sudo make install

As you would expect, libavformat really contains the av_register_all character

$ nm /usr/local/lib/libavformat.a | grep av_register_all
0000000000000000 T _av_register_all
00000000000089b0 S _av_register_all.eh

I tend to believe that g ++ and gcc have different ideas about libraries on my machine. g ++ cannot find the right libraries. Any clue?

+3
2

, , av_register_all extern "C", , , ++, . :

#include <iostream>
using namespace std;
extern "C" {
#include <libavcodec/avcodec.h>    // required headers
#include <libavformat/avformat.h>
}
int main(int argc, char**argv) {
    av_register_all();             // offending library call
    return 0;
}

++, differents, C ( ).

, , C ++, , . , ffmpeg, :

// Standard includes guards
#ifndef INCLUDED_AVCODEC_H
#define INCLUDED_AVCODEC_H

// Protection against inclusion by a C++ file
#ifdef __cplusplus
extern "C" {
#endif

// C code
// ....

// Closing the protection against inclusion by a C++ file
#ifdef __cplusplus
}
#endif
#endif

[Edit]: , FFmpeg wiki.

+12

ffmpeg, , MacPorts. :

 sudo port install ffmpeg

, , UNIX, Linux, Mac. , MacPorts. , , , , , .

0

Source: https://habr.com/ru/post/1783241/


All Articles