簡體   English   中英

鏈接器錯誤“... .obj:錯誤 LNK2019:函數中引用的未解析的外部符號”

[英]Linker error “… .obj : error LNK2019: unresolved external symbol referenced in function”

我已經閱讀了之前針對同一鏈接器問題的所有回復或解決方案。 我知道鏈接器無法訪問定義了函數的庫文件,但我仍然沒有解決它的運氣!

錯誤:

1>trial_12th.obj : error LNK2019: unresolved external symbol _viStatusDesc@12 referenced in function _main
1>trial_12th.obj : error LNK2019: unresolved external symbol _viClose@4 referenced in function _main
1>trial_12th.obj : error LNK2019: unresolved external symbol _viRead@16 referenced in function _main
1>trial_12th.obj : error LNK2019: unresolved external symbol _viWrite@16 referenced in function _main
1>trial_12th.obj : error LNK2019: unresolved external symbol _viOpen@20 referenced in function _main
1>trial_12th.obj : error LNK2019: unresolved external symbol _viOpenDefaultRM@4 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;
}

您需要將visa32.lib 或visa64.lib 添加到您的鏈接器設置中。

一種方法是在編譯器源文件中使用編譯指示:

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

如果仍未找到,則在 IDE 中調整 lib 路徑或在編譯指示中包含完整路徑。

我遇到過同樣的問題。 我發現您必須在項目的鏈接器屬性下的附加依賴項中添加visa32.lib

去你的

項目屬性-> 鏈接器-> 附加依賴項-> 單擊向下箭頭->“編輯”-> 鍵入visa32.lib

單擊確定,確定

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM