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.
Tags
Referenced Files
Unknown Object (File)
Tue, Apr 16, 7:50 PM
Unknown Object (File)
Mar 22 2024, 9:58 PM
Unknown Object (File)
Mar 22 2024, 9:58 PM
Unknown Object (File)
Mar 22 2024, 9:12 PM
Unknown Object (File)
Mar 22 2024, 9:12 PM
Unknown Object (File)
Mar 9 2024, 7:34 AM
Unknown Object (File)
Feb 9 2024, 9:55 AM
Unknown Object (File)
Jan 29 2024, 3:15 AM
Subscribers

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
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

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

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