VxWorks平台中对Socket的未定义引用

问题描述 投票:0回答:1

我正在使用Vxworks 653平台,已经创建了一个应用程序分区。我要在应用程序分区上创建服务器,构建它之后我收到错误

对“套接字”的未定义引用,对“绑定”的未定义引用

我该怎么办是链接器错误或我缺少什么

代码:

        # include "vxWorks.h"   
        # include "sockLib.h"   
        # include "sys/socket.h"   
        # include "netinet/in.h"   
        # include "inetLib.h"   
        # include "ioLib.h"   
        # include "string.h"   
        # include "stdio.h"   
        # include "taskLib.h"   

        /* typedefs */

        typedef int SOCK_FD;/*  

        /* forward declarations */

        LOCAL void error(char* str);

        /******************************************************************************  
        *  
        * vxServer - processes UDP client requests  
        *  
        * This routine sits in an infinite loop handling client requests.  
        * When a request is received, the client's data is converted  
        * to the local byte-ordering and then displayed.  Next,  
        * a reply is sent to the client.  Then the server will process  
        * the next request or block if there is none.  
        */

        void vxServer(u_short port)
        {
            int clientAddrLength;
            SOCK_FD sockFd;
            struct sockaddr_in clientAddr;   
            struct sockaddr_in srvAddr;   
            char inetAddr[INET_ADDR_LEN];
        u_short clientPort;
        char* reply = "Here is your reply\n";
        int val;

        clientAddrLength = sizeof (clientAddr);   

            /* Create a socket */   
            if ((sockFd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)   
                error("Socket failed");

        /*   
         * Bind to a well known address. INADDR_ANY says  
         * any network interface will do. htonX()  
         * routines put things in network byte order.  
         */

        bzero((char*)&srvAddr, sizeof(srvAddr));
        srvAddr.sin_family = AF_INET;   
            srvAddr.sin_port = htons(port);
        srvAddr.sin_addr.s_addr = INADDR_ANY;   

            if (bind (sockFd, (struct sockaddr *) &srvAddr, sizeof(srvAddr)) < 0)   
                {   
                close(sockFd);
        error("Bind failed");   
                }   

            FOREVER   
                {   
                if (recvfrom (sockFd, (char*) &val, sizeof(val), 0,   
                         (struct sockaddr *) &clientAddr,   
                         &clientAddrLength) < 0)   
                    {   
                    close(sockFd);
        error("recvfrom failed");   
                    }   

                val = ntohl(val);
        inet_ntoa_b(clientAddr.sin_addr, inetAddr);
        clientPort = ntohl(clientAddr.sin_port);

        printf("Message received from client "    
                             "(port = %d, inet = %s):\n",
                     clientPort, inetAddr);
        printf("%d\n", val);   

                if (sendto (sockFd, reply, strlen(reply) + 1,   
                             0,(struct sockaddr *) &clientAddr,   
                             clientAddrLength) < 0)   
                    {   
                    close(sockFd);
        error("sendto failed");   
                    }   
                }   
            }   


        void error(char* str)
        {
            perror(str);
            exit(1);
        }
c vxworks
1个回答
1
投票

这些天,我对VxWorks Helix的了解比以前的VxWorks653更熟悉,但是您是否检查了INCLUDE_SOCKLIB组件已添加到项目中,还是SOCKET层已添加到VSB中?

通常,当发生链接器错误(如您描述的错误)时,项目中缺少组件和/或VSB中缺少层。

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