0

I want to use ChatScript externally in my program. In the documents it says:

Embedding Step #1 First, you will need to modify `common.h and compile the system. You need to add all the CS .cpp files to your build list.

Find the // #define NOMAIN 1 and uncomment it. This will allow you to compile your program as the main program and ChatScript merely as a collection of routines to accompany it.

But I am newbie in Linux and can’t understand how to add .cpp files to my build list? What is my build list? May someone explains what do should I do exactly?

I did copy all the .cpp and .h and other folders existed inside ChatScript/SRC directory beside my main.cpp in my project.

Then I tried to run this code:

#include<iostream>
using namespace std;

char* output2;
    unsigned int InitSystem(int argc,char* argv[],char* unchangedPath,char* readonlyPath,char* writablePath);
    void InitStandalone();
    void PerformChat(char* user,char* usee,char* incoming,char* ip,char* output);

    int main()
    {

    PerformChat(NULL,NULL,"hi",NULL,output2);

    cout<<output2;

        return 0;
    }

But I get this error message:

undefined reference to `PerformChat(char*, char*, char*, char*, char*)

Then I did include all the header files to my program and delete this line of code: void PerformChat(char* user,char* usee,char* incoming,char* ip,char* output);

#include<iostream>

#include "common.h"
#include "common1.h"
#include "constructCode.h"
#include "cs_ev.h"
#include "csocket.h"
#include "dictionaryMore.h"
#include "dictionarySystem.h"
#include "english.h"
#include "evserver.h"
#include "factSystem.h"
#include "functionExecute.h"
#include "infer.h"
#include "jsmn.h"
#include "json.h"
#include "mainSystem.h"
#include "markSystem.h"
#include "mongodb.h"
#include "mprintf.h"
#include "multi.h"
#include "my_sql.h"
#include "os.h"
#include "outputSystem.h"
#include "patternSystem.h"
#include "postgres.h"
#include "privatesrc.h"
#include "scriptCompile.h"
#include "spellcheck.h"
#include "systemVariables.h"
#include "tagger.h"
#include "testing.h"
#include "textUtilities.h"
#include "tokenSystem.h"
#include "topicSystem.h"
#include "userCache.h"
#include "userSystem.h"
#include "variableSystem.h"

using namespace std;

char* output2;
    unsigned int InitSystem(int argc,char* argv[],char* unchangedPath,char* readonlyPath,char* writablePath);
    void InitStandalone();
    void PerformChat(char* user,char* usee,char* incoming,char* ip,char* output);

    int main()
    {

    PerformChat(NULL,NULL,"hi",NULL,output2);

    cout<<output2;

        return 0;
    }

But the new error says:

error: conflicting declaration of C function ‘int main()'
Matt Fletcher
  • 8,182
  • 8
  • 41
  • 60
Hasani
  • 3,543
  • 14
  • 65
  • 125
  • Uh oh. This source bundle comes with a Makefile that only supports building executables, not a library, and I don't see any header file appropriate for using it as a library. This isn't going to be simple, I'm afraid. – aschepler Oct 14 '17 at 22:07
  • @aschepler: but it says `Find the // #define NOMAIN 1 and uncomment it. This will allow you to compile your program as the main program and ChatScript merely as a collection of routines to accompany it.` – Hasani Oct 15 '17 at 06:54

1 Answers1

1

You would have to include all the chatscript SRC files in your project to get the function PerformChat to compile. But shortly ChatScript will release with library compilations as well.

  • you mean I must do #include all the .h files above my main function(below #include ) ? – Hasani Oct 16 '17 at 07:17
  • May you explain more your short part? `ChatScript will release with library compilations as well.` – Hasani Oct 16 '17 at 07:17
  • I added all the header files but got new error: `error: conflicting declaration of C function ‘int main()` – Hasani Oct 16 '17 at 08:38
  • I think as tutorial says I must compile the ChatScript before using it externally, but I can't do it :( – Hasani Oct 16 '17 at 08:40
  • ChatScript releeases in the future will come with a DLL ready for use. – user3634756 Oct 17 '17 at 18:21
  • About files, currently the way to include chatscript in your project is to have your project and add all of chatscripts files to it as well (with #define NOMAIN 1) so that all are compiled together. – user3634756 Oct 17 '17 at 18:22