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?
Related
I'm trying to compile libpcap with cross compilator arm-linux-gcc. When I run 'make' I get an error:
./pcap-linux.c:254:14: conflicting types for socklen_t /usr/arm-linux-gnueabi/include/unistd.h:275:21: note previous declaration of 'socklen_t'
I've also tried to compile it using common gcc but i have the same error. I work on ubuntu. How to resolve this problem
pcap-linux.c makes an alias in next way:
#ifndef HAVE_SOCKLEN_T
typedef int socklen_t;
#endif
You should pass -DHAVE_SOCKLEN_T to compiler or put
#define HAVE_SOCKLEN_T
to some header (usually it is done automatically by configure script or similar, that generates config.h).
Seems like you skipped build configuration step, so be ready to see another weird build errors.
I am programming stm8s and sht20 from sensirion company with I2C on the IAR. I'm using sht20 sample code: this link
I edited this sample code to my mcu. Then, for example I included i2c_hal.h to my main.c, but functions not working in my main.c file and IAR error is
ERROR LI005 no defition for I2c_Init()
Linking error
For example:
main.c
#include "stm8s.h"
#include "i2c_hal.h"
I2c_Init();
i2c_hal.h
#ifndef I2C_HAL_H
#define I2C_HAL_H
void I2c_Init ();
#endif
i2c_hal.c
#include "I2C_HAL.h"
void I2c_Init ()
{
SDA=LOW;
SCL=LOW;
SDA_CONF=LOW;
SCL_CONF=LOW;
SDA=HIGH;
SCL=HIGH;
}
I copied sht20 files to my project directory. What should I do for this error?
The header file is read by the preprocessor not the linker; if you get as far as linking, it is not a header file issue. The three basic build steps for C code are:
preprocess
compile
link
Your build is failing at the link state. The linker requires all compiled object files and any necessary libraries that constitute your application as input. In your case the most likely issue is that you have not compiled and linked i2c_hal.c (or strictly compiled i2c_hal.c and linked i2c_hal.obj). In the IAR IDE you simply explicitly add i2c_hal.c to your project along with main.c, and all should be good (all other dependencies being satisfied).
I suspect that i2c_hal.c will infact fail compilation since it is missing any declaration of SDA, SCL etc. - you probably need to include stm8s.h there also.
In general the process looks like this (this diagram actually omits pre-processing - i.e. expansion of headers, macros and conditional compilation etc. - but it was the otherwise clearest example I found; the original page does however mention the pre-processor stage, and the preprocessor is normally run automatically when you invoke the compiler in any case):
I have also the same issue with the spi. I got hal_spi_init() linking problem. To resolve the issue you need to enable the I2C in your stm32 hal drivers. In stm32xx_hal_conf.h file we have different #define modules. There you can enable the I2C module or just include the defined symbol in your IAR tool. Then Issue resolved
You need to add the C source files to the project. Header files shall not have any code or data, only the declarations of types , extern variables, macros, static inline functions and function prototypes.
Since yesterday i'm learning how to use pcap to parse a pcap file.
And since yesterday i'm getting an error :
Here is my simple code, trying to write the fd in pcap_t structure:
#include <pcap/pcap.h>
#include <sys/types.h>
#include <pcap-bpf.h>
#include <stdio.h>
int main() {
char errbuf[PCAP_ERRBUF_SIZE];
pcap_t *result;
if ((result = pcap_open_offline("test.pcap", errbuf)) == NULL) {
printf("%s\n", errbuf);
return -1;
}
printf("fd=%d\n", result->fd);
return 0;
}
and here is my error:
gcc -Wextra -Wall -Werror -I./includes -c -o main.o main.c
main.c: In function ‘main’:
main.c:14:27: error: dereferencing pointer to incomplete type
printf("fd=%d\n", result->fd);
^
make: *** [main.o] Error 1
I saw this post: Pcap Incomplete Type
Where the guy is having almost the same problem as I have, but still, I can't find a solution, I included what pcap_open_offline needs, I also included pcap-bpf.h because I saw that pcap_t is using bpf_program.
The first answer is saying "The error is because the compiler cannot see the definition of the structure" but in my case the structure is pcap_t and is typedef in pcap.h, which i included.
I just don't get how to include correclty with pcap.
Also, I'm on Ubuntu, and i cannot find all my .h file about pcap. When I look on google, I only find .h from apple and windows, so I assume that i'm using the same as the apple one, but i'm not sure about that !
I'm reading this documentation to see structures fields :
http://www.opensource.apple.com/source/libpcap/libpcap-18/libpcap/pcap.h
http://www.opensource.apple.com/source/libpcap/libpcap-9/libpcap/pcap-int.h
But again, the apple.com is scaring me, i'm not sure that I should rely on that. For instance, pcap-int.h doesn't seem to exist in my system.
Thank you !
For instance, pcap-int.h doesn't seem to exist in my system.
It's not supposed to. It's part of the pcap source code, but it's internal to libpcap, and the data structures it defines are subject to change from cap release to release, so you can't use them in a pcap program.
You rarely if ever need to the file descriptor associated with a pcap_t, but, in those rare cases where you do, you get it with the pcap_fileno() function:
printf("fd=%d\n", pcap_fileno(result));
However, when you open a capture file, using pcap_open_offline(), rather than opening a device for a live capture, there is no file descriptor associated with it, there's just a "standard I/O" FILE *. As the man page for pcap_fileno() says:
If p refers to a ``savefile'' that was opened using functions such as
pcap_open_offline() or pcap_fopen_offline(), a ``dead'' pcap_t opened
using pcap_open_dead(), or a pcap_t that was created with pcap_create()
but that has not yet been activated with pcap_activate(), it returns
-1.
so it should print "fd=-1" in your program.
The first answer is saying "The error is because the compiler cannot see the definition of the structure" but in my case the structure is pcap_t and is typedef in pcap.h, which i included.
It's typedefed as a structure in pcap.h, but that structure isn't fully defined in pcap.h. C allows a pointer to a structure that's not fully defined; this allows a library to provide a "handle" for a data structure that only the library itself can look at or modify. That's the case with the pcap_t structure; code outside libpcap should not look at it or modify it, it should make calls to libpcap routines to do that.
Also, I'm on Ubuntu, and i cannot find all my .h file about cap.
You probably need to install the "libpcap-dev" package. The "libpcap" package just installs enough libraries to allow programs already compiled with libpcap to run; the "libpcap-dev" package installs the header files to allow programs to be compiled with libpcap.
When I look on google, I only find .h from apple and windows
It doesn't find the GitHub repository for libpcap? That's surprising.
so I assume that i'm using the same as the apple one
Apple's libpcap is based on the one from the Tcpdump Group, which is the one on GitHub. The one in Ubuntu is also based on the one from the Tcpdump Group, as is WinPcap, which is the version for Windows.
I have typedeffed a C block type that I use commonly, in my project's PCH file:
typedef void (^UserBlock)(PFUser* user);
When I try to define an Objective C method in a header like this:
+(void)ensureUserWithID:(NSString *)userID withCompletion:(UserBlock)completionHandler
I am getting Expected a type error on UserBlock. However, if I move the typedef from PCH to beginning of that header file, it compiles (with the warning Redefinition of typedef 'UserBlock' is a C11 feature. I've cleaned the build folder, deleted derived data, restarted Xcode, but I'm still getting the same error. I've got other definitions in my PCH too, and they are compiling just file. All I'm having trouble is the C block types defined in my PCH. Why am I encountering such behavior? I am on Xcode 5.1.1 and LLVM 5.1.
Found the problem. The header file that I was getting errors on was imported to the PCH file, before the typedefs. I've moved the typedefs above the header import, and the problem was gone.
I'm writing some code that uses a C library provided by MATLAB (to extract data from *.mat files). In my IDE (Code::Blocks), I've included the folder containing the necessary "mat.h", which is on a network drive. My code recognises types defined in mat.h when I do this, but whenever I call functions from the file I get an "undefined reference" error. This is the same case for the example code MathWorks provides. What sort of problem usually causes this?
#include "mat.h"
int main (void) {
MATFile *pmat; // Compiles only when compiler is told to search in mat.h directory
pmat = matOpen("example_filename", "r"); // Never compiles
return 0;
}
Thanks!
Cameron
"undefined reference" is normally a linker error. It's not a problem of a header file. You need to tell the linker to link MATLAB's library (or a dedicated object) to your program.
No idea how this is done in Code::Blocks though. In the Code:Blocks documentation it is described here.
Have you checked the contents of mat.h? Does it declare matOpen()? Also, does the error occur when compiling or linking? If it's during the link phase, you probably need to reference the library that contains the implementation of matOpen() (a .lib in Windows, or .a in Unix). The .h file only declares the function.