extern "C" the top level header file, and add a simple c++ compile test.
Signed-off-by: Keith Busch <kbusch@kernel.org>
*.so.*
test/test
+test/cpp
examples/display-tree
examples/display-columnar
fi
print_config "systemd" "${systemd}"
+##########################################
+# check for c++
+cpp="no"
+which g++ > /dev/null 2> /dev/null
+if [ $? -eq 0 ]; then
+ cpp="yes"
+fi
+print_config "cpp" "${cpp}"
+
+
if test "$libuuid" = "yes"; then
output_sym "CONFIG_LIBUUID"
echo "override LDFLAGS += -luuid" >> $config_host_mak
output_sym "CONFIG_SYSTEMD"
echo "override LDFLAGS += -lsystemd" >> $config_host_mak
fi
+if test "$cpp" = "yes"; then
+ output_mak "CONFIG_CPLUSPLUS" "y"
+fi
all: $(all_targets)
-test_srcs := telemetry-listen.c display-tree.c display-columnar.c discover-loop.c
-
-test_objs := $(patsubst %.c,%.ol,$(test_srcs))
-
%: %.c
$(QUIET_CC)$(CC) $(CFLAGS) -o $@ $< -lnvme
clean:
- @rm -f $(all_targets) $(test_objs)
+ rm -f $(all_targets)
#ifndef _LIBNVME_H
#define _LIBNVME_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
#include "nvme/types.h"
#include "nvme/ioctl.h"
#include "nvme/fabrics.h"
#include "nvme/tree.h"
#include "nvme/util.h"
+#ifdef __cplusplus
+}
+#endif
+
#endif /* _LIBNVME_H */
ifneq ($(MAKECMDGOALS),clean)
include ../config-host.mak
+else
+CONFIG_CPLUSPLUS=y
endif
-all_targets += test
+c_targets += test
+ifdef CONFIG_CPLUSPLUS
+cpp_targets += cpp
+else
+cpp_targets +=
+endif
+
+all_targets += $(c_targets) $(cpp_targets)
all: $(all_targets)
-%: %.c
- $(QUIET_CC)$(CC) $(CFLAGS) -o $@ $< -lnvme
+CXXFLAGS ?= -lstdc++
-test_srs := test.c
+%: %.cc
+ $(QUIET_CC)$(CC) $(CFLAGS) $(CXXFLAGS) -o $@ $< -lnvme
-test_objs := $(patsubst %.c,%.ol,$(test_srcs))
+%: %.c
+ $(QUIET_CC)$(CC) $(CFLAGS) -o $@ $< -lnvme
clean:
- @rm -f $(all_targets) $(test_objs)
+ rm -f $(all_targets)
--- /dev/null
+#include <iostream>
+#include <libnvme.h>
+
+int main()
+{
+ nvme_root_t r;
+ nvme_subsystem_t s;
+ nvme_ctrl_t c;
+ nvme_path_t p;
+ nvme_ns_t n;
+
+ r = nvme_scan();
+ if (!r)
+ return -1;
+
+ nvme_for_each_subsystem(r, s) {
+ std::cout << nvme_subsystem_get_name(s) << " - NQN=" << nvme_subsystem_get_nqn(s) << "\n";
+ nvme_subsystem_for_each_ctrl(s, c) {
+ std::cout << " `- " << nvme_ctrl_get_name(c) << " " <<
+ nvme_ctrl_get_transport(c) << " " <<
+ nvme_ctrl_get_address(c) << " " <<
+ nvme_ctrl_get_state(c) << "\n";
+ nvme_ctrl_for_each_ns(c, n)
+ std::cout << " `- " << nvme_ns_get_name(n) <<
+ "lba size:" << nvme_ns_get_lba_size(n) << " lba max:" <<
+ nvme_ns_get_lba_count(n) << "\n";
+ nvme_ctrl_for_each_path(c, p)
+ std::cout << " `- " << nvme_path_get_name(p) << " " <<
+ nvme_path_get_ana_state(p) << "\n";
+ }
+ nvme_subsystem_for_each_ns(s, n) {
+ std::cout << " `- " << nvme_ns_get_name(n) <<
+ "lba size:" << nvme_ns_get_lba_size(n) << " lba max:" <<
+ nvme_ns_get_lba_count(n) << "\n";
+ }
+ }
+ std::cout << "\n";
+
+ return 0;
+}