链接器错误“... .obj:错误LNK2019:函数中引用的未解析的外部符号”

问题描述 投票:1回答: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;
}
c++ linker
1个回答
1
投票

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

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

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

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

© www.soinside.com 2019 - 2024. All rights reserved.