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)
Fri, Nov 22, 8:50 PM
Unknown Object (File)
Oct 5 2024, 10:47 PM
Unknown Object (File)
Oct 5 2024, 4:57 PM
Unknown Object (File)
Oct 5 2024, 12:29 PM
Unknown Object (File)
Oct 5 2024, 8:27 AM
Unknown Object (File)
Oct 4 2024, 10:05 PM
Unknown Object (File)
Oct 4 2024, 12:46 PM
Unknown Object (File)
Oct 4 2024, 12:01 PM
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 Skipped
Unit
Tests Skipped

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