0

When I try to compile my cpp file in which the header files from ffmpeg are connected:

  #include <stdio.h>
  #include <windows.h>
  extern "C"
  {
      #include "libavcodec/avcodec.h"
      #include "libavformat/avformat.h"
      #include "libswscale/swscale.h"
  }

  int main(int argc, char* argv[])
  {
      if(argc < 2)
      {
          printf("Usage: %s filename\n", argv[0]);
      }
      av_register_all();
      return 0;
  }

When compiling with a simple command I get:

  D:\gcc\bin>g++ -o a a.cpp
  C:\users\root\Temp\ccC9UvT7.o:a.cpp:(.text+0x2a): undefined reference to 'av_register_all'
  collect2.exe: error: ld returned 1 exit status

Using a more complex I get:

  D:\gcc\bin>g++ -o a a.cpp -lavutil -lavformat -lavcodec -lz
  d:/gcc/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe: cannot -lavutil
  d:/gcc/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe: cannot -lavformat
  d:/gcc/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe: cannot -lavcodec
  d:/gcc/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe: cannot -lz
  collect2.exe: error: ld returned 1 exit status

How can I fix this?

Hask
  • 1
  • 1
  • If you program in C++ then please don't add the C language tag. C++ and C are two very different languages. – Some programmer dude Apr 04 '18 at 06:24
  • And please *copy-paste* the errors you get. "cannot -lavutil"? That's not the correct message. – Some programmer dude Apr 04 '18 at 06:28
  • I see this also in C – Hask Apr 04 '18 at 06:30
  • Help please, I cant find this in internet! – Hask Apr 04 '18 at 07:04
  • Have you *installed* the libraries? In the *standard locations*? And have you tried to read the duplicate and its answers? – Some programmer dude Apr 04 '18 at 07:14
  • What does it mean installed, and what libraries? I just connected the header files. The duplicate says something else, but my situation is different, with the import of h files from ffmpeg. And if I try to enter the parameters of the libraries when compiling, then it does not recognize them, you saw errors. – Hask Apr 04 '18 at 07:35
  • The errors means that the library files are not available. And you need the library files to not get the undefined reference errors. Where are the library files (the file you attempt to link with the `-l` option, like `avutil`)? Perhaps you should take a few steps back and try something simpler and work your way up until you know what all this means? – Some programmer dude Apr 04 '18 at 07:38
  • If they were not available, I would get an include error, but everything is fine, and I just checked that the bat file, cpp file and ffmpeg folders are near. Therefore, everything is in place. What to do next? Where I can find -l syntax? – Hask Apr 04 '18 at 08:10
  • Just because the header file are available doesn't automatically mean the actual libraries are. You need to actually *search* for them, to see if they are in your system. – Some programmer dude Apr 04 '18 at 08:13
  • Which libraries? How do they look (extension), where should they be in windows? Or in the source code? H files have the same names, but not next to the bat file, but inside the directory. Why the -l option is written together, and how there add / if he needs h files? -lz is incomprehensible to me, there is no file with that name (z), but it seems to be a standard function, why is it not recognized? And why do I need to use -l? Why does not include the function av_register_all ()? – Hask Apr 04 '18 at 08:19
  • How? This dont help me, but patch to h files real. g++ -o a a.cpp -llibavutil/avutil -llibavformat/avformat -llibavcodec/avcodec – Hask Apr 04 '18 at 10:12
  • check here for linux format : https://github.com/abdullahfarwees/screen-recorder-ffmpeg-cpp/blob/master/compile.sh – Abdullah Farweez Apr 17 '18 at 07:18

0 Answers0