Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 22 Dec 1999 21:46:47 +0000
From:      Mark Ovens <mark@ukug.uk.freebsd.org>
To:        "Ronald 'Ko' Klop" <ronald@node11a94.a2000.nl>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: Q: using kvm gives a compile error
Message-ID:  <19991222214646.G322@marder-1>
In-Reply-To: <Pine.BSF.4.05.9912222136540.1813-100000@dlanor.evertsen.nl>
References:  <Pine.BSF.4.05.9912222136540.1813-100000@dlanor.evertsen.nl>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, Dec 22, 1999 at 09:41:56PM +0100, Ronald 'Ko' Klop wrote:
> Hello,
> 
> I'm trying to write a program using kvm.
> But even the simplest program failes to compile.
> 
> Here is my program iftest.cc:
> #include <fcntl.h>
> #include <kvm.h>
> #include <stdlib.h>
> #include <stdio.h>
> 
> int main(int argc,char **argv) {
>         char *nlistf=NULL,*memf=NULL;
>         kvm_t *kvmd;
> 
>         kvmd = kvm_open(nlistf,memf,NULL,O_RDONLY,"kvm: ");
>         if (kvmd==NULL) {
>                 printf("error opening kvm\n");
>                 exit(0);
>         }
>         kvm_close(kvmd);
>         return 0;
> }
> 
> 
> Compiling gives the following output:
> g++ iftest.cc 
> /var/tmp/ccOV18281.o: In function `main':
> /var/tmp/ccOV18281.o(.text+0x26): undefined reference to `kvm_open'
> /var/tmp/ccOV18281.o(.text+0x55): undefined reference to `kvm_close'
> 
> I have read the man pages searched the mail archive, but didn't find
> anything. I also looked at the implementation of top and netstat.
> But couldn't find a clue about what I am forgetting.
> 
> Does somebody know how to do this?
> 

You need to link in the kvm library:

marder-1# g++ iftest.cc
/tmp/ccKh11401.o: In function `main':
/tmp/ccKh11401.o(.text+0x26): undefined reference to `kvm_open'
/tmp/ccKh11401.o(.text+0x55): undefined reference to `kvm_close'
marder-1# g++ iftest.cc -lkvm
marder-1# ./a.out
marder-1# 


> Greetings,
> 
> Ronald.
> 
> PS: I'm trying to do this to get the number of send/received bytes across
> the ethernet from the kernel.
> 
> -- 
> Ronald Klop
> http://node11a94.a2000.nl/~ronald/
> 
> 
> 
> To Unsubscribe: send mail to majordomo@FreeBSD.org
> with "unsubscribe freebsd-questions" in the body of the message

-- 
	"there's a long-standing bug relating to the x86 architecture
	that allows you to install Windows too"
				   -Matthew D. Fuller
________________________________________________________________
      FreeBSD - The Power To Serve http://www.freebsd.org
      My Webpage http://ukug.uk.freebsd.org/~mark/
mailto:mark@ukug.uk.freebsd.org              http://www.radan.com



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?19991222214646.G322>