User forums > Using Code::Blocks
error: `sockaddr_in' undeclared (first use in this function)
eb:
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?
stahta01:
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.
eb:
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
eb:
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.
eb:
Sorry folks, looks like it's not a CodeBlocks issue after all.
Just tried and experiment. Turns out this:
--- Code: ---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;
--- End code ---
gives you this:
--- Quote ---C:/cygwin/home/eb/rap00/main.c:60: error: `sockaddr_in' undeclared (first use in this function)
--- End quote ---
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...
Navigation
[0] Message Index
[#] Next page
Go to full version