Неопределенная ссылка на «Socket» в платформе VxWorks - PullRequest
0 голосов
/ 21 апреля 2020

Я работаю с платформой 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);
        }

1 Ответ

1 голос
/ 21 апреля 2020

В наши дни я больше знаком с VxWorks Helix, чем с более старым VxWorks 653, но проверяли ли вы, что компонент INCLUDE_SOCKLIB был добавлен в ваш проект или слой SOCKET добавлен в VSB?

Обычно в случае ошибки компоновщика, такой как описанная вами, в вашем проекте отсутствует компонент, и / или в VSB отсутствует слой.

...