Hello again,
I am writing to this post, as I face some more problems with trying to link 
Julia functions with C++ code.
The thing is that I changed my current Julia version, I installed Julia 
running the source code as I wanted 
to install the Cxx package as well.
So, I just went to run the first smallest example with some c code and c++ 
code that uses a julia function
as presented here <http://julia.readthedocs.org/en/latest/manual/embedding/>, 
so I only try to run the following file:

#include <julia.h>
int main(int argc, char *argv[]){
    /* required: setup the julia context */
    jl_init(NULL);

    /* run julia commands */
    jl_eval_string("print(sqrt(2.0))");

    /* strongly recommended: notify julia that the         program is about to 
terminate. this allows         julia time to cleanup pending write requests     
    and run all finalizers    */
    jl_atexit_hook();
    return 0;}



The first thing that was different was that when I was including just the 
path of julia.h and libjulia.so and I
run the command like this:

gcc -o test main.c -I /home/kostav/julia/src -L/home/kostav/julia/usr/lib 
-ljulia

I receive an error saying: 

*In file included from main.c:1:0: /home/kostav/julia/src/julia.h:12:24: 
fatal error: libsupport.h: No such file or directory  #include 
"libsupport.h" compilation terminated.*

Then when I add the path of libsupport.h I receive a similar error msg 
saying that uv.h is missing so I have 
to add its path as well, and as a result I finally run the following 
command:

gcc -o test main.c -I /home/kostav/julia/src -I 
/home/kostav/julia/usr/include -I /home/kostav/julia/src/support 
-L/home/kostav/julia/usr/lib -ljulia

In that case I receive various errors about undefined references regarding 
llvm functions and as a result I include
as well the equivelant library and finally run the following command:

gcc -o test main.c -I /home/kostav/julia/src -I 
/home/kostav/julia/usr/include -I /home/kostav/julia/src/support 
-L/home/kostav/julia/usr/lib -ljulia -lLLVM-3.7svn

On this case the program does compile but when I try to run it, I receive 
the following error:




*error while loading shared libraries: libjulia.so: cannot open shared 
object file: No such file or directory*The exact same implies for the 
equivalent program in c++. Note that when I try to call a julia function 
inside a c++ more complicated 
structure (namely in a class) I receive a different error. More 
specifically just for the very simple class that exists
in this Cxx example 
<https://github.com/Keno/Cxx.jl#example-8-using-c-with-shared-libraries> 
for just using the same simple julia function inside the class that leads 
to the following slighltly different cpp file

#include "ArrayMaker.h"
#include <iostream>

using namespace std;

ArrayMaker::ArrayMaker(int iNum, float fNum) {

    jl_init(NULL);
    jl_eval_string("print(sqrt(2.0))");

    cout << "Got arguments: " << iNum << ", and " << fNum << endl;
    iNumber = iNum;
    fNumber = fNum;
    fArr = new float[iNumber];
    jl_atexit_hook();
}

float* ArrayMaker::fillArr() {
    cout << "Filling the array" << endl;
    for (int i=0; i < iNumber; i++) {
        fArr[i] = fNumber;
        fNumber *= 2;
    } 
    return fArr;
}

With the header file being almost the same:

#ifndef ARRAYMAKER_H
#define ARRAYMAKER_H

#include <julia.h>

class ArrayMaker
{
    private:
        int iNumber;
        float fNumber;
        float* fArr;
    public:
        ArrayMaker(int, float);
        float* fillArr();
};

#endif

When I try to compile in terminal using the following command:

g++ -o test ArrayMaker.cpp -I /home/kostav/julia/src -I 
/home/kostav/julia/usr/include -I /home/kostav/julia/src/support 
-L/home/kostav/julia/usr/lib -ljulia -lLLVM-3.7svn

I do receive the following error: 

/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../x86_64-linux-gnu/crt1.o: In 
function `_start': 
/build/buildd/glibc-2.21/csu/../sysdeps/x86_64/start.S:114: undefined 
reference to `main'
collect2: error: ld returned 1 exit status



I am really not sure how to resolve any of the two errors and in general 
the second one is also pretty important to me, as in general my end goal
is starting from a julia file to use my self-written c++ code, where inside 
the c++ code I call some other self-written julia functions, I know it does
sound kind twisted, but that's what I am interested to do, as I am trying 
to tackle a big Mathematical Problem by builing the original problem in Jump
then decompose it and use a solver that is written in c++ (that's why I 
need to call c++ inside julia) which then needs again to send back 
information
to the original model and probably solve some subproblems with CPLEX 
(that's why I will need inside the c++ code to call julia functions again). 
That
with as much as few words as possible in order not to bother you with a lot 
of unnecessary information.

Reply via email to