Does not compile ffmpeg [duplicate] - c

This question already has answers here:
ffmpeg missing config.h in libavutil (No Such File or Directory) CodeBlocks
(2 answers)
Closed 4 years ago.
Translated.
I have a problem. When I try to compile a file in which h files ffmpeg are connected using gcc, I get an error that in the code ffmpeg is incorrectly written include, and it means that the file is in the current directory, although it should be in the next directory. How to fix it?
Includes in my C file:
#include "libavcodec/avcodec.h"
#include "libavformat/avformat.h"
#include "libswscale/swscale.h"
Error:
D:\gcc\bin>gcc -o a a.c -lavutil -lavformat -lavcodec -lz -
lavutil -lm
In file included from a.c:3:0: libavcodec/avcodec.h:31:33:
fatal error: libavutil/samplefmt.h: No such file or directory
#include "libavutil/samplefmt.h"
^
compilation terminated.
My answer:
I was able to solve the problem only by fixing the source code. First I added the libavutil/avconfig.h file with the contents:
#ifndef AVUTIL_AVCONFIG_H
#define AVUTIL_AVCONFIG_H
#define AV_HAVE_BIGENDIAN 0
#define AV_HAVE_FAST_UNALIGNED 0
#endif
Then if I saw an error where the directory and the file (libavutil/avutil) participate, I added "../" there, since this is the case where the directory is located next to the one where the file that caused the error is (../libavutil/avutil.h). In another case, if this file should be inside (only if the directory name matches the current one (libavutil/avutil.h)), you can either just leave the file name (avutil.h), or also add "../", the difference will not be. Such operations need to be repeated about 20 times until errors in all header files disappear. After that, you can safely compile ffmpeg without special knowledge and patches. Code for avconfig.h found on the Chinese site.

your 'compile' statement is missing the location of the header file. Suggest:
the compile/link statement should be similar to:
gcc -o a a.c -I./libavutil -lavutil -lavformat -lavcodec -lz -lavutil -lm
Caveat: I wrote the -I parameter as if the current/working directory contains libavutil as a sub directory. If this is not correct, then that parameter will need to be tweaked.

Related

Compiling C file which includes other header files

I am trying to compile a file Mv.c like - g++ microtime.c Mv.c
It gives an error - v.c:2:10: fatal error: microtime.h: No such file or directory 2 | #include <microtime.h>
My current directory has both microtime.h and microtime.c and Mv.c includes microtime.h
I am not sure how to go about compiling it.
Since my main program Mv.c is using microtime.h do I need to compile microtime.c first and pass it as an argument to g++?
I got it compiled by using the command g++ -I. Mv.c microtime.o
where microtime.o I generated using g++ -c microtime.c
I am not sure why this command works and why we need to specify the extra -I. option when I have already created the compiled object file microtime.o
If you write #include <microtime.h>, the compiler uses its list of system directories to look for the header file. By the option -I you add a directory to this list, and the compiler is happy.
To include project-local header files, use #include "microtime.h".
Read the chapter "Directory Options" in GCC's documentation to learn more.

Why can't we find the header file that actually exists?

I am a C language beginners, I encountered a problem, can not find the header file, but in fact, these header files are in the current file, I saw online methods (for example : solution) are to add - I option can solve this problem, but I am very curious, why can't it find itself, can only rely on - I option?
include path:
ls .
include test_ffmpeg.c
ls include/libavcodec/
avcodec.h avfft.h dirac.h dxva2.h vaapi.h vdpau.h videotoolbox.h xvmc.h
avdct.h d3d11va.h dv_profile.h qsv.h vda.h version.h vorbis_parser.h
source tree:
root
|-----test_ffmpeg.c
|-----include
code:
#include <stdio.h>
#include "./include/libavcode/avcodec.h"
#include "./include/libvformat/acfomat.h"
#include "./include/libavfilter/avfilter.h"
int main(void)
{
return 0;
}
compile:
gcc test_ffmpeg.c -lavcodec -lavdevice -lavfilter -lavformat -lavutil
a fatal error occured:
test_ffmpeg.c:3:10: fatal error: ./include/libavcode/avcodec.h: No such file or directory
#include "./include/libavcode/avcodec.h"
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
Your include statement mentions include/libavcode, but the path that exists is include/libavcodec.
Add a c and you should see a difference.

Error: no such file or directory - C

After interpreting this comment,
/***************** arrayImpl.c **************/
#include"list/list.h"
#if defined(ARRAY)
....
#endif
I wrote #include"list/list.h" in ./Computing/list/arrayImpl.c for testing Computing/list ADT using Computing/testList.c program, shown here.
But list/list.h could not be found by list/arrayImpl.c, as shown below,
PC ~/code_practice/Computing
$ gcc -Wall -g -DARRAY ./list/*.c testList.c -o testList
./list/arrayImpl.c:3:22: fatal error: list/list.h: No such file or directory
compilation terminated.
./list/linkedListImpl.c:3:22: fatal error: list/list.h: No such file or directory
compilation terminated.
How do I understand this error, after following that comment? Did I mis-interpret?
list.h is in the same directory as the c files which include it. When you do
#include "list/list.h"
the compiler tries to find the file in include path + /list. For instance, it will look for list/list/list.h which doesn't exist.
So what would work would be changing to #include "list.h"
OR
add current directory to the command line using -I. so list/list.h is in include path.
gcc -Wall -g -I. -DARRAY ./list/*.c testList.c -o testList
From gcc search path documentation
-I. -I- is not the same as no -I options at all, and does not cause the same behavior for ‘<>’ includes that ‘""’ includes get with no special options. -I. searches the compiler's current working directory for header files. That may or may not be the same as the directory containing the current file.
It's not mentioned anywhere that include path contains the current directory, from which gcc was started.
You need to add include file directory "list".
https://gcc.gnu.org/onlinedocs/gcc/Directory-Options.html
gcc -Wall -g -DARRAY ./list/*.c testList.c -I list -o testList
And you must remove "list" from "#include "list/list.h". Because when you write that you tell to the compiler to search in all include directory a file "list/list.h". But "list.h" is in "list". So "list" is not necessary.
#include "list.h"
You could do that but it's ugly
#include "../list/list.h"

Include gsl_type.h. File not found

It seems to be a common issue but I can't wrap solve this problem.
I have some .c code that I compile using a makefile. The goal is to create a shared object (.so) so that I can run the C code from R.
Here is my makefile:
obs = R_wrapper.o G.o develop.o utilities.o
CFLAGS = -arch x86_64 -std=gnu99 -I/Library/Frameworks/R.framework/Resources/include -I/Library/Frameworks/R.framework/Resources/include/x86_64 -DNDEBUG -I/usr/local/include -fPIC -g -O3 -c
LFLAGS = -arch x86_64 -std=gnu99 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/usr/local/lib -O3 -lgsl -lm -lgslcblas
R_wrapper : $(obs)
$gcc $(LFLAGS) $(obs) -o R_wrapper.so
R_wrapper.o : R_wrapper.c constants.h develop.h G.h
$gcc $(CFLAGS) R_wrapper.c
G.o : G.c G.h constants.h utilities.h develop.h
$gcc $(CFLAGS) G.c develop.c
develop.o : develop.c develop.h G.h constants.h
$gcc $(CFLAGS) develop.c
utilities.o : utilities.c develop.h
$gcc $(CFLAGS) utilities.c
It works fine on the computer in my lab but it doesn't work on my personal computer. What causes this issue is these two lines at the beginning of my R_wrapper.c.
#include </opt/local/include/gsl/gsl_randist.h>
#include </opt/local/include/gsl/gsl_rng.h>
I have tried to move these files around and give different paths, put the files in the gal_type.h files in the same directory as my R_wrapper file, I have tried to rename my directories so that the path is more conventional but the OS did not give me the right to rename opt into usr (which probably makes obvious sense). I haven't created the makefile and don't fully get it. I would suppose I'd need to modify the path after the -I argument somewhere in CFLAGS OR LFLAGS.
EDIT 1
I changed R_wrapper.c on my lab computer to get rid of the whole path in #include <...>. Compilation failed as #Beta predicted. Then, I changed my makefile to add -I/opt/local/include/gsl to CFLAGS. I don't know what you mean by Verify that the makefile still works. I tried to compile with my edited makefile on my lab computer and it failed. I then re-edited my makefile changing -I/opt/local/include/gsl to -I/usr/local/include/gsl because on my lab computer the gsl folder is at /usr/local/include/gsl. -I/opt/local/include/gsl is the location of the gsl folder on my computer. So I am stuck here in your procedure.
Edit 2
I moved my gsl folder around my computer trying to include from different paths. And some interesting stuff happen. For example when I put my gsl folder in Users/remi/Documents/Biologie/programing/C/ and write (in CFLAGS)
-I/Users/remi/Documents/Biologie/programing/C/
I get this error:
R_wrapper.c:43:10: fatal error: 'gsl_randist.h' file not found
#include <gsl_randist.h> // goal.
When I write (in CFLAGS)
Users/remi/Documents/Biologie/programing/C/gsl
I get this error message:
"In file included from R_wrapper.c:43: /Users/remi/Documents/Biologie/programing/C/gsl/gsl_randist.h:22:10: fatal error:
'gsl/gsl_rng.h' file not found
#include <gsl/gsl_rng.h>"
Transferring comment to answer
Judging from the message about gsl/gsl_rng.h not being found that is mentioned in Edit 2, you should be writing
#include <gsl/gsl_randist.h>
(with the path prefix of gsl/ before the header name) in your source code. This is a common convention. You then specify in the -I option the name of the directory containing the gsl subdirectory that contains the gsl_*.h headers. In your Edit 2, you say you put the gsl directory into /Users/remi/Documents/Biologie/programing/C/, so you are then correct to use:
-I/Users/remi/Documents/Biologie/programing/C/
on the command line as you tried.
You should read the documentation, and if it says write either of these:
#include <gsl/gsl_randist.h>
#include "gsl/gsl_randist.h"
then that is what you should write in your code, because (as you've discovered the hard way) if you don't, it won't work.
Beta's answer also states
In general it's a bad idea to write paths into the #include statements unless you really have to; it causes just this kind of problem.
I agree, but would state it more strongly:
Do not write complete paths into the #include statements ever.
If you do write them, it radically limits the portability of your code. You can't rely on other people's machines having software installed in the same place as it is installed on your system. If you tried it in open source software, you'd be laughed out of court.
Be wary of people who get cute with ../somedir/header.h too — see What are the benefits of a relative path such as "../include/header.h" for a header?.
I observe that the GNU Scientific Library manual has an example program which starts:
#include <stdio.h>
#include <gsl/gsl_sf_bessel.h>
and the section on Compiling and Linking says:
The library header files are installed in their own gsl directory. You should write any preprocessor include statements with a gsl/ directory prefix thus,
#include <gsl/gsl_math.h>
If the directory is not installed on the standard search path of your compiler you will also need to provide its location to the preprocessor as a command line flag. The default location of the gsl directory is /usr/local/include/gsl.
In general it's a bad idea to write paths into the #include statements unless you really have to; it causes just this kind of problem.
On your lab computer, edit R_wrapper.c:
#include <gsl_randist.h>
#include <gsl_rng.h>
The build should now fail. If so then this verifies that you don't have other versions of these headers floating around, or links to them, or whatever. Confirm that it fails, then back out the change, and confirm that it works again.
Then add -I/opt/local/include/gsl to CFLAGS. Verify that the makefile still works.
Then edit R_wrapper.c again; now the build should succeed.
Decide where you would like to keep these files (gsl_randist.h and gsl_rnd.h) on your personal computer, and modify CFLAGS accordingly on your home version of the makefile.
Once all of that is working perfectly, we can show you how to write one makefile that will work on both machines.
Also, you can improve your makefile rules in other ways, but I must ask one question first:
G.o : G.c G.h constants.h utilities.h develop.h
$gcc $(CFLAGS) G.c develop.c
Does G.o really require develop.c? If so then you should probably reexamine your source files, because this is really unhygienic.

GCC unable to find header file in a included library

I am trying to include a library file named libmathematica.a in gcc so it gets linked in the executable example.
I attempt to do this with gcc main.c libmathematica.a -o example
Note: I have to do this with gcc, as ld won't link it properly with the correct system libraries
But I get: fatal error: mathematica.h: No such file or directory ,which is odd because mathematica.h is in the library.
Can you help?
A header file cannot be in the library. It has to be present at a certain location and you have to specify that location with the -I compiler flag:
gcc -I/path/to/mathematica/include main.c libmathematica.a -o example
If the header file is in the directory where the main.c is or in a subdirectory, then be sure that you use quotes and not angle brackets in the #include directive.
The issue would be in your source file. If the mathematica.h is in the system includes directory then you would use #include <mathematica.h> and if it was in some local directory then you would use something like #include "libs/mathematica.h".
Try adding to the gcc call - an option like
-I/Full/Path/To/The/Directory/Where/the/desired/header/resides
For example:
gcc -I/usr/include/mathematica -lmathematica -o example main.c

Resources