Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.1k views
in Technique[技术] by (71.8m points)

visual c++ - error linking to oci libraries from vc++

Im using the OCI libraries from oracle 9i(personal edtn) for connecting to the database from my c program.(im using visual c++ 2005) ive included all lib files from oci and included them in the additional dependency also, but when i compile the following code i get linker errors.

#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;
}

the errors i get are,

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 *))" (?createEnvironment@Environment@occi@oracle@@$$FSMPAV123@W4Mode@123@PAXP6MPAX1I@ZP6MPAX11I@ZP6MX11@Z@Z) referenced in function "int __clrcall main(cli::array<class System::String ^ >^)" (?main@@$$HYMHP$01AP$AAVString@System@@@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 *))" (?createEnvironment@Environment@occi@oracle@@$$FSMPAV123@W4Mode@123@PAXP6MPAX1I@ZP6MPAX11I@ZP6MX11@Z@Z) referenced in function "int __clrcall main(cli::array<class System::String ^ >^)" (?main@@$$HYMHP$01AP$AAVString@System@@@Z)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

For some reason, the compiler is messing with the calling convention of callbacks in the oracle headers. Try:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...