Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Problem in addin new heder files to my program (http://www.go4expert.com/forums/addin-heder-files-program-t26216/)

ahrouhi 6Jul2011 09:15

Problem in addin new heder files to my program
Hi everybody
I am using DEV C++ compiler and write simple standard C code in this compiler. I encontered a problem when i included some new header files and wnated to use some of the functions inside the header files.
I updated the include file directory and add the location of new header files to the compiler but still the compiler can not recognise the function which are in new header files. Whats your advice?:thinking:

xpi0t0s 6Jul2011 12:23

Re: Problem in addin new heder files to my program

Originally Posted by ahrouhi (Post 84727)
I encontered a problem

I see you're fairly new here. Think through this problem description for a moment. How descriptive is it? How likely is it that we'll be able to provide a solution?

ahrouhi 7Jul2011 06:12

Re: Problem in addin new heder files to my program
You are right, my explanation about the problem was so naive. My problem is that i wnat to use an open source software(ffmpeg) which has written in C. I have downloaded all header files and other related source file and also ffmpeg.c file in a folder. I want to compile ffmpeg.c so i do the following:
1-Open ffmpeg.c file in DEV C++ compiler.
2-Set Include directory from tools/compiler options/ directories to ffmpeg/libavcodec (folder containing headers).
(There is a another setting place for libraries which i dont know i should set it to which directory.)
3-Compile the program.

But I get many compile time errors such as:
"Line 30 In file include c:\.......libavutil\avutil.h" and when i look at the line in that header file it is just a global variable.
Whats your advice?

ahrouhi 7Jul2011 07:07

Re: Problem in addin new heder files to my program
regarding the above mentioned problem, If you have a look in this link, You may get my mean in another point of view:
In the link, the author easily describe how to add a header file and then use the functions used in header files. But when i follow the same on my code, i encounter the problem again:
the simple line of code is here:

#include <iostream>
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <ffmpeg/avcodec.h>
#include <ffmpeg/avformat.h>
int main(int argc, char *argv[])
AVFormatContext *pFormatCtx;

// Open video file
if(av_open_input_file(&pFormatCtx, argv[1], NULL, 0, NULL)!=0)
return -1; // Couldn't open file
But the compiler at first function call : av_register_all();
make an error and says "av_register_all undeclared"
I know that header files just contain the function prototypes. do i need install appropriate dll? Do i have to make a linking file first? How?

xpi0t0s 7Jul2011 12:27

Re: Problem in addin new heder files to my program
Please post the *exact* error messages. Do not attempt to reinterpret them; you remove the essential information that helps experts determine the cause. Feel free to ADD your interpretation, but do not post ONLY your interpretation.

Are the errors thrown by the compiler or the linker? These have very different implications.

ahrouhi 7Jul2011 12:41

Re: Problem in addin new heder files to my program
Sorry about that.the error is compiler error and the compiler log is:

Compiler: Default compiler
Executing g++.exe...
g++.exe "C:\1-Rouhi-Personal\My-C-H264\MyFrameCounter\test2.cpp" -o "C:\1-Rouhi-Personal\My-C-H264\MyFrameCounter\test2.exe" -g3 -I"d:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include" -I"d:\Dev-Cpp\include\c++\3.4.2\backward" -I"d:\Dev-Cpp\include\c++\3.4.2\mingw32" -I"d:\Dev-Cpp\include\c++\3.4.2" -I"d:\Dev-Cpp\include" -L"d:\Dev-Cpp\lib" -L"C:\1-Rouhi-Personal\SoftwareH264\SoftwareFFMPEG\ffmpegWinComm and-0.5\libavcodec" -L"C:\1-Rouhi-Personal\SoftwareH264\SoftwareFFMPEG\ffmpegWinComm and-0.5\libavformat" -g3
C:\1-Rouhi-Personal\My-C-H264\MyFrameCounter\test2.cpp:5:28: ffmpeg/avcodec.h: No such file or directory
C:\1-Rouhi-Personal\My-C-H264\MyFrameCounter\test2.cpp:6:29: ffmpeg/avformat.h: No such file or directory
C:\1-Rouhi-Personal\My-C-H264\MyFrameCounter\test2.cpp: In function `int main(int, char**)':
C:\1-Rouhi-Personal\My-C-H264\MyFrameCounter\test2.cpp:9: error: `av_register_all' undeclared (first use this function)
As can be seen even header files did not recognise.

xpi0t0s 8Jul2011 11:04

Re: Problem in addin new heder files to my program
OK, you need to learn to read an error list, specifically you must start with the FIRST error not the LAST.

The first error is this:
C:\1-Rouhi-Personal\My-C-H264\MyFrameCounter\test2.cpp:5:28: ffmpeg/avcodec.h: No such file or directory

which explains exactly why it doesn't know what an av_register_all is - this is most likely declared in one of those headers.

The compiler (actually the preprocessor) looks in the current directory, in a series of "standard" locations, and at -I clauses on the command line to find header files. The only -I's you've specified are:


so it's my guess that d:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include\ffmpeg/avcodec.h,
and the other three, don't exist.

As you've told the linker (with -L) to look in
C:\1-Rouhi-Personal\SoftwareH264\SoftwareFFMPEG\ffmpegWinComm and-0.5\libavcodec
C:\1-Rouhi-Personal\SoftwareH264\SoftwareFFMPEG\ffmpegWinComm and-0.5\libavformat
for libraries, you need to locate avcodec.h somewhere under
then add - not THAT directory, but the directory that contains the ffmpeg directory that itself contains avcodec.h, to the g++ line as another -I clause.

When linking with non-standard libraries, you normally need to tell the preprocessor where to find headers with -I and the linker where to find libraries with -L and/or -l (lower case L).

This also highlights what to do about multiple errors. The fix for the first error should fix the second, and in this case also the third. This is useful when faced with 100s of errors; don't lose your cool, just look at the first 2-3 errors and fix those, then recompile before moving on to the next.

ManzZup 8Jul2011 21:22

Re: Problem in addin new heder files to my program
whats you have to understand is that ffmpeg is one of those large project with many headers and other interconnected files which are needed to be included in order for even the smallest thing to work

so if you follow uo a dicumentation by ffmpeg by itself closely it will be better

All times are GMT +5.5. The time now is 11:08.