为什么我收到“未解析的外部符号”消息?

时间:2013-11-20 22:47:40

标签: c++ hllapi

我正在尝试使用IBM的EHLLAPI与他们的Personal Communicator终端仿真器连接。我已经从this page复制了他们的示例代码,但是当我尝试构建它时,它给了我一个错误。

1>------ Build started: Project: PCOMAPI, Configuration: Debug Win32 ------
1>  Source.cpp
1>Source.obj : error LNK2019: unresolved external symbol _hllapi@16 referenced in function _main
1>C:\Users\[username]\Documents\Visual Studio 2013\Projects\VPARSAPI\Debug\PCOMAPI.exe : fatal error LNK1120: 1 unresolved externals

我不完全确定_hllapi @ 16是什么,我在代码中没有看到它。自从我使用C ++以来已经有一段时间了,所以它可能是我想念的简单事情。代码如下:

#include <stdlib.h>
#include <stdio.h>
#include <windows.h>
#include "hapi_c.h"


int main(char **argv, int argc) {
    int HFunc, HLen, HRc;
    char HBuff[1];
    struct HLDConnectPS ConnBuff;
    // Send Key string for HOME+string+ENTER:
    char SendString[] = "@0Hello World!@E";

    HFunc = HA_RESET_SYSTEM;
    HLen = 0;
    HRc = 0;
    hllapi(&HFunc, HBuff, &HLen, &HRc);
    if (HRc != HARC_SUCCESS) {
        printf("Unable to access EHLLAPI.\n");
        return 1;
    }

    HFunc = HA_CONNECT_PS;
    HLen = sizeof(ConnBuff);
    HRc = 0;
    memset(&ConnBuff, 0x00, sizeof(ConnBuff));
    ConnBuff.stps_shortname = 'A';
    hllapi(&HFunc, (char *)&ConnBuff, &HLen, &HRc);
    switch (HRc) {
    case HARC_SUCCESS:
    case HARC_BUSY:
    case HARC_LOCKED: // All these are OK
        break;
    case HARC_INVALID_PS:
        printf("Host session A does not exist.\n");
        return 1;
    case HARC_UNAVAILABLE:
        printf("Host session A is in use by another EHLLAPI application.\n");
        return 1;
    case HARC_SYSTEM_ERROR:
        printf("System error connecting to session A.\n");
        return 1;
    default:
        printf("Error connecting to session A.\n");
        return 1;
    }

    HFunc = HA_SENDKEY;
    HLen = strlen(SendString);
    HRc = 0;
    hllapi(&HFunc, SendString, &HLen, &HRc);
    switch (HRc) {
    case HARC_SUCCESS:
        break;
    case HARC_BUSY:
    case HARC_LOCKED:
        printf("Send failed, host session locked or busy.\n");
        break;
    default:
        printf("Send failed.\n");
        break;
    }

    HFunc = HA_DISCONNECT_PS;
    HLen = 0;
    HRc = 0;
    hllapi(&HFunc, HBuff, &HLen, &HRc);

    printf("EHLLAPI program ended.\n");
    return 0;
}

我的链接器标志是:

  • / OUT:“C:\ Users [username] \ Documents \ Visual Studio 2013 \ Projects \ VPARSAPI \ Debug \ PCOMAPI.exe“/ MANIFEST / NXCOMPAT
  • / PDB:“C:\ Users [username] \ Documents \ Visual Studio
  • 2013 \ Projects \ VPARSAPI \ Debug \ PCOMAPI.pdb“/ DYNAMICBASE”kernel32.lib“
  • “user32.lib”“gdi32.lib”“winspool.lib”“comdlg32.lib”“advapi32.lib”
  • “shell32.lib”“ole32.lib”“oleaut32.lib”“uuid.lib”“odbc32.lib”
  • “odbccp32.lib”/ DEBUG / MACHINE:X86 / INCREMENTAL
  • / PGD:“C:\用户[用户名] \文档\ Visual Studio2013 \ Projects \ VPARSAPI \ Debug \ PCOMAPI.pgd“/ SUBSYSTEM:CONSOLE
  • / MANIFESTUAC:“level ='asInvoker'uiAccess ='false'”
  • / manifest资源配置文件: “调试\ PCOMAPI.exe.intermediate.manifest”
  • / ERRORREPORT:PROMPT / NOLOGO / TLBID:1

2 个答案:

答案 0 :(得分:2)

这是一个链接器错误。您需要将链接传递给链接器.lib文件,即导入库,用于EHLLAPI库。

事实上,查看documentation,此库中有许多.lib文件。您需要仔细研究文档,找出您需要的文档。

答案 1 :(得分:0)

编译和链接部分所述,您必须包含 pcscal32.lib 以进行静态链接,因此可以解析* hapi_c.h *中的符号。< / p>