Thread: Problem with library

  1. #16
    Registered User
    Join Date
    Jul 2012
    Posts
    11
    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

  2. #17
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Quote Originally Posted by QQemka View Post
    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

    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.
    Tim S.
    "...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

  3. #18
    Registered User
    Join Date
    Jul 2012
    Posts
    11
    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.

  4. #19
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Quote Originally Posted by QQemka View Post
    I have everything set good, ...
    If you want a second opinion; once more, I suggest posting the full build log.

    Tim S.
    "...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

  5. #20
    Registered User
    Join Date
    Jul 2012
    Posts
    11
    This is the tutorial i am using Programming with pcap

    The source code i am trying to compile is one of first


    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 log:
    -------------- 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.

  6. #21
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    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
    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
    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.

    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

  7. #22
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Libraries in Windows tend to end with .lib, not .a.
    Regardless, the documentation for pcap should say what file you must link against. That's the filename you input to the compiler.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #23
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Quote Originally Posted by Elysia View Post
    Libraries in Windows tend to end with .lib, not .a.
    Regardless, the documentation for pcap should say what file you must link against. That's the filename you input to the compiler.
    Microsoft Visual Studio Libraries and Borland Libraries tend to end with .lib file extension.
    MinGW GCC Libraries tend to end with .a file extension.

    Tim S.
    "...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

  9. #24
    Registered User
    Join Date
    Jul 2012
    Posts
    11
    Quote Originally Posted by stahta01 View Post
    Under "Project" -> "Build Options"
    Tab: Linker Settings
    Box: Link Libraries
    Thanx Tim, successfully compiled.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Library Problem
    By evetevet in forum C Programming
    Replies: 4
    Last Post: 01-18-2009, 11:07 AM
  2. library problem again!!!
    By kris.c in forum C Programming
    Replies: 8
    Last Post: 07-13-2006, 06:23 AM
  3. problem with the library
    By kris.c in forum C Programming
    Replies: 21
    Last Post: 07-10-2006, 08:29 PM
  4. BZ2 library problem
    By cfrost in forum C Programming
    Replies: 0
    Last Post: 12-20-2004, 11:53 PM
  5. Library Problem - [I Think]
    By White Chocobo in forum C Programming
    Replies: 1
    Last Post: 04-25-2002, 08:50 PM