2011-03-09 47 views
1

我使用OCI库从oracle 9i(personal edtn)从我的c程序连接到数据库(使用visual c + + 2005) 我包括所有lib文件从oci并包括它们在额外的依赖也,但当我编译下面的代码我得到链接器错误 。错误链接到oci库从vC++

#include "stdafx.h" 
#include "Form1.h" 
#include <occi.h> 
#include<oratypes.h> 


using namespace ovci; 
using namespace oracle; 

[STAThreadAttribute] 
int main(array<System::String ^> ^args) 
{ 
     oracle::occi::Environment* environment; 
    oracle::occi::Connection *con; 
    oracle::occi::Statement* stmt; 
    oracle::occi::ResultSet* res;  
     environment = oracle::occi::Environment::createEnvironment(oracle::occi::Environment::DEFAULT); 
     con = environment->createConnection("scott", "tiger", ""); 
     stmt = con->createStatement("select * from emp2"); 
     res = stmt->executeQuery(); 
     stmt->closeResultSet(res); 
     con->terminateStatement(stmt); 
     environment->terminateConnection(con); 
    Application::EnableVisualStyles(); 
    Application::SetCompatibleTextRenderingDefault(false); 
    Application::Run(gcnew Form1()); 
    return 0; 
} 

的错误,我得到的是,

ovci.obj : error LNK2028: unresolved token (0A000016) "public: static class oracle::occi::Environment * __clrcall oracle::occi::Environment::createEnvironment(enum oracle::occi::Environment::Mode,void *,void * (__clrcall*)(void *,unsigned int),void * (__clrcall*)(void *,void *,unsigned int),void (__clrcall*)(void *,void *))" ([email protected]@[email protected]@@[email protected]@[email protected]@[email protected]@[email protected]) referenced in function "int __clrcall main(cli::array<class System::String^>^)" ([email protected]@[email protected]@@@Z) 
ovci.obj : error LNK2019: unresolved external symbol "public: static class oracle::occi::Environment * __clrcall oracle::occi::Environment::createEnvironment(enum oracle::occi::Environment::Mode,void *,void * (__clrcall*)(void *,unsigned int),void * (__clrcall*)(void *,void *,unsigned int),void (__clrcall*)(void *,void *))" ([email protected]@[email protected]@@[email protected]@[email protected]@[email protected]@[email protected]) referenced in function "int __clrcall main(cli::array<class System::String^>^)" ([email protected]@[email protected]@@@Z) 
+0

请注意,这不是一个C程序,它是一个C++/CLI程序。 – 2011-03-09 15:45:46

回答

0

出于某种原因,编译器与在Oracle头回调的调用约定搞乱。请尝试:

#pragma managed(push, off) 
#include <occi.h> 
#include <oratypes.h> 
#pragma managed(pop) 
+0

谢谢错误是我试图在clr /纯模式中使用杂注。现在将它切换到clr正常模式,并且我们的代码运行良好。谢谢。而且,从clr pure更改为clr normal模式会以任何方式影响我的表单。因为我不知道什么是clr纯模式和正常模式。 – naturmaN 2011-03-12 09:13:03

+0

在'/ clr'模式下,你得到一个混合模式的程序集,它具有部分MSIL和部分本地代码。 MSIL代码与CPU无关,但本机代码是32位或64位,每个都需要一个不同的DLL。因为您正在使用Oracle的本机库,所以我没有看到使用混合模式的任何方法。在'/ clr:pure'中,结果只有MSIL,并且可以使用相同的DLL以32位或64位模式运行。在'/ clr:safe'模式下,结果只有可验证的MSIL,它允许你在部分信任沙箱内运行。 – 2011-03-12 15:02:30