【问题标题】:Error: reference to ‘sword’ is ambiguous in armadillo and oracle occi compatibility issue错误:在犰狳和 oracle occi 兼容性问题中对“剑”的引用不明确
【发布时间】:2015-06-29 20:24:12
【问题描述】:

在犰狳 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;
};

global_variable.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

【问题讨论】:

  • 谢谢@Anton Savin

标签: c++ oracle11g centos6 armadillo occi


【解决方案1】:

您的代码中有一些 cmets:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-12-11
    • 1970-01-01
    • 2022-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多