From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id BA76B4A63 for ; Tue, 2 Aug 2016 22:42:00 +0200 (CEST) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga103.fm.intel.com with ESMTP; 02 Aug 2016 13:42:00 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.28,462,1464678000"; d="scan'208";a="858502416" Received: from dwdohert-dpdk.ir.intel.com ([163.33.210.152]) by orsmga003.jf.intel.com with ESMTP; 02 Aug 2016 13:42:00 -0700 From: Declan Doherty To: dev@dpdk.org Cc: Anatoly Burakov , Declan Doherty Date: Tue, 2 Aug 2016 21:37:47 +0100 Message-Id: <1470170269-20721-3-git-send-email-declan.doherty@intel.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1470170269-20721-1-git-send-email-declan.doherty@intel.com> References: <1470170269-20721-1-git-send-email-declan.doherty@intel.com> Subject: [dpdk-dev] [RFC 2/4] examples: add c++ example application X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 02 Aug 2016 20:42:02 -0000 From: Anatoly Burakov Example application for C++ compilation Signed-off-by: Declan Doherty --- examples/Makefile | 1 + examples/helloworld-cpp/Makefile | 51 +++++++++++++++++++++ examples/helloworld-cpp/c_code.c | 5 ++ examples/helloworld-cpp/c_header.h | 6 +++ examples/helloworld-cpp/cpp_code.cpp | 89 ++++++++++++++++++++++++++++++++++++ 5 files changed, 152 insertions(+) create mode 100644 examples/helloworld-cpp/Makefile create mode 100644 examples/helloworld-cpp/c_code.c create mode 100644 examples/helloworld-cpp/c_header.h create mode 100644 examples/helloworld-cpp/cpp_code.cpp diff --git a/examples/Makefile b/examples/Makefile index 18b41b9..cb81c6c 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -46,6 +46,7 @@ endif DIRS-y += ethtool DIRS-y += exception_path DIRS-y += helloworld +DIRS-y += helloworld-cpp DIRS-$(CONFIG_RTE_LIBRTE_PIPELINE) += ip_pipeline ifeq ($(CONFIG_RTE_LIBRTE_LPM),y) DIRS-$(CONFIG_RTE_IP_FRAG) += ip_reassembly diff --git a/examples/helloworld-cpp/Makefile b/examples/helloworld-cpp/Makefile new file mode 100644 index 0000000..f8f281c --- /dev/null +++ b/examples/helloworld-cpp/Makefile @@ -0,0 +1,51 @@ +# BSD LICENSE +# +# Copyright(c) 2010-2014 Intel Corporation. All rights reserved. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Intel Corporation nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +ifeq ($(RTE_SDK),) +$(error "Please define RTE_SDK environment variable") +endif + +# Default target, can be overriden by command line or environment +RTE_TARGET ?= x86_64-native-linuxapp-gcc + +include $(RTE_SDK)/mk/rte.vars.mk + +# binary name +APP = helloworld-cpp + +# all source are stored in SRCS-y +SRCS-y := c_code.c cpp_code.cpp + +CFLAGS += -O3 +CFLAGS += $(WERROR_FLAGS) +LDFLAGS += -lstdc++ + +include $(RTE_SDK)/mk/rte.extapp.mk diff --git a/examples/helloworld-cpp/c_code.c b/examples/helloworld-cpp/c_code.c new file mode 100644 index 0000000..d349a3b --- /dev/null +++ b/examples/helloworld-cpp/c_code.c @@ -0,0 +1,5 @@ +#include "c_header.h" + +int func(void) { + return 100500; +} diff --git a/examples/helloworld-cpp/c_header.h b/examples/helloworld-cpp/c_header.h new file mode 100644 index 0000000..3668b60 --- /dev/null +++ b/examples/helloworld-cpp/c_header.h @@ -0,0 +1,6 @@ +#ifndef HEADER_H +#define HEADER_H + +int func(void); + +#endif diff --git a/examples/helloworld-cpp/cpp_code.cpp b/examples/helloworld-cpp/cpp_code.cpp new file mode 100644 index 0000000..6919048 --- /dev/null +++ b/examples/helloworld-cpp/cpp_code.cpp @@ -0,0 +1,89 @@ +/*- + * BSD LICENSE + * + * Copyright(c) 2010-2014 Intel Corporation. All rights reserved. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +extern "C" { +#include "c_header.h" +}; + +using namespace std; + +static int +lcore_hello(__attribute__((unused)) void *arg) +{ + unsigned lcore_id; + lcore_id = rte_lcore_id(); + printf("hello from core %u\n", lcore_id); + return 0; +} + +int +main(int argc, char **argv) +{ + int ret; + unsigned lcore_id; + + cout << "Hellow world from C++" << endl; + + cout << "Output from C code: " << func() << endl; + + ret = rte_eal_init(argc, argv); + if (ret < 0) + rte_panic("Cannot init EAL\n"); + + /* call lcore_hello() on every slave lcore */ + RTE_LCORE_FOREACH_SLAVE(lcore_id) { + rte_eal_remote_launch(lcore_hello, NULL, lcore_id); + } + + /* call it on master lcore too */ + lcore_hello(NULL); + + rte_eal_mp_wait_lcore(); + return 0; +} -- 2.5.5