Page MenuHomeFreeBSD

libvmm: add __BEGIN_DECLS/__END_DECLS for linking with c++ binaries
ClosedPublic

Authored by gusev.vitaliy_gmail.com on Jul 5 2022, 3:14 PM.

Details

Summary

Sponsored by vStack.

Test Plan

$ cat vmopen.cpp

#include <dlfcn.h>
#include <err.h>
#include <vmmapi.h>

typedef void (*vm_close_fn)(struct vmctx *ctx);
int main(int argc, char *argv[])
{
	const char *vmname = argc > 1 ? argv[1] : "-";
	struct vmctx *ctx;
	vm_close_fn __vm_close = (vm_close_fn)dlsym(RTLD_NEXT, "vm_close");

	ctx = vm_open(vmname);

	if (ctx == NULL)
		err(1, "cannot open vm device: %s", vmname);

	if (__vm_close)
		__vm_close(ctx);
}

Compilation and linking

$ c++ vmopen.cpp -I /data/freebsd/HEAD/lib/libvmmapi/ -L /data/freebsd/HEAD/lib/libvmmapi/ -lvmmapi

Without patch command above produces:

ld: error: undefined symbol: vm_open(char const*)

With patch - success.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

markj added inline comments.
lib/libvmmapi/vmmapi.h
36

Conventionally, cdefs.h is included first (see style(9)). So:

#include <sys/cdefs.h>
#include <sys/param.h>
#include ...
This revision is now accepted and ready to land.Jul 5 2022, 3:50 PM

Corrected include order according to Mark's comment.

This revision now requires review to proceed.Jul 5 2022, 7:42 PM

@markj Could you approve again and commit?

This revision is now accepted and ready to land.Jul 5 2022, 8:29 PM