1

对于同一个链接器问题,我已阅读所有先前的回复或解决方案。我了解链接器无法访问已定义函数的库文件,但我仍然无法解决它!

错误:

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

2 回答 2

1

您需要将 visa32.lib 或 visa64.lib 添加到链接器设置中。

一种方法是在编译器源文件中使用编译指示:

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

如果仍未找到,则在 IDE 中调整 lib 路径或在编译指示中包含完整路径。

于 2013-04-12T23:19:45.113 回答
1

我遇到过同样的问题。我发现您必须在项目的链接器属性下的附加依赖项中添加 visa32.lib

去你的

项目属性->链接器->附加依赖项->单击向下箭头->“编辑->键入visa32.lib

点击确定,确定

于 2020-07-10T04:26:47.920 回答