c++google-nativeclientppapi

No type named 'VarDictionary' in namespace 'pp' using PNaCl


Can someone explain me why am I getting the compile error

error: no type named 'VarDictionary' in namespace 'pp'
        pp::VarDictionary dictionary;
        ~~~~^

I'm tying to set a dictionary in the function

virtual void HandleMessage(const pp::Var& message) {
}

I copied the example from the bottom of this Google page https://developer.chrome.com/native-client/devguide/coding/message-system

and tried something simple like this

virtual void HandleMessage(const pp::Var& message) {
    pp::VarDictionary dictionary;
    pp::VarArray an_array;
    an_array.Set(0, pp::Var("string0"));
    an_array.Set(1, pp::Var("string1"));
    dictionary.Set(pp::Var("param_array"), an_array);
    PostMessage(dictionary);    
}

but when I compile the code i get the error message for the pp::VarDictionary dictionary; however no problem with the pp::VarArray an_array;

I'm using this Makefile from Google

# Copyright (c) 2013 The Native Client Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

#
# GNU Make based build file.  For details on GNU Make see:
# http://www.gnu.org/software/make/manual/make.html
#

#
# Get pepper directory for toolchain and includes.
#
# If NACL_SDK_ROOT is not set, then assume it can be found three directories up.
#
THIS_MAKEFILE := $(abspath $(lastword $(MAKEFILE_LIST)))
NACL_SDK_ROOT ?= $(abspath $(dir $(THIS_MAKEFILE))../..)

# Project Build flags
WARNINGS := -Wno-long-long -Wall -Wswitch-enum -pedantic -Werror
CXXFLAGS := -pthread -std=gnu++98 $(WARNINGS)

#
# Compute tool paths
#
GETOS := python $(NACL_SDK_ROOT)/tools/getos.py
OSHELPERS = python $(NACL_SDK_ROOT)/tools/oshelpers.py
OSNAME := $(shell $(GETOS))
RM := $(OSHELPERS) rm

PNACL_TC_PATH := $(abspath $(NACL_SDK_ROOT)/toolchain/$(OSNAME)_pnacl)
PNACL_CXX := $(PNACL_TC_PATH)/bin/pnacl-clang++
PNACL_FINALIZE := $(PNACL_TC_PATH)/bin/pnacl-finalize
CXXFLAGS := -I$(NACL_SDK_ROOT)/include
LDFLAGS := -L$(NACL_SDK_ROOT)/lib/pnacl/Release -lppapi_cpp -lppapi -ljsoncpp

#
# Disable DOS PATH warning when using Cygwin based tools Windows
#
CYGWIN ?= nodosfilewarning
export CYGWIN


# Declare the ALL target first, to make the 'all' target the default build
all: job1.pexe

clean:
    $(RM) job1.pexe job1.bc

job1.bc: job1.cc
    $(PNACL_CXX) -o $@ $< -O2 $(CXXFLAGS) $(LDFLAGS)

job1.pexe: job1.bc
    $(PNACL_FINALIZE) -o $@ $<


#
# Makefile target to run the SDK's simple HTTP server and serve this example.
#
HTTPD_PY := python $(NACL_SDK_ROOT)/tools/httpd.py

.PHONY: serve
serve: all
    $(HTTPD_PY) -C $(CURDIR)

Solution

  • You need to add the header file for var_dictionary.h that is where the class you are trying to access is declared.

    Source code for that header is available here