Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register
  • Index
  • » Users
  • » anurag
  • » Profile

Posts

Posts

Sep-27-18 09:37:39
i am calling a external c++ function written in coin linear programming and wish to call it from...

Thanks  a lot i will do the changes suggested and see if it works

Aug-31-18 11:45:20
i am calling a external c++ function written in coin linear programming and wish to call it from...

Hello everyone and thank you in advance for your help
I would like  to call a external C++ function written in coin linear programming .test1.cpp whose code is

#include<iostream>
#include"include/coin/OsiSolverInterface.hpp"
#include "include/coin/OsiClpSolverInterface.hpp"
#include "CoinUtils/src/CoinPackedMatrix.hpp"
#include "CoinUtils/src/CoinPackedVector.hpp"

int linp(void)
{
    int nCons = 7;//Number of constraints
    int nVars = 2;//Number of variables
    double  Obj_Func[2] = {-1,-1/3};//Objective Function
    double conMatrix[14]={1,1/4,1,1,1,1/4,1,-1,-1/4,-1,-1,-1,-1,1};//Constraint Matrix
    double  conUB[7]={1/2,2,1,2,1,-1,2};//Constraint Upper Bound
    double  conLB[7] = {1/2, -10000000, -10000000, -10000000, -10000000, -10000000, -10000000}; //Constraint Lower Bound

    double  LB[2]={-1,-0.5};//Variable Lower Bound
    double UB[2]={1.5,1.25};//Variable Upper Bound
    double options[1]  = {3000.0};
    OsiSolverInterface* si = new OsiClpSolverInterface();
    //Defining the constraint matrix
    CoinPackedMatrix *matrix =  new CoinPackedMatrix(false , 0 , 0);
    matrix->setDimensions(0 , nVars);
    for(int i=0 ; i<nCons ; i++)
       {
            CoinPackedVector row;
         for(int j=0 ; j<nVars; j++)
        {
            row.insert(j, conMatrix[i+j*nCons]);
        }
            matrix->appendRow(row);
       }

    //setting options for maximum iterations
        si->setIntParam(OsiMaxNumIteration,options[0]);   

    //Load the problem to OSI
    si->loadProblem(*matrix , LB , UB, Obj_Func , conLB , conUB);

    //Solve the problem
    si->initialSolve();   
    //Output the solution to Scilab
    //get solution for x
    const double* xVal = si->getColSolution();
    double* xValue = const_cast<double*>(xVal);

    for (int i = 0; i<nVars;i++)
    {
        std::cout <<"var"<<i<<" = "<<xValue[i]<<"\n";
    }
   
    //get objective value
    double objValue = si->getObjValue();
   
    return 0;
}

it runs fine in gcc 
I have  converted it into object file test1-utf8.o using gcc in ubuntu 16.04
and i am calling it from the modelica code

model test1
function Ex
output Integer k;
external  k=linp()annotation(Include="#include\"test1-utf8.o\"",Library="OsiClp",Library="Clp",Library="ClpSolver",Library="CoinUtils",Library="Osi");
end Ex;
Integer k;
equation
k=Ex();
end test1;



it gives the error 

OMEdit-test1 Simulation Output

make -j2 -f test1.makefile
clang   -fPIC -O0 -march=native      "-I/home/fossee/Desktop/Extern_func/Resources/Include" -I"/usr/include/omc/c" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -DOMC_MODEL_PREFIX=test1 -DOMC_NUM_MIXED_SYSTEMS=0 -DOMC_NUM_LINEAR_SYSTEMS=0 -DOMC_NUM_NONLINEAR_SYSTEMS=0 -DOMC_NDELAY_EXPRESSIONS=0 -DOMC_NVAR_STRING=0  -c -o test1.o test1.c
clang   -fPIC -O0 -march=native      "-I/home/fossee/Desktop/Extern_func/Resources/Include" -I"/usr/include/omc/c" -I. -DOPENMODELICA_XML_FROM_FILE_AT_RUNTIME -DOMC_MODEL_PREFIX=test1 -DOMC_NUM_MIXED_SYSTEMS=0 -DOMC_NUM_LINEAR_SYSTEMS=0 -DOMC_NUM_NONLINEAR_SYSTEMS=0 -DOMC_NDELAY_EXPRESSIONS=0 -DOMC_NVAR_STRING=0  -c -o test1_functions.o test1_functions.c
In file included from test1_functions.c:6:
In file included from ./test1_includes.h:4:
/home/fossee/Desktop/Extern_func/Resources/Include/test1-utf8.o:1:1: error: expected identifier or '('
<U+007F>ELF<U+0002><U+0001><U+0001>
^
/home/fossee/Desktop/Extern_func/Resources/Include/test1-utf8.o:1:8: warning: null character ignored [-Wnull-character]
<U+007F>ELF<U+0002><U+0001><U+0001>
                                   ^
/home/fossee/Desktop/Extern_func/Resources/Include/test1-utf8.o:1:9: warning: null character ignored [-Wnull-character]
<U+007F>ELF<U+0002><U+0001><U+0001><U+0000>
                                           ^
/home/fossee/Desktop/Extern_func/Resources/Include/test1-utf8.o:1:10: warning: null character ignored [-Wnull-character]
<U+007F>ELF<U+0002><U+0001><U+0001><U+0000><U+0000>
                                                   ^
/home/fossee/Desktop/Extern_func/Resources/Include/test1-utf8.o:1:11: warning: null character ignored [-Wnull-character]
<U+007F>ELF<U+0002><U+0001><U+0001><U+0000><U+0000><U+0000>
                                                           ^
/home/fossee/Desktop/Extern_func/Resources/Include/test1-utf8.o:1:12: warning: null character ignored [-Wnull-character]
<U+007F>ELF<U+0002><U+0001><U+0001><U+0000><U+0000><U+0000><U+0000>
                                                                   ^
/home/fossee/Desktop/Extern_func/Resources/Include/test1-utf8.o:1:13: warning: null character ignored [-Wnull-character]
<U+007F>ELF<U+0002><U+0001><U+0001><U+0000><U+0000><U+0000><U+0000><U+0000>
                                                                           ^
/home/fossee/Desktop/Extern_func/Resources/Include/test1-utf8.o:1:14: warning: null character ignored [-Wnull-character]
<U+007F>ELF<U+0002><U+0001><U+0001><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000>
                                                                                   ^
/home/fossee/Desktop/Extern_func/Resources/Include/test1-utf8.o:1:15: warning: null character ignored [-Wnull-character]
<U+007F>ELF<U+0002><U+0001><U+0001><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000>
                                                                                           ^
/home/fossee/Desktop/Extern_func/Resources/Include/test1-utf8.o:1:16: warning: null character ignored [-Wnull-character]
<U+007F>ELF<U+0002><U+0001><U+0001><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000>
                                                                                                   ^
/home/fossee/Desktop/Extern_func/Resources/Include/test1-utf8.o:1:18: warning: null character ignored [-Wnull-character]
<U+007F>ELF<U+0002><U+0001><U+0001><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0001>
                                                                                                                   ^
/home/fossee/Desktop/Extern_func/Resources/Include/test1-utf8.o:1:20: warning: null character ignored [-Wnull-character]
<U+007F>ELF<U+0002><U+0001><U+0001><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0001><U+0000>>
                                                                                                                            ^
/home/fossee/Desktop/Extern_func/Resources/Include/test1-utf8.o:1:22: warning: null character ignored [-Wnull-character]
<U+007F>ELF<U+0002><U+0001><U+0001><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0001><U+0000>><U+0000><U+0001>
                                                                                                                                            ^
/home/fossee/Desktop/Extern_func/Resources/Include/test1-utf8.o:1:23: warning: null character ignored [-Wnull-character]
<U+007F>ELF<U+0002><U+0001><U+0001><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0001><U+0000>><U+0000><U+0001><U+0000>
                                                                                                                                                    ^
/home/fossee/Desktop/Extern_func/Resources/Include/test1-utf8.o:1:24: warning: null character ignored [-Wnull-character]
<U+007F>ELF<U+0002><U+0001><U+0001><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0001><U+0000>><U+0000><U+0001><U+0000><U+0000>
                                                                                                                                                            ^
/home/fossee/Desktop/Extern_func/Resources/Include/test1-utf8.o:1:25: warning: null character ignored [-Wnull-character]
<U+007F>ELF<U+0002><U+0001><U+0001><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0001><U+0000>><U+0000><U+0001><U+0000><U+0000><U+0000>
                                                                                                                                                                    ^
/home/fossee/Desktop/Extern_func/Resources/Include/test1-utf8.o:1:26: warning: null character ignored [-Wnull-character]
<U+007F>ELF<U+0002><U+0001><U+0001><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0001><U+0000>><U+0000><U+0001><U+0000><U+0000><U+0000><U+0000>
                                                                                                                                                                            ^
/home/fossee/Desktop/Extern_func/Resources/Include/test1-utf8.o:1:27: warning: null character ignored [-Wnull-character]
<U+007F>ELF<U+0002><U+0001><U+0001><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0001><U+0000>><U+0000><U+0001><U+0000><U+0000><U+0000><U+0000><U+0000>
                                                                                                                                                                                    ^
/home/fossee/Desktop/Extern_func/Resources/Include/test1-utf8.o:1:28: warning: null character ignored [-Wnull-character]
<U+007F>ELF<U+0002><U+0001><U+0001><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0001><U+0000>><U+0000><U+0001><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000>
                                                                                                                                                                                            ^
/home/fossee/Desktop/Extern_func/Resources/Include/test1-utf8.o:1:29: warning: null character ignored [-Wnull-character]
<U+007F>ELF<U+0002><U+0001><U+0001><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0001><U+0000>><U+0000><U+0001><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000>
                                                                                                                                                                                                    ^
/home/fossee/Desktop/Extern_func/Resources/Include/test1-utf8.o:1:30: warning: null character ignored [-Wnull-character]
<U+007F>ELF<U+0002><U+0001><U+0001><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0001><U+0000>><U+0000><U+0001><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000>
                                                                                                                                                                                                            ^
/home/fossee/Desktop/Extern_func/Resources/Include/test1-utf8.o:1:31: warning: null character ignored [-Wnull-character]
<U+007F>ELF<U+0002><U+0001><U+0001><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0001><U+0000>><U+0000><U+0001><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000>
                                                                                                                                                                                                                    ^
/home/fossee/Desktop/Extern_func/Resources/Include/test1-utf8.o:1:32: warning: null character ignored [-Wnull-character]
<U+007F>ELF<U+0002><U+0001><U+0001><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0001><U+0000>><U+0000><U+0001><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000>
                                                                                                                                                                                                                            ^
/home/fossee/Desktop/Extern_func/Resources/Include/test1-utf8.o:1:33: warning: null character ignored [-Wnull-character]
<U+007F>ELF<U+0002><U+0001><U+0001><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0001><U+0000>><U+0000><U+0001><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000>
                                                                                                                                                                                                                                    ^
/home/fossee/Desktop/Extern_func/Resources/Include/test1-utf8.o:1:34: warning: null character ignored [-Wnull-character]
<U+007F>ELF<U+0002><U+0001><U+0001><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0001><U+0000>><U+0000><U+0001><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000>
                                                                                                                                                                                                                                            ^
/home/fossee/Desktop/Extern_func/Resources/Include/test1-utf8.o:1:35: warning: null character ignored [-Wnull-character]
<U+007F>ELF<U+0002><U+0001><U+0001><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0001><U+0000>><U+0000><U+0001><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000>
                                                                                                                                                                                                                                                    ^
/home/fossee/Desktop/Extern_func/Resources/Include/test1-utf8.o:1:36: warning: null character ignored [-Wnull-character]
<U+007F>ELF<U+0002><U+0001><U+0001><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0001><U+0000>><U+0000><U+0001><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000>
                                                                                                                                                                                                                                                            ^
/home/fossee/Desktop/Extern_func/Resources/Include/test1-utf8.o:1:37: warning: null character ignored [-Wnull-character]
<U+007F>ELF<U+0002><U+0001><U+0001><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0001><U+0000>><U+0000><U+0001><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000>
                                                                                                                                                                                                                                                                    ^
/home/fossee/Desktop/Extern_func/Resources/Include/test1-utf8.o:1:38: warning: null character ignored [-Wnull-character]
<U+007F>ELF<U+0002><U+0001><U+0001><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0001><U+0000>><U+0000><U+0001><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000>
                                                                                                                                                                                                                                                                            ^
/home/fossee/Desktop/Extern_func/Resources/Include/test1-utf8.o:1:39: warning: null character ignored [-Wnull-character]
<U+007F>ELF<U+0002><U+0001><U+0001><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0001><U+0000>><U+0000><U+0001><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000>
                                                                                                                                                                                                                                                                                    ^
/home/fossee/Desktop/Extern_func/Resources/Include/test1-utf8.o:1:40: warning: null character ignored [-Wnull-character]
<U+007F>ELF<U+0002><U+0001><U+0001><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0001><U+0000>><U+0000><U+0001><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000><U+0000>
                                                                                                                                                                                                                                                                                            ^
30 warnings and 1 error generated.
<builtin>: recipe for target 'test1_functions.o' failed
make: *** [test1_functions.o] Error 1
make: *** Waiting for unfinished jobs....
Compilation process failed. Exited with code 2.


please tell me what is wrong in the above procedure as test1.cpp gives right answer when compiled and run in gcc ubuntu 16.04.

my Directory structure is as follows

                                                                         extern_Funct
                                                                                 Resoureces                                                                                         test1.mo
                                                                                     Include                                                     Library
                                                                                       test1-utf.o                                              linux 64
                                                                                                                                                       all the library files of coin linear programming                 


  • Index
  • » Users
  • » anurag
  • » Profile
You are here: