Ajanth
Ajanth

Reputation: 2515

Linker error in Visual C++ Windows Forms project

I am using SQLAPI++ to connect to Oracle from my Visual C++ application. I can easily connect to database from VC++ only when I do it in Win32 console appliation mode.

But when I try to do the same in Windows Forms Project I get the following linker errors. Can someone help me with this because I need the values entered in the form to be inserted into database.

My code is:

#include <SQLAPI.h> 
#include "stdafx.h"
#include "Form1.h"
#include <stdio.h>
using namespace sqlapi;
[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
    SAConnection con; 
    SACommand cmd;    
    try
    {
        con.Connect("", "scott", "tiger", SA_Oracle_Client);
        cmd.setConnection(&con);
        cmd.setCommandText(
            "Create table test_tbl(fid integer, fvarchar20 varchar(20), fblob blob)");
        cmd.Execute();
        cmd.setCommandText(
            "Insert into test_tbl(fid, fvarchar20) values (1, 'Some string (1)')");
        cmd.Execute();
        con.Commit();
    }
    catch(SAException &x)
    {
        try
        {
            con.Rollback();
        }
        catch(SAException &)
        {
        }
    }
    // Enabling Windows XP visual effects before any controls are created
    Application::EnableVisualStyles();
    Application::SetCompatibleTextRenderingDefault(false);
    Application::Run(gcnew Form1());
    return 0;
}

And the errors I get are

sqlapi.obj : error LNK2028: unresolved token (0A000010) "public: void __clrcall SAConnection::Rollback(void)" (?Rollback@SAConnection@@$$FQAMXXZ) referenced in function __catch$?main@@$$HYMHP$01AP$AAVString@System@@@Z$0
sqlapi.obj : error LNK2028: unresolved token (0A000016) "public: void __clrcall SAConnection::Commit(void)" (?Commit@SAConnection@@$$FQAMXXZ) referenced in function "int __clrcall main(cli::array<class System::String ^ >^)" (?main@@$$HYMHP$01AP$AAVString@System@@@Z)

sqlapi.obj : error LNK2028: unresolved token (0A000018) "public: void __clrcall SACommand::setCommandText(class SAString const &,enum SACommandType_t)" (?setCommandText@SACommand@@$$FQAMXABVSAString@@W4SACommandType_t@@@Z) referenced in function "int __clrcall main(cli::array<class System::String ^ >^)" (?main@@$$HYMHP$01AP$AAVString@System@@@Z)
sqlapi.obj : error LNK2028: unresolved token (0A000019) "public: void __clrcall SACommand::setConnection(class SAConnection *)" (?setConnection@SACommand@@$$FQAMXPAVSAConnection@@@Z) referenced in function "int __clrcall main(cli::array<class System::String ^ >^)" (?main@@$$HYMHP$01AP$AAVString@System@@@Z)
sqlapi.obj : error LNK2028: unresolved token (0A00001A) "public: __clrcall SAString::~SAString(void)" (??1SAString@@$$FQAM@XZ) referenced in function "int __clrcall main(cli::array<class System::String ^ >^)" (?main@@$$HYMHP$01AP$AAVString@System@@@Z)
sqlapi.obj : error LNK2028: unresolved token (0A00001B) "public: __clrcall SAString::SAString(char const *)" (??0SAString@@$$FQAM@PBD@Z) referenced in function "int __clrcall main(cli::array<class System::String ^ >^)" (?main@@$$HYMHP$01AP$AAVString@System@@@Z)
sqlapi.obj : error LNK2028: unresolved token (0A00001C) "public: void __clrcall SAConnection::Connect(class SAString const &,class SAString const &,class SAString const &,enum SAClient_t,void (__cdecl*)(class SAConnection &,enum SAConnectionHandlerType_t))" (?Connect@SAConnection@@$$FQAMXABVSAString@@00W4SAClient_t@@P6AXAAV1@W4SAConnectionHandlerType_t@@@Z@Z) referenced in function "int __clrcall main(cli::array<class System::String ^ >^)" (?main@@$$HYMHP$01AP$AAVString@System@@@Z)
sqlapi.obj : error LNK2028: unresolved token (0A00001D) "public: virtual __clrcall SACommand::~SACommand(void)" (??1SACommand@@$$FUAM@XZ) referenced in function __catch$?main@@$$HYMHP$01AP$AAVString@System@@@Z$0
sqlapi.obj : error LNK2028: unresolved token (0A00001E) "public: __clrcall SACommand::SACommand(void)" (??0SACommand@@$$FQAM@XZ) referenced in function "int __clrcall main(cli::array<class System::String ^ >^)" (?main@@$$HYMHP$01AP$AAVString@System@@@Z)
sqlapi.obj : error LNK2028: unresolved token (0A00001F) "public: virtual __clrcall SAConnection::~SAConnection(void)" (??1SAConnection@@$$FUAM@XZ) referenced in function __catch$?main@@$$HYMHP$01AP$AAVString@System@@@Z$0
sqlapi.obj : error LNK2028: unresolved token (0A000020) "public: __clrcall SAConnection::SAConnection(void)" (??0SAConnection@@$$FQAM@XZ) referenced in function "int __clrcall main(cli::array<class System::String ^ >^)" (?main@@$$HYMHP$01AP$AAVString@System@@@Z)
sqlapi.obj : error LNK2019: unresolved external symbol "public: virtual __clrcall SAConnection::~SAConnection(void)" (??1SAConnection@@$$FUAM@XZ) referenced in function __catch$?main@@$$HYMHP$01AP$AAVString@System@@@Z$0
sqlapi.obj : error LNK2019: unresolved external symbol "public: virtual __clrcall SACommand::~SACommand(void)" (??1SACommand@@$$FUAM@XZ) referenced in function __catch$?main@@$$HYMHP$01AP$AAVString@System@@@Z$0
sqlapi.obj : error LNK2019: unresolved external symbol "public: void __clrcall SAConnection::Rollback(void)" (?Rollback@SAConnection@@$$FQAMXXZ) referenced in function __catch$?main@@$$HYMHP$01AP$AAVString@System@@@Z$0
sqlapi.obj : error LNK2019: unresolved external symbol "public: void __clrcall SAConnection::Commit(void)" (?Commit@SAConnection@@$$FQAMXXZ) referenced in function "int __clrcall main(cli::array<class System::String ^ >^)" (?main@@$$HYMHP$01AP$AAVString@System@@@Z)

I dont get any errors in Win32 console mode. I've even added the libraries in additional dependencies also.

Upvotes: 2

Views: 3385

Answers (1)

jdasilva
jdasilva

Reputation: 616

I haven't worked with C++/CLI very much, but I think your having the same problem as answered in this question error linking to oci libraries from vc++.

I also found a comment at the bottom of this thread http://social.msdn.microsoft.com/Forums/en-US/vclanguage/thread/44fc45c4-10da-4670-bc5d-2f505ee32fd1 that implies C++ windows forms projects must be in /clr:pure mode. I'm guessing that might be the difference from a console app. I also wonder if you are using a later version of Visual Studio if you could get away with using /clr mode for Window Forms?

Upvotes: 1

Related Questions