I am trying to include a JSON-Parsing library into my smart contract. There are only two .hpp/.cpp files to link which are in the same folder as the contract. JSON and JSONValue

In my contracts header file I use

#include "JSON.h" //in JSON.h the JSONValue.h is included

//@abi action
void test(const std::string &pToParse);
EOSIO_ABI(Test, (test));

In my contracts .cpp file I call this method:

void VectorTest::test(const std::string& pToParse){

When I compile it with the following commands no errors are generated:

eosiocpp -o contracts/test.wast contracts/test.cpp contracts/JSON.cpp contracts/JSONValue.cpp
eosiocpp -g contracts/test.abi contracts/test.cpp

But when I try to push it I get some Runtime error that there is no apply function.

900434ms thread-0   http_plugin.cpp:405           handle_exception     ] FC Exception encountered while processing chain.push_transaction
900434ms thread-0   http_plugin.cpp:406           handle_exception     ] Exception Details: 3070002 wasm_execution_error: Runtime Error Processing WASM
Smart contract's apply function not exported; non-existent; or wrong type
    thread-0  wasm_eosio_validation.cpp:91 validate

    thread-0  apply_context.cpp:62 exec_one

I cross checked the test.wast file and searched for apply but there is no apply function.

Am I doing something wrong or do I try to achieve something which is impossible?


Also this command does not work:

eosiocpp -o contracts/test.wast contracts/*.cpp

It always seems like it would just include the JSON-cpp files into the WAST.

  • include your other cpp file to your main cpp file like #include "xxx.cpp"
    – Jimmy Guo
    Commented Jul 6, 2018 at 2:23
  • Isn't this considered bad coding style in cpp?
    – tmm
    Commented Jul 6, 2018 at 6:11
  • Have defined the apply function yourself or have you used EOS_ABI that creates the apply function?
    – friedger
    Commented Jul 6, 2018 at 11:35
  • I have used EOS_ABI Macro. Including the cpp files into the contract worked btw - but I still want to know how to use eosiocpp with multiple files
    – tmm
    Commented Jul 6, 2018 at 11:37
  • @TeeAttack42 you can't, see the system contract, it also include the cpp file
    – Jimmy Guo
    Commented Jul 6, 2018 at 13:22

1 Answer 1


This is a workaround based on @KemmyGuo 's comment:

You can include the additional .cpp files (which have to be in the same folder) into your contracts .cpp file.

Disclaimer: this is not a good C++ coding style, but it works for the moment.

In my case inside the test.cpp this did the trick

#include "test.h"
#include "JSON.cpp"
#include "JSONValue.cpp"

void Test::test(const std::string& pToParse){

Then you can run as usual

eosiocpp -o contracts/test.wast contracts/test.cpp
eosiocpp -g contracts/test.abi contracts/test.cpp

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.