--------------------Configuration: cbnbsvr - Win32 Debug--------------------
Linking...
cbnbsvr.obj : error LNK2001: unresolved external symbol _Send
cbnbsvr.obj : error LNK2001: unresolved external symbol _Recv
cbnbsvr.obj : error LNK2001: unresolved external symbol _FormatNetbiosName
cbnbsvr.obj : error LNK2001: unresolved external symbol _AddName
cbnbsvr.obj : error LNK2001: unresolved external symbol _ResetAll
cbnbsvr.obj : error LNK2001: unresolved external symbol _LanaEnum
Debug/cbnbsvr.exe : fatal error LNK1120: 6 unresolved externals
Error executing link.exe.cbnbsvr.exe - 7 error(s), 0 warning(s)直接打开的教程的代码,原来有八个错误,在网上搜了下加了NetAPI32.lib WSOCK32.LIB 后还有7个错误。
在网上搜不出答案了,来这请教下,上面是VC里提示的错误,下面是教程里的代码.
还有lib文件的文件名是不是不分大小写的?// Module Name: Cbnbsvr.c
//
// Description:
//    This NetBIOS sample implements a server using the asynchronous
//    callback functions as opposed to asynch events.  The server
//    will add its name to each LANA number on the machine and post
//    a listen (NCBLISTEN) on each LANA in order to service client
//    requests.
//
// Compile:
//    cl -o cbnbsvr.exe cbnbsvr.c ..\Common\nbcommon.obj netapi32.lib
//
// Command Line Options:
//    NONE - The server automatically uses the NetBIOS name as
//           defined by the constant SERVER_NAME
//
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
   
#include "..\Common\nbcommon.h"#define MAX_BUFFER      2048
#define SERVER_NAME     "TEST-SERVER-1"DWORD WINAPI ClientThread(PVOID lpParam);//
// Function: ListenCallback
//
// Description:
//    This function is called when an asynchronous listen completes.
//    If no error occured create a thread to handle the client.
//    Also post another listen for other client connections.
//
void CALLBACK ListenCallback(PNCB pncb)
{
    HANDLE      hThread;
    DWORD       dwThreadId;    if (pncb->ncb_retcode != NRC_GOODRET)
    {
        printf("ERROR: ListenCallback: %d\n", pncb->ncb_retcode);
        return;
    }
    Listen(pncb->ncb_lana_num, SERVER_NAME);    hThread = CreateThread(NULL, 0, ClientThread, (PVOID)pncb, 0, 
        &dwThreadId);
    if (hThread == NULL)
    {
        printf("ERROR: CreateThread: %d\n", GetLastError());
        return;
    }
    CloseHandle(hThread);    return;
}//
// Function: ClientThread
//
// Description:
//    The client thread blocks for data sent from clients and 
//    simply sends it back to them. This is a continuous loop
//    until the sessions is closed or an error occurs.  If
//    the read or write fails with NRC_SCLOSED then the session
//    has closed gracefully so exit the loop.
//
DWORD WINAPI ClientThread(PVOID lpParam)
{
    PNCB        pncb = (PNCB)lpParam;
    NCB         ncb;
    char        szRecvBuff[MAX_BUFFER];
    DWORD       dwBufferLen = MAX_BUFFER,
                dwRetVal = NRC_GOODRET;
    char        szClientName[NCBNAMSZ+1];    FormatNetbiosName(pncb->ncb_callname, szClientName);    while (1)
    {
        dwBufferLen = MAX_BUFFER;        dwRetVal = Recv(pncb->ncb_lana_num, pncb->ncb_lsn,
szRecvBuff, &dwBufferLen);
        if (dwRetVal != NRC_GOODRET)
            break;
        szRecvBuff[dwBufferLen] = 0;
        printf("READ [LANA=%d]: '%s'\n", pncb->ncb_lana_num, 
            szRecvBuff);        dwRetVal = Send(pncb->ncb_lana_num, pncb->ncb_lsn,
szRecvBuff, dwBufferLen);
        if (dwRetVal != NRC_GOODRET)
            break;
    }
    printf("Client '%s' on LANA %d disconnected\n", szClientName,
        pncb->ncb_lana_num);
 
    if (dwRetVal != NRC_SCLOSED)
    {
        // Some other error occured, hang up the connection
        //
        ZeroMemory(&ncb, sizeof(NCB));
        ncb.ncb_command = NCBHANGUP;
        ncb.ncb_lsn = pncb->ncb_lsn;
        ncb.ncb_lana_num = pncb->ncb_lana_num;        if (Netbios(&ncb) != NRC_GOODRET)
        {
            printf("ERROR: Netbios: NCBHANGUP: %d\n", ncb.ncb_retcode);
            dwRetVal = ncb.ncb_retcode;
        }
        GlobalFree(pncb);
        return dwRetVal; 
    }
    GlobalFree(pncb);
    return NRC_GOODRET;
}//
// Function: Listen
//
// Description:
//    Post an asynchronous listen with a callback function. Create
//    an NCB structure for use by the callback (since it needs a
//    global scope).
//
int Listen(int lana, char *name)
{
    PNCB        pncb = NULL;    pncb = (PNCB)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, sizeof(NCB));
    pncb->ncb_command = NCBLISTEN | ASYNCH;
    pncb->ncb_lana_num = lana;
    pncb->ncb_post = ListenCallback;
    //
    // This is the name clients will connect to
    //
    memset(pncb->ncb_name, ' ', NCBNAMSZ);
    strncpy(pncb->ncb_name, name, strlen(name));
    //
    // An '*' means we'll take a client connection from anyone.  By
    // specifying an actual name here you restrict connections to
    // clients with that name only.
    //
    memset(pncb->ncb_callname, ' ', NCBNAMSZ);
    pncb->ncb_callname[0] = '*';    if (Netbios(pncb) != NRC_GOODRET)
    {
        printf("ERROR: Netbios: NCBLISTEN: %d\n", pncb->ncb_retcode);
        return pncb->ncb_retcode;
    }
    return NRC_GOODRET;
}//
// Function: main
//
// Description:
//    Initialize the NetBIOS interface, allocate some resources, add
//    the server name to each LANA, and post an asynch NCBLISTEN on
//    each LANA with the appropriate callback. Then wait for incoming
//    client connections, at which time, spawn a worker thread to
//    handle them. The main thread simply waits while the server
//    threads are handling client requests. You wouldn't do this in a
//    real application, but this sample is for illustrative purposes
//    only. 
//
int main(int argc, char **argv)
{
    LANA_ENUM   lenum;
    int         i,
                num;    // Enumerate all LANAs and reset each one
    //
    if (LanaEnum(&lenum) != NRC_GOODRET)
        return 1;
    if (ResetAll(&lenum, 254, 254, FALSE) != NRC_GOODRET)
        return 1;
    //
    // Add the server name to each LANA and issue a listen on each
    //
    for(i = 0; i < lenum.length; i++)
    {
        AddName(lenum.lana[i], SERVER_NAME, &num);
        Listen(lenum.lana[i], SERVER_NAME);
    }    while (1)
    {        
        Sleep(5000);
    }
}

解决方案 »

  1.   

    lib文件的文件名是不分大小写
      

  2.   

    cl -o cbnbsvr.exe cbnbsvr.c ..\Common\nbcommon.obj netapi32.lib 
    还有个nbcommon.c文件没参与编译,加进工程就好了。
    参考http://support.microsoft.com/kb/177314
      

  3.   

    #include "..\Common\nbcommon.h"
    是不是还有一个nbcommon.cpp文件啊?在Common目录里?
    将其添加到工程共,然后Rebuild All
      

  4.   

    谢谢tttyd 和 socoola 确定是有nbcommon.c文件没加进工程导致辞程序不能运行.
      

  5.   

    程序正常运行了,但为什么我添加头文件#include<iostream.h>后,还是不可以使用cout和<<
      

  6.   

    #include <iostream>
    using namespace std;
      

  7.   

    提示 "eh.h is only for C++!" 
      

  8.   

    你的是c文件啊,把后缀改成cpp或者不要使用cin和cout
      

  9.   

    哪里在的后缀改成cpp啊?
    iostream.cpp
    还是using namespace cpp
    都是错的.比较喜欢cin和cout
    scanf和printf需要%d %c的格式化,打起来很麻烦而且%s非常不好用,cout就方便多了.
      

  10.   

    知道了,连文件后缀名都搞不清了。
    改完后,编译时问题更多,我看我这种菜中之菜还是乖乖scanf和printf好点,免得问题越搞越多.
    谢谢两位了,又帮我一次
      

  11.   

    下面是客户端代码,主函数里开始的判断条件是怎么回事?
    那个main函数参数argc如果不是3就退出程序,我在if之前给它argc=3,最后执行错误.
    我把if里面的return 给屏蔽还是执行错误,那这个例题的客户端怎么能和上面的服务器端连上并让服务器返回客户端发送的信息呢?
    书上说是这样的作用,我就像看看执行结果,再来慢慢研究。// Module Name: Nbclient.c
    //
    // Purpose:
    //    This is a NetBIOS client application that can interact with
    //    either of the two server samples.  The client attempts a
    //    connection to the server on all LANA numbers. Once the first
    //    connect succeeds, all others are cancelled or disconnected.
    //
    // Compile:
    //    cl -o Nbclient.exe Nbclient.c ..\Common\Nbcommon.obj
    //       netapi32.lib user32.lib
    //
    // Command Line Options:
    //    Nbclient.exe CLIENT-NAME SERVER-NAME
    //
    //    CLIENT-NAME        The NetBIOS name this client registers as
    //    SERVER-NAME        The NetBIOS name of the server to connect to
    //
    #include <windows.h>
    #include <stdio.h>
    #include <stdlib.h>#include "..\Common\nbcommon.h"#define MAX_SESSIONS     254
    #define MAX_NAMES        254#define MAX_BUFFER       1024char    szServerName[NCBNAMSZ];//
    // Function: Connect
    //
    // Description:
    //    Post an asynchronous connect on the given LANA number to
    //    the server. The NCB structure passed in already has the 
    //    ncb_event field set to a valid Windows event handle. Just
    //    fill in the blanks and make the call.
    //
    int Connect(PNCB pncb, int lana, char *server, char *client)
    {
        pncb->ncb_command = NCBCALL | ASYNCH;
        pncb->ncb_lana_num = lana;    memset(pncb->ncb_name, ' ', NCBNAMSZ);
        strncpy(pncb->ncb_name, client, strlen(client));    memset(pncb->ncb_callname, ' ', NCBNAMSZ);
        strncpy(pncb->ncb_callname, server, strlen(server));    if (Netbios(pncb) != NRC_GOODRET)
        {
            printf("ERROR: Netbios: NCBCONNECT: %d\n",
    pncb->ncb_retcode);
            return pncb->ncb_retcode;
        }
        return NRC_GOODRET;
    }//
    // Function: main
    //
    // Description:
    //    Initialize the NetBIOS interface, allocate some resources
    //    (event handles, a send buffer, and so on), and issue an 
    //    NCBCALL for each LANA to the given server. Once a connection
    //    has been made, cancel or hang up any other outstanding
    //    connections. Then send/receive the data. Finally, clean 
    //    things up.
    //
    int main(int argc, char **argv)
    {
        HANDLE      *hArray;
        NCB         *pncb;
        char         szSendBuff[MAX_BUFFER];
        DWORD        dwBufferLen,
                     dwRet,
                     dwIndex,
                     dwNum;
        LANA_ENUM    lenum;
        int          i;

       if (argc != 3)
        {
            printf("usage: nbclient CLIENT-NAME SERVER-NAME\n");
            return 1;
        }
        // Enumerate all LANAs and reset each one
        //
        if (LanaEnum(&lenum) != NRC_GOODRET)
            return 1;
        if (ResetAll(&lenum, (UCHAR)MAX_SESSIONS, (UCHAR)MAX_NAMES, 
                FALSE) != NRC_GOODRET)
            return 1;
        strcpy(szServerName, argv[2]);
        //
        // Allocate an array of HANDLEs to use for asynchronous events.
        // Also allocate an array of NCB structures.  We need 1 handle
    // and 1 NCB for each LANA number.
        //
        hArray = (HANDLE *)GlobalAlloc(GMEM_FIXED,
    sizeof(HANDLE) * lenum.length);
        pncb   = (NCB *)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT,
    sizeof(NCB) * lenum.length);        
        //
        // Create an event and assign it into the corresponding NCB 
        // structure and issue an asynchronous connect (NCBCALL). 
        // Additionally don't forget to add the clients name to each
    // LANA it wants to connect over.
        //
        for(i = 0; i < lenum.length; i++)
        {
            hArray[i] = CreateEvent(NULL, TRUE, FALSE, NULL);
            pncb[i].ncb_event = hArray[i];        AddName(lenum.lana[i], argv[1], &dwNum);
            Connect(&pncb[i], lenum.lana[i], szServerName, argv[1]);
        }
        // Wait for at least one connection to succeed
        //
        dwIndex = WaitForMultipleObjects(lenum.length, hArray, FALSE, 
            INFINITE);
        if (dwIndex == WAIT_FAILED)
        {
            printf("ERROR: WaitForMultipleObjects: %d\n",
    GetLastError());
        }
        else
        {
            // If more than one connection succeeds, hang up the extra 
            // connection. We'll use the connection that was returned
            // by WaitForMultipleObjects. Otherwise, if it's still pending,
            // cancel it.
            //
            for(i = 0; i < lenum.length; i++)
            {
                if (i != dwIndex)
                {
                    if (pncb[i].ncb_cmd_cplt == NRC_PENDING)
                        Cancel(&pncb[i]);
                    else
                        Hangup(pncb[i].ncb_lana_num, pncb[i].ncb_lsn);
                }
            }
            printf("Connected on LANA: %d\n", pncb[dwIndex].ncb_lana_num);
            //
            // Send and receive the messages
            //
            for(i = 0; i < 20; i++)
            {
                wsprintf(szSendBuff, "Test message %03d", i);
                dwRet = Send(pncb[dwIndex].ncb_lana_num, 
                    pncb[dwIndex].ncb_lsn, szSendBuff,
    strlen(szSendBuff));
                if (dwRet != NRC_GOODRET)
                    break;
                dwBufferLen = MAX_BUFFER;
                dwRet = Recv(pncb[dwIndex].ncb_lana_num, 
                    pncb[dwIndex].ncb_lsn, szSendBuff, &dwBufferLen);
                if (dwRet != NRC_GOODRET)
                    break;
                szSendBuff[dwBufferLen] = 0;
                printf("Read: '%s'\n", szSendBuff);
            }
            Hangup(pncb[dwIndex].ncb_lana_num, pncb[dwIndex].ncb_lsn);
        }
        // Clean things up
        //
        for(i = 0; i < lenum.length; i++)
        {
            DelName(lenum.lana[i], argv[1]);
            CloseHandle(hArray[i]);
        }
        GlobalFree(hArray);
        GlobalFree(pncb);    return 0;
    }