I have a program (main.c) that includes the header rpc/rpc.h which includes the header netinet/in.h which contains the header cygwin/in.h which contains the struct "sockaddr_in".
So why is it that when I compile main.c I get the error: `sockaddr_in' undeclared (first use in this function) yet when I right click and "Open Include file:" on each of the headers involved it successful opens each successive header properly?
http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28errors%29#Q:_How_do_I_troubleshoot_a_compiler_problem.3F (http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28errors%29#Q:_How_do_I_troubleshoot_a_compiler_problem.3F)
Under menu "Settings" -> "Compiler and Debugger" -> Global compiler settings -> [the compiler you use] -> "Other Setting" tab
Also check this check-mark "Explicitly currently compiling file's directly to compiler search dirs"
Note: I do not think this will help it is the only item I can think that might help.
Tim S.
I tried "Explicitly add currently compiling file's directly to compiler search dirs" and "Explicitly add project's top level directory to compiler search dirs" separately and together each time followed by a "Rebuild workspace". It still can't find it.
Buil log:
-------------- Clean: Release in rap00 ---------------
Cleaned "rap00 - Release"
-------------- Build: Release in rap00 ---------------
gcc-3.exe -Wall -O2 -IC:/cygwin/usr/include/tirpc -IC:/cygwin/usr/include -c C:/cygwin/home/eb/rap00/main.c -o obj/Release/main.o
C:/cygwin/home/eb/rap00/main.c: In function `main':
C:/cygwin/home/eb/rap00/main.c:50: error: `sockaddr_in' undeclared (first use in this function)
C:/cygwin/home/eb/rap00/main.c:50: error: (Each undeclared identifier is reported only once
C:/cygwin/home/eb/rap00/main.c:50: error: for each function it appears in.)
C:/cygwin/home/eb/rap00/main.c:50: error: `addr' undeclared (first use in this function)
C:/cygwin/home/eb/rap00/main.c:53: warning: implicit declaration of function `inet_pton'
Process terminated with status 1 (0 minutes, 0 seconds)
4 errors, 1 warnings
Another piece of info:
When I edit netinet/in.h; when I change "cygwin/in.h" to "cygwin/in1.h" (cygwin/in1.h does not exist) and compile, I get a whole cascade of errors.
So cygwin/in.h IS being successfully accessed but `sockaddr_in' is not being found.
Sorry folks, looks like it's not a CodeBlocks issue after all.
Just tried and experiment. Turns out this:
struct sockaddr_in
{
sa_family_t sin_family; /* Address family */
in_port_t sin_port; /* Port number */
struct in_addr sin_addr; /* Internet address */
/* Pad to size of `struct sockaddr'. */
unsigned char __pad[__SOCK_SIZE__ - sizeof(short int)
- sizeof(unsigned short int) - sizeof(struct in_addr)];
};
sockaddr_in *addr = NULL;
gives you this:
QuoteC:/cygwin/home/eb/rap00/main.c:60: error: `sockaddr_in' undeclared (first use in this function)
PLUS other 'struct' declarations in this file work fine, that is they appear in the CodeBlocks Symbols list.
So there must be a problem with the way the struct is being called out.
Good ol' Cygwin...
Hold on...
Consider the code:
struct group_filter
{
uint32_t gf_interface;
struct sockaddr_storage gf_group;
uint32_t gf_fmode;
uint32_t gf_numsrc;
struct sockaddr_storage gf_slist[1];
};
#define GROUP_FILTER_SIZE(numsrc) (sizeof (struct group_filter) \
- sizeof (struct sockaddr_storage) \
+ (numsrc) * sizeof (struct sockaddr_storage))
/* Structure describing an Internet (IP) socket address. */
#define __SOCK_SIZE__ 16 /* sizeof(struct sockaddr) */
struct sockaddr_in
{
sa_family_t sin_family; /* Address family */
in_port_t sin_port; /* Port number */
struct in_addr sin_addr; /* Internet address */
/* Pad to size of `struct sockaddr'. */
unsigned char __pad[__SOCK_SIZE__ - sizeof(short int)
- sizeof(unsigned short int) - sizeof(struct in_addr)];
};
CodeBlocks sees group_filter as a symbol but not sockaddr_in. But if I insert a blank line above "struct sockaddr_in" CodeBlocks sees sockaddr_in and adds it to the 'All local symbols (workspace)' list.
I still get the compile error though. >:(
OH! And "Find declaration of:" finds it now.
Quote from: eb on February 04, 2012, 01:06:11 AM
Hold on...
Consider the code:
[...]
CodeBlocks sees group_filter as a symbol but not sockaddr_in.
Works fine here. However, as you did not mention
anything about your configuration (Platform, version) nobody can help you.
Platform Win XP 64
version Code Blocks 10.05