Hi,
I want to compile my code in C++ (because this is what I know and I am doing an experiment), but the standard makefile '.include <bsd.kmod.mk>' works only with the C compiler. At this stage, I do not have any idea about the various bits of code that must be linked and that is why I cannot simply write my own makefile.
This is the test code that I am wanting to compile:
This is the Makefile - which currently does not work:
The file <bsd.kmod.mk> does not seem to contain anything that prevents compilation in C++, but it includes <bsd.sys.mk> which seems to be where the problems come from. The first thing I would like to do is to simply use g++ and to remove all the references to c etc.
Can you help me to write a working makefile so I can use KLD via a C++ coded module?
What libraries would I need to link?
I want to compile my code in C++ (because this is what I know and I am doing an experiment), but the standard makefile '.include <bsd.kmod.mk>' works only with the C compiler. At this stage, I do not have any idea about the various bits of code that must be linked and that is why I cannot simply write my own makefile.
This is the test code that I am wanting to compile:
Code:
// test module event handler
#include <iostream>
#include <sys/param.h>
#include <sys/module.h>
#include <sys/kernel.h>
#include <sys/systm.h>
static int hello_modevent(module_t mod__unused, int event, void *arg__unused)
{
int error = 0;
switch(event)
{
case MOD_LOAD:
std::cout << "Hello, world!" << std::endl;
break;
case MOD_UNLOAD:
std::cout << "Good-bye, cruel world" << std::endl;
break;
default:
error = EOPNOTSUPP;
break;
}
return(error);
}
static moduledata_t hello_mod=
{
"hello",
hello_modevent,
NULL
};
DECLARE_MODULE(hello, hello_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE);
This is the Makefile - which currently does not work:
Code:
KMOD= hello
SRCS= hello.cpp
.include <bsd.kmod.mk>
The file <bsd.kmod.mk> does not seem to contain anything that prevents compilation in C++, but it includes <bsd.sys.mk> which seems to be where the problems come from. The first thing I would like to do is to simply use g++ and to remove all the references to c etc.
Can you help me to write a working makefile so I can use KLD via a C++ coded module?
What libraries would I need to link?