473,387 Members | 1,504 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

#include errors

Hi,

I've been banging my head against this for a while now. Hoping someone
here can shed some light on what's going on.

On including stdlib.h in a file, I'm seeing the following errors:

----BEGIN ERRORS----
gcc -g3 -DUSE_LIBC -Wall -c -I../mm -I../include -I/usr/include
-I/usr/include/linux -o mm_tree_test.o mm_tree_test.c
In file included from mm_tree_test.c:2:
/usr/include/stdlib.h:137: error: syntax error before
"__ctype_get_mb_cur_max"
In file included from /usr/include/sys/types.h:266,
from /usr/include/stdlib.h:416,
from mm_tree_test.c:2:
/usr/include/bits/pthreadtypes.h:50: error: syntax error before "size_t"
/usr/include/bits/pthreadtypes.h:53: error: syntax error before
"__stacksize"
In file included from mm_tree_test.c:2:
/usr/include/stdlib.h:433: error: syntax error before "size_t"
/usr/include/stdlib.h:462: error: syntax error before "size_t"
/usr/include/stdlib.h:556: error: syntax error before "__size"
/usr/include/stdlib.h:558: error: syntax error before "__nmemb"
/usr/include/stdlib.h:567: error: syntax error before "size_t"
In file included from /usr/include/stdlib.h:578,
from mm_tree_test.c:2:
/usr/include/alloca.h:33: error: syntax error before "__size"
In file included from mm_tree_test.c:2:
/usr/include/stdlib.h:583: error: syntax error before "__size"
/usr/include/stdlib.h:739: error: syntax error before "size_t"
/usr/include/stdlib.h:743: error: syntax error before "size_t"
/usr/include/stdlib.h:812: error: syntax error before "size_t"
/usr/include/stdlib.h:815: error: syntax error before "size_t"
/usr/include/stdlib.h:819: error: syntax error before "size_t"
/usr/include/stdlib.h:822: error: syntax error before "size_t"
/usr/include/stdlib.h:830: error: syntax error before "size_t"
/usr/include/stdlib.h:833: error: syntax error before '*' token
/usr/include/stdlib.h:837: error: syntax error before "wchar_t"
/usr/include/stdlib.h:841: error: syntax error before "mbstowcs"
/usr/include/stdlib.h:841: error: syntax error before '*' token
/usr/include/stdlib.h:844: error: syntax error before "wcstombs"
/usr/include/stdlib.h:845: error: syntax error before '*' token
mm_tree_test.c: In function `main':
----END ERRORS----

I've posted all relevant code below. If I remove the line:

#include <stdlib.h>

from mm_tree_test.c, the errors go away. Any ideas?

Thanks in advance.

zolli
----BEGIN mm_tree_test.c----
#include <mm_tree.h>
#include <stdlib.h>
#include <macro.h>

int main( int argc, char** argv ) {
/* do nothing */
return 0;
}
----END mm_tree_test.c----
----BEGIN mm_tree.h----
#ifndef INCLUDE_MM_TREE_H
#define INCLUDE_MM_TREE_H

#include <stdtype.h>

struct mm_avlnode_str
{
uint32 val;
struct mm_avlnode_str *left;
struct mm_avlnode_str *right;
int32 height;
};
....(truncated)...
#endif /* INCLUDE_MM_TREE_H */
----END mm_tree.h----
----BEGIN mm_tree.c----
#include "mm_tree.h"
#include <macro.h>

/* pre-declarations */
static mmTreeNode insert( mmTreeNode node, mmTreeNode root );
static mmTreeNode remove( mmTreeNode node, mmTreeNode root );
....(truncated)...

/* API function implementations defined in .h */
void mmTree_insert( mmTree t, mmTreeNode node ) {
t->root = insert( node, t->root );
}
void mmTree_remove( mmTree t, mmTreeNode node ) {
t->root = remove( node, t->root );
}
....(truncated)...
----END mm_tree.c----
----BEGIN stdtype.h----
#ifndef INCLUDE_STDTYPE_H
#define INCLUDE_STDTYPE_H

typedef enum { FALSE, TRUE } bool;
#define ARCH_32_BIT 1
#define PAGE_LEN 0x1000 /* 4K */

#ifdef ARCH_32_BIT
#define int32 int
#define uint32 unsigned int
#define int16 short int
#define uint16 unsigned short int
#define int8 char
#define uint8 unsigned char
#define byte unsigned char
#endif

#define ulong unsigned long int
#define uint unsigned int
#define ushort unsigned short int
#define uchar unsigned char

#ifndef NULL
#define NULL ((void *)0)
#endif

#endif /* INCLUDE_STDTYPE_H */
----END stdtype.h----
----BEGIN macro.h----
#ifndef INCLUDE_MACRO_H
#define INCLUDE_MACRO_H

extern int printf(const char *format, ...);

#define log_err(format, args...) \
printf("[ERROR]%s:%d:%s(): " format "\n", \
__FILE__,__LINE__,__FUNCTION__, ##args)
#define log_warn(format, args...) \
printf("[WARN]%s:%d:%s(): " format "\n", \
__FILE__,__LINE__,__FUNCTION__, ##args)
#define log_trace(format, args...) \
printf("[TRACE]%s:%d:%s(): " format "\n", \
__FILE__,__LINE__,__FUNCTION__, ##args)
#define log_trace_fxn() \
printf("[TRACE-FXN]%s:%d:%s(): \n", \
__FILE__,__LINE__,__FUNCTION__)
#define log_dbg(format, args...) \
printf("[DEBUG]%s:%d:%s(): " format "\n", \
__FILE__,__LINE__,__FUNCTION__, ##args)
#define log_ver(format, args...) \
printf("[VERBOSE]%s:%d:%s(): " format "\n", \
__FILE__,__LINE__,__FUNCTION__, ##args)

#endif /* INCLUDE_MACRO_H */
----END macro.h----
Nov 15 '05 #1
9 6387
zolli <zo***@nospamplease.net> wrote:
I've been banging my head against this for a while now. Hoping someone
here can shed some light on what's going on.

On including stdlib.h in a file, I'm seeing the following errors:
[ Snip syntax errors. ]
I've posted all relevant code below. If I remove the line:

#include <stdlib.h>

from mm_tree_test.c, the errors go away. Any ideas? ----BEGIN mm_tree_test.c----
#include <mm_tree.h>
#include <stdlib.h>
Yes. There is probably an error on the last code line of <mm_tree.h>.
----BEGIN mm_tree.h----
#ifndef INCLUDE_MM_TREE_H
#define INCLUDE_MM_TREE_H

#include <stdtype.h>

struct mm_avlnode_str
{
uint32 val;
struct mm_avlnode_str *left;
struct mm_avlnode_str *right;
int32 height;
};
...(truncated)...
#endif /* INCLUDE_MM_TREE_H */
----END mm_tree.h----


I.e., the last bit of "(truncated)" probably has a syntax error.

Richard
Nov 15 '05 #2
zolli wrote:
I've posted all relevant code below.
Not true. You have failed to include the definitions for mmTreeNode and
mmTree.
If I remove the line:
#include <stdlib.h>
from mm_tree_test.c, the errors go away. Any ideas?
Of course. Clean up the mess, so you don't confuse yourself with your
multiple inclusions. What happens when you include that code directly?
The last lines of <mm_tree.h> (do you really mean to use angle
brackets?) seem to interfere with <stdlib.h>. ----BEGIN mm_tree_test.c----
#include <mm_tree.h>
#include <stdlib.h>
There's no way for us to tell, since you have very inconveniently
replaced the end of mm_tree.h with ...(truncated)...
#endif /* INCLUDE_MM_TREE_H */


Nov 15 '05 #3
Hi,

Richard Bos wrote:
zolli <zo***@nospamplease.net> wrote:

I've been banging my head against this for a while now. Hoping someone
here can shed some light on what's going on.

On including stdlib.h in a file, I'm seeing the following errors:

[ Snip syntax errors. ]


Thanks for the replies. I spent some more time on this: stripping down
everything to the bare minimum, verifying that mm_tree.o compiles just
fine by itself, running the code through the preprocessor (gcc -E) &
examining the output. What a pain.

Turns out if I remove these two includes from the Makefile:

-I/usr/include -I/usr/include/linux

then everything works as expected. Not sure why. The system is debian
3.1; I suspect there's something going on with the way gcc tracks down
the system includes.

Thanks again for the help.

zolli

----BEGIN mm_tree_test.c----
#include <mm_tree.h>
#include <stdlib.h>

Yes. There is probably an error on the last code line of <mm_tree.h>.

----BEGIN mm_tree.h----
#ifndef INCLUDE_MM_TREE_H
#define INCLUDE_MM_TREE_H

#include <stdtype.h>

struct mm_avlnode_str
{
uint32 val;
struct mm_avlnode_str *left;
struct mm_avlnode_str *right;
int32 height;
};
...(truncated)...
#endif /* INCLUDE_MM_TREE_H */
----END mm_tree.h----

I.e., the last bit of "(truncated)" probably has a syntax error.

Richard

Nov 15 '05 #4
zolli <zo***@nospamplease.net> wrote:

[ Please don't mail _and_ post follow-ups. ]
Richard Bos wrote:
zolli <zo***@nospamplease.net> wrote:
I've been banging my head against this for a while now. Hoping someone
here can shed some light on what's going on.

On including stdlib.h in a file, I'm seeing the following errors:
[ Snip syntax errors. ]

Turns out if I remove these two includes from the Makefile:

-I/usr/include -I/usr/include/linux

then everything works as expected. Not sure why.


I do; you've probably broken your make. Try #including another standard
header (e.g., <stdio.h> somewhere and see if it works. In any case, I do
suspect that you've just glossed over the symptoms, and not solved your
actual problem.

Richard
Nov 15 '05 #5
On 24 Aug 2005 00:56:02 -0500,
zolli <zo***@nospamplease.net> wrote:


Turns out if I remove these two includes from the Makefile:

-I/usr/include -I/usr/include/linux

then everything works as expected. Not sure why. The system is debian
3.1; I suspect there's something going on with the way gcc tracks down
the system includes.


That is because the search sequence does make a difference, and /usr/include
should not be searched before other system and architecture dependent include
directories. These directories are specified in the compiler set-up, and if
you specify -I/usr/include you will upset the proper search sequence.

Specifying -I /usr/include/linux is almost always a mistake. Include files
from this directory should by included using #include <linux/xxx.h>. That
being said, user level programs should only in very rare circumstances
include anything directly from this directory.

Villy
Nov 15 '05 #6
Richard Bos wrote:
zolli <zo***@nospamplease.net> wrote:

[ Please don't mail _and_ post follow-ups. ]


Sorry about that; hit Reply-all instead of Reply.
Richard Bos wrote:
zolli <zo***@nospamplease.net> wrote:
I've been banging my head against this for a while now. Hoping someone
here can shed some light on what's going on.

On including stdlib.h in a file, I'm seeing the following errors:

[ Snip syntax errors. ]


Turns out if I remove these two includes from the Makefile:

-I/usr/include -I/usr/include/linux

then everything works as expected. Not sure why.

I do; you've probably broken your make. Try #including another standard
header (e.g., <stdio.h> somewhere and see if it works. In any case, I do
suspect that you've just glossed over the symptoms, and not solved your
actual problem.


That's quite possible. I'm new to C programming; I'll post the complete
test code here so you can take a look. If I'm doing something
fundamentally wrong, I'd like to know. In the Makefile, if I replace
this line:
INCLUDES := -I../mm
with this line:
INCLUDES := -I../mm -I/usr/include -I/usr/include/linux

The aforementioned errors are seen.

The directory structure looks like this:
/test/Makefile
/test/mm_tree_test.c
/mm/mm_tree.h
/mm/mm_tree.c

Thanks,
zolli
<Makefile>
all: mm_tree_test

CC := gcc
CFLAGS = -g3 -DUSE_LIBC -Wall
INCLUDES := -I../mm -I../include

mm_tree_test.o: mm_tree_test.c ../mm/mm_tree.h ../mm/mm_tree.c
cd ../mm && $(CC) $(CFLAGS) -c $(INCLUDES) -o mm_tree.o mm_tree.c && cd
.../test
$(CC) $(CFLAGS) -c $(INCLUDES) -o $@ $<
mm_tree_test: mm_tree_test.o
$(CC) $(CFLAGS) -o mm_tree_test mm_tree_test.o ../mm/mm_tree.o
clean:
rm *.o
</Makefile>
<mm_tree_test.c>
#include <stdlib.h>
#include <mm_tree.h>

int main( int argc, char** argv ) {
return 0;
}
</mm_tree_test.c>
<mm_tree.h>
#ifndef INCLUDE_MM_TREE_H
#define INCLUDE_MM_TREE_H

#ifndef NULL
#define NULL ((void *)0)
#endif

struct avlnode
{
int val;
struct avlnode *left;
struct avlnode *right;
int height;
};
struct avltree
{
struct avlnode *root;
};
int avltree_height( struct avltree *t );

#endif
</mm_tree.h>
<mm_tree.c>
#include "mm_tree.h"

static int height( struct avlnode *node );

int mmTree_height( struct avltree *t ) {
return height( t->root );
}
static int height( struct avlnode *node ) {
if( node == NULL ) {
return -1;
}
return node->height;
}
</mm_tree.c>
Nov 15 '05 #7
zolli wrote:
Richard Bos wrote:
<snip>
test code here so you can take a look. If I'm doing something
fundamentally wrong, I'd like to know. In the Makefile, if I replace
this line:
INCLUDES := -I../mm
with this line:
INCLUDES := -I../mm -I/usr/include -I/usr/include/linux

The aforementioned errors are seen.
So don't do that. Nothing in your code requires it and nothing should
*ever* require adding /usr/include explicitly to the path. Ask in a
Linux group for details about search paths.
The directory structure looks like this:
/test/Makefile
/test/mm_tree_test.c
/mm/mm_tree.h
/mm/mm_tree.c

Thanks,
zolli
<Makefile>
all: mm_tree_test

CC := gcc
CFLAGS = -g3 -DUSE_LIBC -Wall
I would suggest
CFLAGS = -g3 -O -DUSE_LIBC -Wall -ansi -pedantic
Possibly even loose the -DUSE_LIBC since I can't see why you are doing it.
INCLUDES := -I../mm -I../include
Just have
INCLUDES := -I../mm
mm_tree_test.o: mm_tree_test.c ../mm/mm_tree.h ../mm/mm_tree.c
cd ../mm && $(CC) $(CFLAGS) -c $(INCLUDES) -o mm_tree.o mm_tree.c &&
cd ../test
$(CC) $(CFLAGS) -c $(INCLUDES) -o $@ $<
mm_tree_test: mm_tree_test.o
$(CC) $(CFLAGS) -o mm_tree_test mm_tree_test.o ../mm/mm_tree.o
clean:
rm *.o
</Makefile>
<mm_tree_test.c>
#include <stdlib.h>
#include <mm_tree.h>
The above should be
#include "mm_tree.h"

mm_tree.h is yours, not a system header.
int main( int argc, char** argv ) {
return 0;
}
</mm_tree_test.c>
<mm_tree.h>
#ifndef INCLUDE_MM_TREE_H
#define INCLUDE_MM_TREE_H

#ifndef NULL
#define NULL ((void *)0)
#endif
Don't define NULL yourself, just include one of the headers that
provides it when you need it. Otherwise, if someone includes your header
then a standard header things might break.
struct avlnode
{
int val;
struct avlnode *left;
struct avlnode *right;
int height;
};
struct avltree
{
struct avlnode *root;
};
int avltree_height( struct avltree *t );

#endif
</mm_tree.h>
<mm_tree.c>
#include "mm_tree.h"
#include <stdlib.h>

Then you will have a definition of NULL. Alternatively see below...
static int height( struct avlnode *node );

int mmTree_height( struct avltree *t ) {
return height( t->root );
}
static int height( struct avlnode *node ) {
if( node == NULL ) {
If you don't want to include a system header (although you will probably
need it for other stuff later) use either
if( node == 0 ) {
or
if( !node ) {
return -1;
}
return node->height;
}
</mm_tree.c>

--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
Nov 15 '05 #8
zolli wrote:
Richard Bos wrote:
zolli <zo***@nospamplease.net> wrote:

[ Please don't mail _and_ post follow-ups. ]


Sorry about that; hit Reply-all instead of Reply.


Then simply cancel the message with CTRL-W and try again.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
Nov 15 '05 #9
Flash Gordon wrote:
zolli wrote:
Richard Bos wrote:

<snip>
test code here so you can take a look. If I'm doing something
fundamentally wrong, I'd like to know. In the Makefile, if I replace
this line:
INCLUDES := -I../mm
with this line:
INCLUDES := -I../mm -I/usr/include -I/usr/include/linux

The aforementioned errors are seen.

So don't do that. Nothing in your code requires it and nothing should
*ever* require adding /usr/include explicitly to the path. Ask in a
Linux group for details about search paths.


Thanks for the advice.
The directory structure looks like this:
/test/Makefile
/test/mm_tree_test.c
/mm/mm_tree.h
/mm/mm_tree.c

Thanks,
zolli
<Makefile>
all: mm_tree_test

CC := gcc
CFLAGS = -g3 -DUSE_LIBC -Wall

I would suggest
CFLAGS = -g3 -O -DUSE_LIBC -Wall -ansi -pedantic
Possibly even loose the -DUSE_LIBC since I can't see why you are doing it.


The -DUSE_LIBC is there for the sake of the project. In the actual
(non-test) source, I compile modules, such as the binary search tree,
using glibc in order to test them. Later, the code is used in a
standalone OS which doesn't currently have a libc.

I've used pedantic, but never tried -ansi; I'll add it to my base
Makefile now.
INCLUDES := -I../mm -I../include

Just have
INCLUDES := -I../mm
mm_tree_test.o: mm_tree_test.c ../mm/mm_tree.h ../mm/mm_tree.c
cd ../mm && $(CC) $(CFLAGS) -c $(INCLUDES) -o mm_tree.o mm_tree.c
&& cd ../test
$(CC) $(CFLAGS) -c $(INCLUDES) -o $@ $<
mm_tree_test: mm_tree_test.o
$(CC) $(CFLAGS) -o mm_tree_test mm_tree_test.o ../mm/mm_tree.o
clean:
rm *.o
</Makefile>
<mm_tree_test.c>
#include <stdlib.h>
#include <mm_tree.h>

The above should be
#include "mm_tree.h"

mm_tree.h is yours, not a system header.


I read the K&R book a little bit today, trying to figure out when to use
"include.h" vs. <include.h>. The book was a bit nebulous, but I see
that the C FAQ has more solid advice that mirrors yours.

Again, thank you for the helpful suggestions.

zolli
#ifndef NULL
#define NULL ((void *)0)
#endif


Don't define NULL yourself, just include one of the headers that
provides it when you need it. Otherwise, if someone includes your header
then a standard header things might break.
struct avlnode
{
int val;
struct avlnode *left;
struct avlnode *right;
int height;
};
struct avltree
{
struct avlnode *root;
};
int avltree_height( struct avltree *t );

#endif
</mm_tree.h>
<mm_tree.c>
#include "mm_tree.h"

#include <stdlib.h>

Then you will have a definition of NULL. Alternatively see below...
static int height( struct avlnode *node );

int mmTree_height( struct avltree *t ) {
return height( t->root );
}
static int height( struct avlnode *node ) {
if( node == NULL ) {

If you don't want to include a system header (although you will probably
need it for other stuff later) use either
if( node == 0 ) {
or
if( !node ) {
return -1;
}
return node->height;
}
</mm_tree.c>


Nov 15 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Francesco Gallarotti | last post by:
Can any of you help with this? Pretty much all the errors I have belong to 2 different categories: 1) error C2872: ambiguous symbols 2) error C2662: cannot convert 'this' pointer from 'const class...
10
by: Toke H?iland-J?rgensen | last post by:
Hello. I am quite new to the c++ language, and am still trying to learn it. I recently discovered how using include files would allow me to split up my code into smaller segments, instead of having...
17
by: lallous | last post by:
Hello Sometimes, I don't know when exactly, when I try to include an external js file as: <script src='myfile.js'></script> that .js file goes not included in some cases!! To solve it, I...
2
by: Tommy Vercetti | last post by:
I'm new to Managed C++ development, and I can't seem to get started. Every time I try to include vcclr.h I get bizarre compilation errors. I've isolated this to a really simple case: In Visual...
14
by: Jon Rea | last post by:
I am currently cleaning up an application which was origainlly hashed together with speed of coding in mind and therefore contains quite a few "hacky" shortcuts. As part of this "revamping"...
5
by: Tio | last post by:
I have project in MFC(vc++) . There are files and classes: classes:dialog1,dialog2,aaa,bbb ---------------------- main.cpp --------------------- #include "mainfrm.h" #include "dialog1.h"...
6
by: Jordi | last post by:
I'm having a problem which I think has to do with the circular use of inlcuding header files. The short version of my code would look a bit like this, I think: GameEngine.h: #ifndef GAME_ENGINE...
11
by: cybervigilante | last post by:
I can't seem to change the include path on my local winmachine no matter what I do. It comes up as includ_path .;C:\php5\pear in phpinfo() but there is no such file. I installed the WAMP package...
12
by: Geoff Cox | last post by:
Hello I'm having a problem loading a frameset file using an include in a php file. Nothing is displayed and when I look at the source code I see that <html> <head> <title></title>
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.