0

在犰狳 c++ 中,我使用了一些 api 并使用 oracle occi 尝试将值插入到 oracle 表中,但是我得到了一些像这样的错误:-

/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

我的示例代码是:- 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;
};

全局变量.h

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

生成文件:

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
4

1 回答 1

1

对您的代码的一些评论:

  • 小心使用全局变量(mat glbmtrx;in main.cpp)。如果库犰狳也使用全局变量来工作,你无法保证所有全局变量的分配顺序。如果你的变量glbmtrx是在构造函数使用的全局变量之前分配的mat,你就会遇到问题!如果你真的需要,更喜欢使用Singleton Pattern
  • common_struct.h:永远不要调用using头文件!您可以在命名空间之间创建冲突。想象一下,我想合并你的应用程序和我的应用程序。如果我使用vector在我的应用程序中命名的类,那么调用它而不会发生冲突会很复杂,因为它vector引用std::vector了您的文件。
  • 实际上,您的问题可能来自命名空间的冲突。我建议您永远不要调用using namespace std并始终将其添加到您调用的类/函数中。当我一起使用几个库时,我从不调用using namespace xxx,我总是使用全局名称。
于 2015-04-22T10:36:10.890 回答