PDA

View Full Version : gcc not finding header files?


Banana
2009-05-12, 20:40
As a excuse to learn a bit of C, I'm trying to write & compile a user-defined function for mysql. After some initial trouble, I decided to look at the template provided by mysql; udf_example.c

Using this (http://dev.mysql.com/doc/refman/5.1/en/udf-compiling.html) as a reference, I issued the command:

my-imac:sql me$ gcc -shared -o udf.example.so udf_example.c
udf_example.c:127:23: error: my_global.h: No such file or directory
udf_example.c:128:20: error: my_sys.h: No such file or directory
udf_example.c:139:19: error: mysql.h: No such file or directory
udf_example.c:142: error: syntax error before ‘LOCK_hostname’
udf_example.c:142: warning: data definition has no type or storage class

Which seems to be similar problem to what I was having with my .c (which is just a bunch of prototypes and empty functions); I simply can't compile them, even though they all are present in the same directory I tried to compile udf_example.c in.

I'm suspecting I'm missing a vital step; perhaps to declare to gcc where to look for the header files or something like that? Adjusting for the fact that I'm not really using Linux but rather a BSD derivative? Advices?

Thanks!

chucker
2009-05-12, 23:27
How do you refer to them?

#include <my_global.h> will look in the global header directories.
#include "my_global.h" will look in a relative path.

Banana
2009-05-13, 00:16
my files basically copied off the udf_examples.c, which generally used the <> forms.

Here's a extract of the top portion in the udf_example.c.

#ifdef STANDARD
/* STANDARD is defined, don't use any mysql functions */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#ifdef __WIN__
typedef unsigned __int64 ulonglong; /* Microsofts 64 bit types */
typedef __int64 longlong;
#else
typedef unsigned long long ulonglong;
typedef long long longlong;
#endif /*__WIN__*/
#else
#include <my_global.h>
#include <my_sys.h>
#if defined(MYSQL_SERVER)
#include <m_string.h> /* To get strmov() */
#else
/* when compiled as standalone */
#include <string.h>
#define strmov(a,b) stpcpy(a,b)
#define bzero(a,b) memset(a,0,b)
#define memcpy_fixed(a,b,c) memcpy(a,b,c)
#endif
#endif
#include <mysql.h>
#include <ctype.h>

The manual did not give any explicit instruction on how to deal with headers so I'm not sure if gcc even know where to get the mysql's header files (which are in the same directory).

chucker
2009-05-13, 01:39
Yeah, that's not gonna work unless the MySQL headers are globally installed. Try the "" form for the MySQL-specific stuff.

Banana
2009-05-13, 07:58
So I made a copy of the udf_example and replaced the <> with "" for mysql's headers, and made sure it had all headers it needed in the directory. This time I got even more errors which seems to be coming from the headers that's now found.

bash-3.2$ gcc -shared -c ./udf_example2.c -o ./udf_example.so
In file included from ./udf_example2.c:127:
./my_global.h:80:23: error: my_config.h: No such file or directory
./my_global.h:602:26: error: my_attribute.h: No such file or directory
./my_global.h:639:21: error: my_dbug.h: No such file or directory
In file included from ./udf_example2.c:127:
./my_global.h:678: error: syntax error before ‘size_socket’
./my_global.h:678: warning: data definition has no type or storage class
./my_global.h:803:2: error: #error "please add -DSTACK_DIRECTION=1 or -1 to your CPPFLAGS"
./my_global.h:871:1: warning: "isnan" redefined
In file included from /usr/include/math.h:28,
from ./my_global.h:420,
from ./udf_example2.c:127:
/usr/include/architecture/i386/math.h:162:1: warning: this is the location of the previous definition
In file included from ./udf_example2.c:128:
./my_sys.h:34:63: error: m_ctype.h: No such file or directory
./my_sys.h:36:21: error: typelib.h: No such file or directory
In file included from ./udf_example2.c:128:
./my_sys.h:224: error: syntax error before ‘*’ token
./my_sys.h:224: warning: data definition has no type or storage class
./my_sys.h:225: error: syntax error before ‘*’ token
./my_sys.h:225: warning: data definition has no type or storage class
./my_sys.h:226: error: syntax error before ‘compiled_charsets’
./my_sys.h:226: warning: data definition has no type or storage class
./my_sys.h:552:22: error: my_alloc.h: No such file or directory
./my_sys.h:650: error: syntax error before ‘ATTRIBUTE_FORMAT’
./my_sys.h:650: error: syntax error before numeric constant
./my_sys.h:650: warning: data definition has no type or storage class
./my_sys.h:680: error: syntax error before ‘RETSIGTYPE’
./my_sys.h:680: error: syntax error before ‘)’ token
./my_sys.h:715: error: syntax error before ‘*’ token
./my_sys.h:726: error: syntax error before ‘sigtstp_handler’
./my_sys.h:726: warning: data definition has no type or storage class
./my_sys.h:729: error: syntax error before ‘my_set_alarm_variable’
./my_sys.h:729: warning: data definition has no type or storage class
./my_sys.h:733: error: syntax error before ‘my_qsort’
./my_sys.h:734: warning: data definition has no type or storage class
./my_sys.h:735: error: syntax error before ‘my_qsort2’
./my_sys.h:736: warning: data definition has no type or storage class
./my_sys.h:831: error: syntax error before ‘*’ token
./my_sys.h:833: error: syntax error before ‘*’ token
./my_sys.h:834: error: syntax error before ‘*’ token
./my_sys.h:835: error: syntax error before ‘*’ token
./my_sys.h:836: error: syntax error before ‘*’ token
./my_sys.h:837: error: syntax error before ‘*’ token
./my_sys.h:839: error: syntax error before ‘*’ token
./my_sys.h:840: error: syntax error before ‘*’ token
./my_sys.h:841: error: syntax error before ‘*’ token
./my_sys.h:928: error: syntax error before ‘*’ token
./my_sys.h:928: warning: data definition has no type or storage class
./my_sys.h:929: error: syntax error before ‘*’ token
./my_sys.h:929: warning: data definition has no type or storage class
./my_sys.h:930: error: syntax error before ‘*’ token
./my_sys.h:931: warning: data definition has no type or storage class
./my_sys.h:934: error: syntax error before ‘CHARSET_INFO’
./my_sys.h:937: error: syntax error before ‘CHARSET_INFO’
./my_sys.h:942: error: syntax error before ‘*’ token
./my_sys.h:944: error: syntax error before ‘*’ token
./my_sys.h:945: error: syntax error before ‘*’ token
./my_sys.h:953: error: syntax error before ‘*’ token
In file included from ./udf_example2.c:133:
/usr/include/string.h:115: error: syntax error before ‘(’ token
/usr/include/string.h:115: error: syntax error before ‘const’
./udf_example2.c:142: error: syntax error before ‘LOCK_hostname’
./udf_example2.c:142: warning: data definition has no type or storage class

I can't help but feel that something is off because none of those needs to be defined at compile time; it's just a library (more specifically a plugin) meant to be loaded dynamically which presumably by then the rest of definitions will make sense.

Somerton Beach
2009-05-13, 08:41
I would try the following trick. Find the directory to where the header files are installed using the following find command:
sudo find / -type f -name "mysql.h"
Once you find the directories where the header are installed, you have to tell gcc where to look for the include using the -I directive. i.e.:
$ gcc -shared -o udf.example.so -I<Insert Path to Header Files Here> udf_example.c

Banana
2009-05-13, 08:49
Thanks, but I get same errors as previously posted when I try it. I don't think it's a issue of finding the headers (anymore now that I know about the -l and the "" forms) but rather compiling it without having to grab all headers in existence to satisfy all missing definitions. I could be wrong, though.