I'm looking for a header file on windows that I can use to get the ntohl function in C, but Winsock2.h will not work for me. Does anybody know what other header files would provide this?
Here are some errors I get when I try to include Winsock2.h
C:\Program Files (x86)\PellesC\Include\Win\Winsock2.h(1045): error #2120: Redeclaration of 'getservbyport', previously declared at C:\Program Files (x86)\PellesC\Include\Win\winsock.h(468); expected 'PSERVENT __stdcall function(int, const char *)' but found 'struct servent * __stdcall function(int, const char *)'.
C:\Program Files (x86)\PellesC\Include\Win\Winsock2.h(135): error #2123: Redefinition of 'hostent', previously defined at C:\Program Files (x86)\PellesC\Include\Win\winsock.h(91).
C:\Program Files (x86)\PellesC\Include\Win\ws2def.h(39): error #1050: Redefinition of macro 'AF_IPX'.
C:\Program Files (x86)\PellesC\Include\Win\Winsock2.h(1310): error #2121: Redeclaration of 'LPSOCKADDR_IN'.
It's in winsock2.h as per the MSDN docs and, from a development system of mine (in C:\Program files (x86) Microsoft SDKs\Windows\v7.0A\Include\Winsock2.h):
WINSOCK_API_LINKAGE u_long WSAAPI ntohl (__in u_long netlong);
I'm not sure why that's "not working" for you. If you're getting an error message, you need to post it.
Based on your question edits on why you're having trouble with winsock2.h, it appears you're trying to include both winsock.h and winsock2.h - that's rarely a good idea :-) They're actually fundamentally incompatible, winsock2 is a later version with extra goodies.
Unfortunately, it's not always under your obvious control since windows.h automagically include winsock.h for you under most circumstances.
From memory, one way around this is to define WIN32_LEAN_AND_MEAN before including windows.h. This will prevent some of the lesser-used headers from being included.
Another is to define _WINSOCKAPI_ before including windows.h - this will prevent winsock.h from being included as well.
The third (and prbably preferable) way is simply to include winsock2.h before windows.h. winsock2.h defines _WINSOCKAPI_ so has the same effect as the previous paragraph.
I solved my own problem eventually. I had neglected to download the windows software development kit and add the include directories etc. in my project. I had assumed that my compiler came with all of the libraries and headers for sockets.
Related
I am developing a C application, and using Eclipse CDT IDE, which I find great. The project uses Glib,Gtk,and GStreamer , so whenever I use some of their features in a file, I need to include:
#include <glib.h>
#include <gtk/gtk.h>
#include <gst/gst.h>
The code compiles without any error, since the PATH variable to search those headers is set correctly in a CMakeLists.txt.
However, while working on the project, I found annoying errors highlighting in my code, regarding type definitions like gchar or GValue or GTKApplication; the error outlined is "symbol **** could not be resolved". These definitions are inside a header file that my Eclipse IDE cannot find (included by glib.h), if not at compile time (indeed the program compiles correctly). Instead, the type GError , defined in gst.h , is not highlighted as an error by the pre-compiler.
I would like then that my Eclipse IDE could search on nested headers (#include inside an #inlcude inside...) to find those type definition, in order so to not have those annoying errors highlighting. How can I do so? I would not like to have to include directly all files where the type definitions are done.
EDIT: As Jonah Graham outlined, the problem is not beacuse Eclispe does a "single-step research" on the headers, since it inspects includes inside other includes like any other IDE. It is a CMake bug with c and Eclipse
Thanks in advance.
The problem you are facing is a CMake bug*. CMake adds __cplusplus into the defined symbols unconditionally, which means that glib headers are not parsed properly when in C mode. You can see this clearly by opening gmacros.h around the definition for G_BEGIN_DECLS:
Because CMake told CDT __cplusplus is defined, it thinks G_BEGIN_DECLS is also defined, which makes code like this from gtypes.h parse incorrectly:
G_BEGIN_DECLS
/* Provide type definitions for commonly used types.
* These are useful because a "gint8" can be adjusted
* to be 1 byte (8 bits) on all platforms. Similarly and
* more importantly, "gint32" can be adjusted to be
* 4 bytes (32 bits) on all platforms.
*/
typedef char gchar;
...
Of course with no gchar defined, everything else is going to go badly.
Luckily there is a quick workaround until the problem is resolved in CMake, remove __cplusplus from the info in CDT.
Open Project Properties
C/C++ Include Paths and Symbols
Remove __cplusplus from the list and press OK
(sometimes necessary) Right-click on project -> Index -> Rebuild
* There may be some other workarounds if you know CMake better. The bug says also it will be fixed for the next release of CMake.
I am trying to use the following method to include a project header file:
#include FILE_PATH
Where FILE_PATH is defined as the file to be included.
The project compiles without errors if FILE_PATH is include as:
#define FILE_PATH "hal/micro/config.h"
#include FILE_PATH
But if FILE_PATH is pre-defined as a compiler define option inside the project options, then building the project returns the following error:
Error #13: Expected a file name
The development software being used is Code Composer Studio version 6.
What am I missing here to pre-define the header file path in a project?
Additional Details:
I am in the process of converting a working project from the IAR embedded workbench IDE to Code Composer Studio. The Pre-define NAME (--define, -D) shown in the picture below are mostly identical to how they were in the IAR project.
The pre-define name boxed in red is currently the cause of the error, but this could occur with any of the other defines with file pathnames.
I have tried the suggestion of using the #ifdef statement to at least verify that PLATFORM_HEADER is actually defined and it does seem to be defined. I also checked for typos and there doesn't appear to be any noticeable typos.
The key reason for wanting to go with the pre-defined macro approach is to avoid individually making changes to numerous files affected by this error.
I still have not yet tried a command line compile, since I need to reference the manual on how to do so, but I will try as soon as I figure it out.
#StenSoft wrote:
The IDE does not correctly escape the parameters. You should escape the quotes. You can also try placing PLATFORM_HEADER somewhere in the code and see what the compiler would tell you it sees.
I'm using cygwin to compile a network tool(iffinder).
After ./configure and make i have a problem that i guess is related to struct icmp. Where is the icmp struct in header files. I searched for it in cygwin header files, but i didn't find anything.
How can i compile source codes which need icmp, in cygwin?
If it helps, you can find the source code of iffinder here
Note: I have ip_icmp.h in my cygwin's header files.
Compile error:
iffinder.c:1059: warning: "struct icmp" declared inside parameter list
iffinder.c:1059: warning: its scope is only this definition or
declaration, which is probably not what you want iffinder.c: In
function `handle_icmp_error': iffinder.c:1069: error: dereferencing
pointer to incomplete type
...
In cygwin, the icmp.h is empty. I suggest you copy a icmp.h from a open source project, and compile it with your project. Maybe, you have many errors and you have to correct them, but you just need an icmp struct and it will solve your problem.
iffinder.c line 54 does #include <netinet/ip_icmp.h> - is this header file present on your system?
I am using Visual studio 2010 for building C project. My project contains a number of header files,source file and parsers. It uses lex and bason files. I am getting a single error during the compilation and íé the following
abc.y:error C2065: 'INPUT' : undeclared identifier
I tried the solutions I am getting like including
#define WIN32_WINNT >= 0x0501
in my main.c file before the inclusion of any of the header files.I am not able to get rid of this error. Could you please let me know what Can be the reasons for this error?
EDIT
The snippet of code that is showing error is:
list_Cons(0, list_List((POINTER)INPUT)
The surprising thing is that If i alter INPUT into INPUT1, I get the same error. It is stoic to change.
Presumably you read this and this.
#define WIN32_WINNT >= 0x0501 wont work. You should try using #define WIN32_WINNT 0x0501 instead.
Also, check that you are actually #including winuser.h
A C++ compiler cannot process a *.y file. For that you need a yacc / bison program, which does not come included with Visual Studio 2010.
For myself I use CMake which can generate MSVC projects along with other build types. You can tell it that a .y needs to be processed outwith the C/C++ files and it will instruct MSVC to invoke whatever external tools are necessary to preprocess the non-C/C++ parts.
This is my warning.
warning : implicit declaration of function 'sqlglm'
The warning comes in a bi.pc file.
when i check the bi.c file.
it doesn't include
#include <sqlcpr.h>
#include <sqlca.h>
As .c file generate at compile time.
there is no need to edit .c file
i am using linux & gcc compiler,C.
This is an old question, but to be helpful to people who might stumble on it via search engine like me, the right answer is:
you have to add the following lines to your Pro*C source
EXEC SQL INCLUDE sqlca.h;
EXEC SQL INCLUDE oraca.h;
EXEC SQL INCLUDE sqlcpr.h;
The sqlca.h and oraca.h are required before sqlcpr.h can be included. A standard C header like stddef.h or stdio.h have to be included before these embedded SQL statements as they need to have size_t defined.
It is important to use the embedded SQL include statements instead of the C #include.
The EXEC SQL INCLUDE will copy the content of the header file into the generated C file. Therefore, it is not necessary to add the other include file paths of the Oracle client into the C compiler command line.
warning : implicit declaration of function 'sqlglm' shows up when function has been defined in some other header file, but has not been #included, or the function has not been defined at all. So, include the file which defines it or define it yourself.
Update
Use #include "sqlcpr.h" (in case sqlcpr.h is not in compiler's search paths and is in the same directory as the source file)