2013-04-12 40 views
1

我已閱讀所有以前的回覆或針對相同鏈接程序問題的解決方案。我知道鏈接器無法訪問已定義函數的庫文件,但仍然沒有解決它的運氣!鏈接器錯誤「... .obj:錯誤LNK2019:函數中引用的無法解析的外部符號」

的錯誤:

1>trial_12th.obj : error LNK2019: unresolved external symbol [email protected] referenced in function _main 
1>trial_12th.obj : error LNK2019: unresolved external symbol [email protected] referenced in function _main 
1>trial_12th.obj : error LNK2019: unresolved external symbol [email protected] referenced in function _main 
1>trial_12th.obj : error LNK2019: unresolved external symbol [email protected] referenced in function _main 
1>trial_12th.obj : error LNK2019: unresolved external symbol [email protected] referenced in function _main 
1>trial_12th.obj : error LNK2019: unresolved external symbol [email protected] referenced in function _main 
1>C:\Users\41kchoudhary\Documents\Visual Studio 2010\Projects\trial_12th\Debug\trial_12th.exe : fatal error LNK1120: 6 unresolved externals 

我試圖從混合信號示波器發送和接收數據。爲此,我需要使用使用Microsoft Visual Studio C++定義的預定義命令/函數來編寫.cpp文件。我已經閱讀了使用這些命令的用戶手冊,並且我還擁有實現它所需的頭文件和庫。

我使用下面的代碼:

#include <visa.h> 
#include "stdafx.h" 
#include <stdio.h> 
#include <memory.h> 

int main(int argc, char* argv[]) 
{ 
    ViSession rm = VI_NULL, vi = VI_NULL; 
    ViStatus status; 
    ViChar buffer[256]; 
    ViUInt32 retCnt; 

    // Open a default session 
    status = viOpenDefaultRM(&rm); 
    if (status < VI_SUCCESS) goto error; 

    // Open the GPIB device at primary address 1, GPIB board 8 
    status = viOpen(rm, "USB::0x0699::0x0377::C011104::INSTR", VI_NULL, VI_NULL, 
    &vi); 
    if (status < VI_SUCCESS) goto error; 

    // Send an ID query. 
    status = viWrite(vi, (ViBuf) "*idn?", 5, &retCnt); 
    if (status < VI_SUCCESS) goto error; 

    // Clear the buffer and read the response 
    memset(buffer, 0, sizeof(buffer)); 
    status = viRead(vi, (ViBuf) buffer, sizeof(buffer), &retCnt); 
    if (status < VI_SUCCESS) goto error; 

    // Print the response 
    printf("id: %s\n", buffer); 

    // Clean up 
    viClose(vi); // Not needed, but makes things a bit more 

    // understandable 
    viClose(rm); // Closes resource manager and any sessions 

    // opened with it 
    return 0; 

    error: 
     // Report error and clean up 
      viStatusDesc(vi, status, buffer); 
      fprintf(stderr, "failure: %s\n", buffer); 
      if (rm != VI_NULL) { 
       viClose(rm); 
      } 
      return 1; 
} 
+0

您是否包含.lib文件? – ArgumentNullException

+2

您忘記鏈接到包含這些'Vi *'符號的庫。 –

+0

這可能是32位與64位問題(假設.lib文件已添加到項目中)。我也有這個問題。我按照TDS2000系列手冊(第5-2頁)中的說明解決了這個問題,從零開始創建一個新項目(例如,不轉換.dsw項目 - 很可能是因爲獲得了64位應用程序/項目) :未使用預編譯頭文件,「Win32」用於項目模板「Win32 Console Application」等。 –

回答

1

你需要或者visa32.lib或visa64.lib添加到您的連接設置。要做到這一點

的一種方法是在你的編譯器的源文件使用編譯:

#pragma comment(lib,"visa32.lib") 

如果仍然沒有找到它,然後在你的IDE調整你的lib路徑或包括在編譯的完整路徑。

+0

@ArgumentNullException:我已經包含如下項目的.lib文件 - > properties - > linker - > input - > additional dependencies – user2276161

+0

@ Haroogan:我想我已經將.lib文件包含在上面 – user2276161

+0

以上我已經嘗試使用#pragma,但它沒有工作:( – user2276161

相關問題