0

In armadillo c++ i use some api and using oracle occi try to insert the value into oracle table,but I get some error like this:-

/home/oracle/Desktop/project/armadillo-4.450.4/include/armadillo_bits/typedef_elem.hpp:79: error:                 typedef arma::s32 arma::sword
/usr/include/oracle/11.1/client/ociap.h:10830: error: reference to ‘sword’ is ambiguous
/usr/include/oracle/11.1/client/oratypes.h:227: error: candidates are: typedef int sword

My sample code is:- main.cpp

#include <stdio.h>
#include <iostream>
#include "db_manager.h"
#include <armadillo>
using namespace arma;
int glbsize;//this variable is global it is declared in global_variables.h
mat glbmtrx;//this variable is global it is declared in global_variables.h
void add()
{
    double deter;
    int ppp=0;
    mat z;
    mat x = randu<mat>(4,4);
    mat y = randu<mat>(4,4);
    z=x+y;
    mystruct strct;
    strct.mymatrix=z;//variable from comm.structure 
    glbmtrx=strct.mymatrix;//varible from glb.variables
    deter= det(z);  
    db_manager db;
    db.load_determinant(deter);
}
int main()
{
    add();
    return 0;
}

db_manager.cpp

#include "db_manager.h"
#include <sstream>
#include <iostream>
#include <sstream>
#include <fstream>
using namespace oracle::occi;
using namespace std;
Environment *env;
Connection  *con;
void db_manager::load_determinant(double det)
{      
    mystruct strct;
    strct.deter_size=det;//var from comm.structure
    string user = "user";
    string passwd = "p@$$word";
    string db = "localhost:1521/sisdba";
    env = Environment::createEnvironment((Environment::Mode)(Environment::OBJECT|Environment::THREADED_MUTEXED));
    con = env->createConnection(user, passwd, db);
    Statement *stmt = NULL;
    ResultSet *rs = NULL;
    string concat1="";
    concat1=static_cast<ostringstream*>(&(ostringstream()<<det))->str();
    string sql="insert into determinanit_table values('"+concat1+"')";
    stmt = con->createStatement(sql);
    stmt->executeUpdate(sql);
    env->terminateConnection (con);
    Environment::terminateEnvironment (env);
}

db_manager.h

#include "includes/global_variables.h"
#include <occi.h>
class db_manager
{
public:
    db_manager(void);
    ~db_manager(void);
            void load_determinant(double det);  
};

common_struct.h

#include <armadillo>
using namespace arma;
using namespace std;

struct mystruct
{
    mat mymatrix;
    double deter_size;
};

global_variable.h

#include "../includes/common_structures.h"
using namespace arma;
extern int glbsize;
extern mat glbmtrx;

Makefile:

excute:main.o db_manager.o
    g++ -o excute main.o db_manager.o \
    -I/home/oracle/Desktop/sum_result/armadillo-4.450.4/include -DARMA_USE_BLAS -DARMA_USE_LAPACK -DARMA_DONT_USE_WRAPPER -lblas -llapack \
    -I/usr/include/oracle/11.1/client \
    -L$(ORACLE_HOME)/lib -lclntsh -locci
%.o: %.cpp
    g++ -c -o $@ $< -ggdb \
    -I/home/oracle/Desktop/sum_result/armadillo-4.450.4/include -DARMA_USE_BLAS -DARMA_USE_LAPACK -DARMA_DONT_USE_WRAPPER -lblas -llapack \
    -I/usr/include/oracle/11.1/client \
    -L$(ORACLE_HOME)/lib -lclntsh -locci
clean:
    rm *.o excute
kahsay kalayu
  • 309
  • 5
  • 16

1 Answers1

1

Some comments on your code :

  • Be carreful with global variables (mat glbmtrx; in main.cpp). If the library armadillo also use global variables to work, you have no guaranty about the order of allocation of all the global variables. If your variable glbmtrx is allocated before a global variable used by the constructor of mat, you are going to have a problem ! If you really need that, prefer to use the Singleton Pattern.
  • In common_struct.h : never call using in a header file ! You can create conflict between namespaces. Imagine, I want to merge your application and my application. If I use a class named vector in my application, it will be complex to call it without conflicts, due to the fact that vector refers to std::vector due to your file.
  • Actually, it's possible your problem comes from a conflict of namespaces. I advise you to never call using namespace std and always add it to the classes/functions you call. When I use several libraries together, I never call using namespace xxx and I always use global names.
Caduchon
  • 4,574
  • 4
  • 26
  • 67