Call C++ Hello World from Julia - c++

I have a C++ program that parses a binary file and outputs a std::string. I would like to call this function directly from Julia and convert the steam into a DataFrame. I need it to work in Linux and Windows. Currently, I have the program write the output to a text file, and then I read it into Julia. Cxx is no longer supported, and trying to get CxxWrap to work has been an exercise in frustration.
Toy Problem:
If someone could show me how to call the code below from Julia, that would be awesome.
// the example from https://github.com/JuliaInterop/CxxWrap.jl
#include <string>
std::string greet()
{
return "hello, world";
}

There's a new package which might fit your needs here:
https://github.com/eschnett/CxxInterface.jl
It is intended as a successor to Cxx.jl and more stable, so I'd recommend giving it ago although I haven't tried it myself!

Related

Hiding the "String" part of the code to avoid getting the code exposed

I have written a program in C++ code and it works as expected. I have compiled this at OS level (Linux SLES SPS 02) by using the standard gnu compiler.
Now the issue is, if I type something like strings ---name of the compiled file----, it will show me all the pieces of the code that are in string format.
Say, for example, if i have written a simple hello world program and compiled the output in Xyz.out file.
If I try to execute strings Xyz.out, it will show me the string "Hello World" from the code that I have written.
Is there a way to prevent this? Is there any way I can encrypt my written code?

Plot values in .m file from C++

I have looked extensively in the net, yet not found exactly what I want.
I have a big simulation program that outputs results in a MATLAB M-file (let's call it res.m) and I want to plot the results visually.
I want to start the simulation with C++ many times in a row and therefore want to automatize the plotting of the results.
I come up to two options:
Execute from C++ an Octave or MATLAB script that generates the graph.
-> Haven't found anyone who managed to do so
Use the Octave source files to read the res.m file and output them after with whatever plotting C++ tool.
-> Theoretically possible but I get lost in those files
Is someone able to solve this? Or has a better, easier approach?
The answer is to execute through the terminal.
I didn't manage to actually run a octave script from my c++ program directly, but there is a way around messing with/through the terminal and a extra Octave file. I used in my cpp:
string = "octave myProgr.m"
const char *command = str.c_str();
system(command);
myProgr.m is the script that plots the res.m file

How to embed R in a c++ cli program

I'd like to embed R into a c++ winforms app. It will output the graphs to a pictureBox, and output the numbers to a richTextBox. It takes commands from a textbox. I tried the header file RInside.h, but there is no such file.
Pseudo code:
#include <someDirToImbedR>
ExecuteButton_Click(args) {
RExecute(commandTextBox->Text);
outputGraphPictureBox->Load(output_graph);
richTextBox1->Text = OutputString;
}
I found this post on SO concerning (may be) the same problem.
Here is the Link to a repository by Dirk Eddelbuettel. It has even sample code in c++ to try for yourself.
Also this Link might be helpful.
Hope this can bring you on track. Unfortunately I personally used R only in C#.

how to distribute a lua file with c++

I know how to do stuff with Lua states and what not but what i don't understand is how you would distribute the final program with a seperate lua file because say you have a .exe and a lua file in the same directory how would I make it so that it is all one executable like how Löve 2d uses
copy /b
to append the lua file to the Löve 2d interpreter so it can be distributed.
could someone possibly explain how this works.
many thanks
Blazing
You could embed the lua code directly into your C++ source in a raw string literal like so:
const auto lua_code = R"lua(
...lua code here...
)lua";

Is it possible to call Matlab from QtCreator?

I am doing image analysis using C++ in the QtCreator environment. In order to build a learning model, I want to use the TreeBagger class from MATLAB, which is really powerful. Can I call MATLAB from QtCreator, give it some parameters, and get back the classification error? Can I do this without using mex files?
From QProcess's Synchronous Process API example:
QProcess gzip;
gzip.start("gzip", QStringList() << "-c");
if (!gzip.waitForStarted())
return false;
gzip.write("Qt rocks!");
gzip.closeWriteChannel();
if (!gzip.waitForFinished())
return false;
QByteArray result = gzip.readAll();
The concept to from this example is the process of being able to execute matlab w/ whatever settings that would be preferable and begin writing a script to it immediately. After the write; you can close the channel, wait for response, then read the results from matlab. Uunfortunately, I'm not experienced w/ it to provide a more direct example, but this is the concept for the most case. Please research the documentation for anything else.
Matlab has an "engine" interface described here to let standalone programs call matlab functions. It has the advantage that you can call engPutVariableand engGetVariable to transfer your data in binary format (I think it works by using shared memory between your process and matlab, but I'm not sure on this), so you don't have to convert your data to ascii and parse the result from ascii.
For c++ you might want to write a wrapper class for RAII or have a look at http://www.codeproject.com/Articles/4216/MATLAB-Engine-API, where this has already been done.