Find the answer to your Linux question:
Results 1 to 4 of 4
I am trying to compile a simple c++ pcap program. I installed pcap using sources->./configure->make->make install Here is the code and the linking (not compiling) error: Code: filosottile.at.filosottile-desktop:~/Filo-CM$ cat monitor.cpp ...
  1. #1
    Just Joined!
    Join Date
    Jun 2009
    Posts
    2

    Angry g++ not finds the lib

    I am trying to compile a simple c++ pcap program.
    I installed pcap using sources->./configure->make->make install
    Here is the code and the linking (not compiling) error:
    Code:
    filosottile.at.filosottile-desktop:~/Filo-CM$ cat monitor.cpp
    #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);
    }
    
    filosottile.at.filosottile-desktop:~/Filo-CM$ ls /usr/local/lib
    libpcap.a  python2.6  site_ruby
    filosottile.at.filosottile-desktop:~/Filo-CM$ g++ -L/usr/local/lib monitor.cpp -llibpcap
    /usr/bin/ld: cannot find -llibpcap
    collect2: ld returned 1 exit status
    Can someone help me, please?
    Last edited by FiloSottile; 06-23-2009 at 02:58 PM. Reason: added please ;)

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    Because you installed it in /usr/local you need to add /usr/local/lib to your LD_LIBRARY_PATH environment variable. From your command line where you are running the executable:
    Code:
    export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/local/lib
    You can add that to your ~/.bash_profile so it will be set for all your applications the next time you login.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #3
    Just Joined!
    Join Date
    Jun 2009
    Posts
    2
    But why "-L/usr/local/lib" didn't work?

  4. #4
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
    Posts
    8,974
    Quote Originally Posted by FiloSottile View Post
    But why "-L/usr/local/lib" didn't work?
    Sorry. Didn't read your posting closely enough. Your problem is with linking. You are using -llibpcap. Change that to -lpcap - you don't use the leading 'lib' with Linux/Unix compilers.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...