이 아닙니다. 주어진 파일의 비디오 재생 시간을 결정하기 위해 libavformat을 사용합니다. 다음과 같이 내 프로그램은 같습니다gcc가 libavformat 코드를 컴파일하지만, g ++이
#include <stdio.h>
#include <libavformat/avformat.h>
#include <libavutil/dict.h>
int main (int argc, char **argv) {
AVFormatContext *fmt_ctx = NULL;
int ret;
if (argc != 2) {
printf("usage: %s <input_file>\n", argv[0]);
return 1;
}
av_register_all();
if ((ret = avformat_open_input(&fmt_ctx, argv[1], NULL, NULL)))
return ret;
int64_t duration = fmt_ctx->duration;
int hours, mins, secs;
secs = duration/AV_TIME_BASE;
mins = secs/60;
secs %= 60;
hours = mins/60;
mins %= 60;
printf("Duration: %02d:%02d:%02d\n", hours, mins, secs);
avformat_free_context(fmt_ctx);
return 0;
}
내 문제는 GCC뿐만 아니라 불평없이 그렇게 ++ 잘 코드, g를 컴파일하지만 동안 생성 된 오브젝트 파일이 둘의 gcc 나 g ++로 연결되지 않을 수 있다는 것입니다. 또는 더 정확하게하려면 :
gcc -c duration.c
gcc -o duration duration.o -lavformat
./duration my_movie.mp4
작품. 하지만이
g++ -c duration.C# "works" as in "g++ does not complain"
g++ -o duration duration.o -lavformat # (gcc produces the same output after compiling with g++)
duration.o: In function `main':
duration.c:(.text+0x41): undefined reference to `av_register_all()'
duration.c:(.text+0x62): undefined reference to `avformat_open_input(AVFormatContext**, char const*, AVInputFormat*, AVDictionary**)'
duration.c:(.text+0x18c): undefined reference to `avformat_free_context(AVFormatContext*)'
collect2: error: ld returned 1 exit status
이 작동하지 않습니다. 이것은 g ++가 (이 경우) 제대로 링크 될 수있는 코드를 생성하지 않는다는 결론에 이르게합니다.
더 큰 C++ 프로젝트의 일부이기 때문에 g ++로이 라이브러리를 사용하는 파일을 항상 컴파일해야하기 때문에 g ++로이 작업을 정말로하고 싶습니다. 왜 g ++가이 프로그램을 올바르게 컴파일하지 않는지 아는 사람이 있습니까?
아마도 맹 글링 문제 일 수 있습니까? 'extern "C"' – Dmitri
과 함께 포함을 래핑 해보십시오. 여러분이 이름 - mangling에 문제가있는 것 같네요. 'extern "C"'을 뿌리려고 할 수 있습니다. 또는 C와 C++이 다른 언어임을 인정하십시오. – EOF
왜 C 코드가 다른 언어로 컴파일되어야한다고 생각하십니까? – Olaf