Im sure i included pcap.h, and set something in linker and compiler. When i will be back home in 1-2 hours i will post it with some screens
Im sure i included pcap.h, and set something in linker and compiler. When i will be back home in 1-2 hours i will post it with some screens
Post the Full Compiler Build Log; after you turn on logging.
From FAQ-Compiling (errors) - CodeBlocks
Tim S.Q: How do I troubleshoot a compiler problem?
A: I would start by turning on full Compiler logging.
This is done by selecting the "Full command line" option Under menu "Settings" -> "Compiler and Debugger" -> Global compiler settings -> [the compiler you use] -> "Other Setting" tab, "Compiler logging".
This option will make Code::Blocks output the exact commands it uses to compile your code.
Things to remember:
You should review all the commands and their options;
If you have compiled your app before, do a re-build (or clean before build) to see all compiling / linking steps;
If you don't know what an option or a command does please read the documentation for the compiler/linker you're using;
Look for missing commands;
For every source file (.cpp; .c; .d; etc) in your project, you must have at least one command in the log. This command must produce an object file (file extension .o if using gcc/g++ and .obj if using Visual Studio);
Every object file should be linked in the final executable, if not there are undefined symbols errors;
Remember the file extension matters: *.c is compiled as C file, *.cpp is compiled as C++ file.
"...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson
I have everything set good, i think i have chosen wrong packet library... every tutorial for winpcap is in C, not in c++ do you know any other one? I need only to write a simple sniffer
It may be problem that im using codeblocks instead of visual studio whatever it is?
Last edited by QQemka; 07-03-2012 at 01:39 PM.
"...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson
This is the tutorial i am using Programming with pcap
The source code i am trying to compile is one of first
Build log:Code:#include <stdio.h> #include <pcap.h> int main(int argc, char *argv[]) { char *dev, errbuf[PCAP_ERRBUF_SIZE]; dev = pcap_lookupdev(errbuf); if (dev == NULL) { fprintf(stderr, "Couldn't find default device: %s\n", errbuf); return(2); } printf("Device: %s\n", dev); return(0); }
-------------- Build: Debug in qqqqqqq ---------------
mingw32-g++.exe -L"C:\Documents and Settings\QQemka\Pulpit\WpdPack\Lib" -o bin\Debug\qqqqqqq.exe obj\Debug\main.o
obj\Debug\main.o: In function `main':
C:/Documents and Settings/QQemka/Pulpit/qqqqqqq/main.cpp:8: undefined reference to `pcap_lookupdev
'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 0 seconds)
1 errors, 0 warnings
Build messages:
obj\Debug\main.o||In function `main':|
C:\Documents and Settings\QQemka\Pulpit\qqqqqqq\main.cpp|8|undefine d reference to `pcap_lookupdev|
||=== Build finished: 1 errors, 0 warnings ===|
In settings>search directories>compiler path is "C:\Documents and Settings\QQemka\Pulpit\WpdPack\Include"
settings>search directories>Linker "C:\Documents and Settings\QQemka\Pulpit\WpdPack\Lib"
I have just found out that i got some example files. I cannot compile them, mass errors. But they are all C not cpp, so maybe the library wont work with cpp??
Last edited by QQemka; 07-03-2012 at 04:10 PM.
To link to a library you actually need to link to a library!
This means you need a library name in the command; NOT just a path to a library.
Normally the command will have -lname where "name" is replaced with the library name.
In using Code::Blocks with GCC if the library file-name is libname.a you would enter only name without the leading lib or the trailing .a in the list of library names.
I am guessing the correct library file-name is "libwpcap.a" so try wpcap in the library list.
Under "Project" -> "Build Options"
Tab: Linker Settings
Box: Link Libraries
My full build log follows
The options "-Wno-unused-but-set-variable -Wno-deprecated-declarations -Wno-unused-variable -Wno-sign-compare -Wno-unused-parameter -Wno-attributes -Winvalid-pch" are me testing some other items and can be ignored.Code:mingw32-gcc.exe -Wall -g -Wno-unused-but-set-variable -Wno-deprecated-declarations -Wno-unused-variable -Wno-sign-compare -Wno-unused-parameter -Wno-attributes -Winvalid-pch -IC:\Users\stahta01\Downloads\WpdPack_4_1_2\WpdPack\Include -IH:\SourceCode\Projects\TestProjects\testpcap -c H:\SourceCode\Projects\TestProjects\testpcap\main.c -o obj\Debug\main.o mingw32-g++.exe -LC:\Users\stahta01\Downloads\WpdPack_4_1_2\WpdPack\Lib -o bin\Debug\testpcap.exe obj\Debug\main.o -lwpcap
Tim S.
Last edited by stahta01; 07-03-2012 at 04:24 PM.
"...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson
"...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson