By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,187 Members | 1,659 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,187 IT Pros & Developers. It's quick & easy.

undeclared (first use this function) problem

P: 6
hello,

we are having problems in compiling a 'slightly' altered x264. We are always receiving a 'helloWorld' undeclared (first use this function) error. We may be commiting a very simple error but we just have to ask after looking through possible solutions that have not worked.

So far, we are able to successfully compile the x263 source (an unaltered one from the VideoLAN downloads section) using the instructions found at www.mplayerhq.hu. So now, we are trying to see if we can really access the library libx264.a using a method of ours which is adding a simple int-returning function named hellowWorld().

We are currently using Dev-Cpp. Our project directory contains the files:

main.cpp
libx264.a
x264_test.dev

In Project -> project options -> parameters:
libx264.a

In Project -> project options -> directories:
Library directory: our project directory
Include directory: our project directory


As for the source codes, here is the code for main.cpp:
------------------
#include <stdio.h>
#include <cstdlib>
#include <iostream>
#include < stdint.h>

int main(int argc, char *argv[])
{
argc = helloWorld();
system("PAUSE");
return EXIT_SUCCESS;
}
------------------
Note: as we are coding main.cpp, it can see the int helloWorld() function (through the autocomplete feature)

As i mentioned, we added a function named helloWorld() at the end of x264.c
------------------
...
static int close_file_mkv( hnd_t handle )
{
...
}

extern int helloWorld()
{
return -1;
}
------------------

We added the helloWorld prototype in x264.h:
------------------
extern int helloWorld();
------------------

And so, we compiled x264 again and tried to use the new libx264.a in our project. As we try to compile our own test project, we get the following errors:

Compile Log:
Compiler: Default compiler
Building Makefile: "C:\Documents and Settings\Michi and the others\Desktop\x264-test\Makefile.win"
Executing make...
make.exe -f "C:\Documents and Settings\Michi and the others\Desktop\x264-test\Makefile.win" all
g++.exe -c main.cpp -o main.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" -I"C:/Documents and Settings/Michi and the others/Desktop/x264-test"

main.cpp: In function `int main(int, char**)':

main.cpp:11: error: `helloWorld' undeclared (first use this function)
main.cpp:11: error: (Each undeclared identifier is reported only once for each function it appears in.)

make.exe: *** [main.o] Error 1

Execution terminated


We are currently stuck at this problem.I hope anybody could help us.

Thank you.
Nov 30 '06 #1
Share this Question
Share on Google+
7 Replies


DeMan
100+
P: 1,806
I may be way off, but methinks you should declare a prototype in a header (*.h) file. In my experience, the c (or c++) compiler likes to know what functions are available to call. This means they must be declared before you try to call them. If you declare it in the main file, it would have to be before the cal, if you declare it anywhere else, you need to include (a prototype of) it in one of the files that you #include <that is somewhere that is processed earlier by the compiler>

Short answer, try putting a prototype of the function in a fred.h file the add the line #include "fred.h" (note quotation marks not <>);

say the function is :
Expand|Select|Wrap|Line Numbers
  1. int average( int a, int b){
  2.   return (a+b)/2;
  3. }
  4.  
the prototype (in the header file) only needs to be

[code]
int average( int a, int b); /* note semicolon, no method body */
{/code]

Basically the function always has to be visible (I'm not sure whether the name of the .h file needs to be the same as the .c file the full method is stored in, but try that too)

Cheers
Nov 30 '06 #2

Expert 100+
P: 1,510
the prototype for helloWorld() is in header x264.h - if you include it in the file with main() it may fix the error
Expand|Select|Wrap|Line Numbers
  1. #include "x264.h"
  2.  
  3. int main(int argc, char *argv[])
  4.  
etc
Nov 30 '06 #3

DeMan
100+
P: 1,806
sorry, my bad, i should have rtfs
Nov 30 '06 #4

P: 6
the prototype for helloWorld() is in header x264.h - if you include it in the file with main() it may fix the error
Expand|Select|Wrap|Line Numbers
  1. #include "x264.h"
  2.  
  3. int main(int argc, char *argv[])
  4.  
etc
i already tried what you have proposed but it gave out the same errors.
Dec 1 '06 #5

P: 6
thank you so much for the replies, we need it really bad.

just to clarify things, we have only altered x264.c and x264.h in the whole (original) x264 project from VideoLAN. After which, we compiled this x264 project using MinGW, producing libx264.a which we are including in our test project. So we assume that we do not have to include x264.h again. But just to be safe, we did try it and the same errors occured.
Dec 1 '06 #6

DeMan
100+
P: 1,806
I'm not entirely sure why it needs to be declared 'extern'.
Dec 1 '06 #7

P: 6
I'm not entirely sure why it needs to be declared 'extern'.
ok, i'll try modifying that in bit, i'm having problems with cygwin and msys (they're both in my system) so i can't compile the library right now. thanks
Dec 2 '06 #8

Post your reply

Sign in to post your reply or Sign up for a free account.