Try to write this command instead, g++ main.cpp -o main -I/usr/local/include/js/ -L/usr/local/lib/ -lmozjs1.8.5
regarding the path I wrote above, you must write your own path which include the library and JSAPI.h file included in, And the last term is spidermonkey library, you will find it in lib folder, for me it exists in /usr/local/lib