2013-03-29 34 views
0

請注意,我使用的是Windows窗體與.NETC++:爲什麼我得到鏈接器錯誤?

這裏的應用是我的代碼:

#pragma once 
#include <cstdlib> 
#include <Windows.h> 
#include <string.h> 
#include <stdlib.h> 
#include <algorithm> 
#include <stdio.h> 
#include <string> 
#include <cstring> 
#include <iostream> 
#include <vcclr.h> 
#include <hashlibpp.h> 

namespace Launcher { 

    using namespace System; 
    using namespace System::ComponentModel; 
    using namespace System::Collections; 
    using namespace System::Windows::Forms; 
    using namespace System::Data; 
    using namespace System::Drawing; 
    using namespace System::Diagnostics; 
    using namespace MySql::Data::MySqlClient; 
    using namespace std; 
    using namespace System::Runtime::InteropServices; 




    /// <summary> 
    /// Summary for Form1 
    /// </summary> 
    public ref class Form1 : public System::Windows::Forms::Form 
    { 
    public: 
     Form1(void) 
     { 
      InitializeComponent(); 


      // 
      //TODO: Add the constructor code here 
      // 
     } 

    protected: 
     /// <summary> 
     /// Clean up any resources being used. 
     /// </summary> 
     ~Form1() 
     { 
      if (components) 
      { 
       delete components; 
      } 
     } 

    //Component properties (not important) 

     } 
#pragma endregion 

void convert(String^ total1, char *ch){ //Converts string to const char* 
    // Pin memory so GC can't move it while native function is called 
    pin_ptr<const wchar_t> c1 = PtrToStringChars(total1); 
    printf_s("%S\n", c1); 

    // Conversion to char* : 
    // Can just convert wchar_t* to char* using one of the 
    // conversion functions such as: 
    // WideCharToMultiByte() 
    // wcstombs_s() 
    // ... etc 
    size_t convertedChars = 0; 
    size_t sizeInBytes = ((total1->Length + 1) * 2); 
    errno_t err = 0; 
    ch = (char *)malloc(sizeInBytes); 

    err = wcstombs_s(&convertedChars, 
        ch, sizeInBytes, 
        c1, sizeInBytes); 
    if (err != 0) 
     printf_s("wcstombs_s failed!\n"); 

    printf_s("%s\n", ch); 
} 

void MarshalString (String^s, string& os) { //Another converter 
    using namespace Runtime::InteropServices; 
    const char* chars = 
     (const char*)(Marshal::StringToHGlobalAnsi(s)).ToPointer(); 
    os = chars; 
    Marshal::FreeHGlobal(IntPtr((void*)chars)); 
} 

void MarshalString (String^s, wstring& os) { //Another converter 
    using namespace Runtime::InteropServices; 
    const wchar_t* chars = 
     (const wchar_t*)(Marshal::StringToHGlobalUni(s)).ToPointer(); 
    os = chars; 
    Marshal::FreeHGlobal(IntPtr((void*)chars)); 
} 

    private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) { 
      } 
      //I removed some other functions from here because they are blank 
    private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { 
        //MySQL variables 
       try{ 
        conDataBase->Open(); 
        myReader=cmdDataBase->ExecuteReader(); 
        while(myReader->Read()){ 
        String^ atmp_user = textBox1->Text; 
        String^ user = (myReader->GetString(1));//Gets Usernames from database 
        String^ atmp_pass = textBox2->Text; 
        String^ pass = (myReader->GetString(2));//Gets Passwords from database 
        atmp_pass->ToLower();//Lower Case's variable 
        atmp_user->ToLower(); 
        String^ total1 = gcnew String(atmp_user+atmp_pass);//Combines 2 strings 

        string totala;//std::string 

        MarshalString(total1, totala);//Copies data from (total1) to (totala) 

        hashwrapper *myWrapper = new sha1wrapper();//SHA1 hashing begins 

        string hash1 = myWrapper->getHashFromString(totala);//creates new variable(hash1) and copies data from (totala) 

        String^ finalpass;//Creates new System::String 
        MarshalString(finalpass, hash1);//Copies data from (hash1) to (finalpass) 
delete myWrapper;//Ends SHA1 hashing 
           //Login Script 
        if(atmp_user == user && finalpass == pass){ 
         textBox1->Text = ("It worked!"); 
        } 
        } 
       } catch(Exception^ex) { 
        MessageBox::Show(ex->Message); 
       } 
     } 
    //Other blank functions created 
}; 
} 

下面是錯誤:

Error 4 error LNK2028: unresolved token (0A0000D5) "public: __clrcall md5wrapper::md5wrapper(void)" ([email protected]@[email protected]) referenced in function "public: class hashwrapper * __clrcall wrapperfactory::create(enum HL_Wrappertype)" ([email protected]@@[email protected]@[email protected]@@Z) C:\Users\Jeremy\Documents\Visual Studio 2010\Projects\Launcher\Launcher\hl_wrapperfactory.obj 
Error 3 error LNK2028: unresolved token (0A00009D) "public: __clrcall sha384wrapper::sha384wrapper(void)" ([email protected]@[email protected]) referenced in function "public: class hashwrapper * __clrcall wrapperfactory::create(enum HL_Wrappertype)" ([email protected]@@[email protected]@[email protected]@@Z) C:\Users\Jeremy\Documents\Visual Studio 2010\Projects\Launcher\Launcher\hl_wrapperfactory.obj 
Error 2 error LNK2028: unresolved token (0A000094) "public: __clrcall sha512wrapper::sha512wrapper(void)" ([email protected]@[email protected]) referenced in function "public: class hashwrapper * __clrcall wrapperfactory::create(enum HL_Wrappertype)" ([email protected]@@[email protected]@[email protected]@@Z) C:\Users\Jeremy\Documents\Visual Studio 2010\Projects\Launcher\Launcher\hl_wrapperfactory.obj 
Error 1 error LNK2028: unresolved token (0A00005B) "public: __clrcall sha256wrapper::sha256wrapper(void)" ([email protected]@[email protected]) referenced in function "public: class hashwrapper * __clrcall wrapperfactory::create(enum HL_Wrappertype)" ([email protected]@@[email protected]@[email protected]@@Z) C:\Users\Jeremy\Documents\Visual Studio 2010\Projects\Launcher\Launcher\hl_wrapperfactory.obj 
Error 5 error LNK2019: unresolved external symbol "public: __clrcall sha512wrapper::sha512wrapper(void)" ([email protected]@[email protected]) referenced in function "public: class hashwrapper * __clrcall wrapperfactory::create(enum HL_Wrappertype)" ([email protected]@@[email protected]@[email protected]@@Z) C:\Users\Jeremy\Documents\Visual Studio 2010\Projects\Launcher\Launcher\hl_wrapperfactory.obj 
Error 6 error LNK2019: unresolved external symbol "public: __clrcall sha384wrapper::sha384wrapper(void)" ([email protected]@[email protected]) referenced in function "public: class hashwrapper * __clrcall wrapperfactory::create(enum HL_Wrappertype)" ([email protected]@@[email protected]@[email protected]@@Z) C:\Users\Jeremy\Documents\Visual Studio 2010\Projects\Launcher\Launcher\hl_wrapperfactory.obj 
Error 7 error LNK2019: unresolved external symbol "public: __clrcall sha256wrapper::sha256wrapper(void)" ([email protected]@[email protected]) referenced in function "public: class hashwrapper * __clrcall wrapperfactory::create(enum HL_Wrappertype)" ([email protected]@@[email protected]@[email protected]@@Z) C:\Users\Jeremy\Documents\Visual Studio 2010\Projects\Launcher\Launcher\hl_wrapperfactory.obj 
Error 8 error LNK2019: unresolved external symbol "public: __clrcall md5wrapper::md5wrapper(void)" ([email protected]@[email protected]) referenced in function "public: class hashwrapper * __clrcall wrapperfactory::create(enum HL_Wrappertype)" ([email protected]@@[email protected]@[email protected]@@Z) C:\Users\Jeremy\Documents\Visual Studio 2010\Projects\Launcher\Launcher\hl_wrapperfactory.obj 
Error 9 error LNK1120: 8 unresolved externals C:\Users\Jeremy\Documents\Visual Studio 2010\Projects\Launcher\Debug\Launcher.exe 1 

我不懂這些,所以我希望你們能。順便說一句我在這個項目中使用hashlib ++庫SHA1哈希。我假設這就是爲什麼有這麼多的參考。

回答

0

您需要重新鏈接庫本身。在Visual Studio中,轉到項目首選項,鏈接器選項,然後選擇您正在使用的實際庫。 Here你可以在屏幕上找到一個關於如何完成的例子。

+0

它沒有附帶任何的.libs。只是包含文件。 – FreelanceCoder

+1

恐怕它必須與lib文件一起發貨才能正常工作。 – stdcall

0

這是我遇到的一個奇怪的錯誤。出於某種原因,VC++將這些方法視爲具有__clrcall調用約定,儘管它們屬於非託管類。我不確定是什麼觸發它,它大部分時間不會發生。

如果一切都失敗了,儘量明確地標記非託管班與__thiscall調用約定的方法(包括構造函數和析構函數)(這是不受管理方法的默認):

class md5wrapper 
{ 
public: 
    __thiscall md5wrapper(); 
    __thiscall ~md5wrapper(); 

    void __thiscall SomeMethod(); 

    ... 
相關問題