错误:在armadillo和oracle occi兼容性问题中,对"剑"的引用不明确



在armadillo 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;

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

对代码的一些评论:

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

相关内容

  • 没有找到相关文章