1

I have C++ code spread across multiple C++ and header files and wanted to know how to link them in ECL. Should I install them as libraries (.cpp and header files) into the local cluster I am running in order to import them into the main C++ embed code and use it OR is there any other way of linking embedded C++ code across ECL files?

To be more clear, suppose there's a helper.cpp with helper functions and helper.h with appropriate headers and we want to use them in our embedded C++ code. So how do we import these helper functions and their declarations into the main C++ embed program that we write? Is there a way to install them into the cluster we are using?

helpers.h

int sum(int , int);

helpers.cpp

#include "helpers.h"

int sum(int a, int b) {
    return a+b;
}

main.cpp

#include "helpers.h"
#include<iostream>
using namespace std;

int main() {
    cout<<sum(10,5);
    return 0;
}

We are able to compile both helpers.cpp and main.cpp as g++ helpers.cpp main.cpp -o main and run the executable using ./main to get 15 as output. How do we move these 3 files to embedded C++ and include many more such files in the background?

O'Neil
  • 3,790
  • 4
  • 16
  • 30

1 Answers1

2

I have discussed this with some developers of the platform and although you might be able to #include headers and cpp's above the #body of an embedded c++ function definition and call it's members from it (e.g. : https://github.com/hpcc-systems/HPCC-Platform/blob/0a7e3c4affbe570af28ac46dc6b26c5d0fb1f5cf/ecl/regress/cppbody.ecl#L91), probably the easiest way is to compile the source into a library, and preferably turning into a plugin (see more details on the "External Service Implementation" section of the ECL language reference manual).

Also, there are various options for making it easier to compile c++ associated with embedded code. The following is supported within embedded c++ as long as the files are deployed to the eclccserver machine:

//Compile a c++ file with the workunit
#option source myfile.cpp


// Link a library into a workunit
#option library libmylibrary.so
hwatanuki
  • 66
  • 4