This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler/CCSTUDIO: How to compile one single source file?

Part Number: CCSTUDIO

Tool/software: TI C/C++ Compiler

Hi, there. As title, How to compile one single source file?

I only found a option "Build Selected File(s)", but didn't response anything after clicking it.

https://imgur.com/a/TnV6E5S

I want to compile file sockets.c, but nothing happened after clicking it.

Why I want to compile sockets.c? Because I found a weird thing.

At second image, I can't locate right bracket of function lwip_sendto by right clicking left bracket of it.

I started to debug this function and found that there is a superfluous left bracket at line 40.(Could line number show up before posting?)

int
lwip_sendto(int s, const void *data, size_t size, int flags,
       const struct sockaddr *to, socklen_t tolen)
{
  struct lwip_sock *sock;
  err_t err;
  u16_t short_size;
  const struct sockaddr_in *to_in;
  u16_t remote_port;
#if !LWIP_TCPIP_CORE_LOCKING
  struct netbuf buf;
#endif

  sock = get_socket(s);
  if (!sock) {
    return -1;
  }

  if (sock->conn->type == NETCONN_TCP) {
#if LWIP_TCP
    return lwip_send(s, data, size, flags);
#else /* LWIP_TCP */
    LWIP_UNUSED_ARG(flags);
    sock_set_errno(sock, err_to_errno(ERR_ARG));
    return -1;
#endif /* LWIP_TCP */
  }

  /* @todo: split into multiple sendto's? */
  LWIP_ASSERT("lwip_sendto: size must fit in u16_t", size <= 0xffff);
  short_size = (u16_t)size;
  LWIP_ERROR("lwip_sendto: invalid address", (((to == NULL) && (tolen == 0)) ||
             ((tolen == sizeof(struct sockaddr_in)) &&
             ((to->sa_family) == AF_INET) && ((((mem_ptr_t)to) % 4) == 0))),
             sock_set_errno(sock, err_to_errno(ERR_ARG)); return -1;);
  to_in = (const struct sockaddr_in *)(void*)to;

#if LWIP_TCPIP_CORE_LOCKING
  /* Should only be consider like a sample or a simple way to experiment this option (no check of "to" field...) */
  {
    struct pbuf* p;
    ip_addr_t *remote_addr;

#if LWIP_NETIF_TX_SINGLE_PBUF
    p = pbuf_alloc(PBUF_TRANSPORT, short_size, PBUF_RAM);
    if (p != NULL) {
#if LWIP_CHECKSUM_ON_COPY
      u16_t chksum = 0;
      if (sock->conn->type != NETCONN_RAW) {
        chksum = LWIP_CHKSUM_COPY(p->payload, data, short_size);
      } else
#endif /* LWIP_CHECKSUM_ON_COPY */
      MEMCPY(p->payload, data, size);
#else /* LWIP_NETIF_TX_SINGLE_PBUF */
    p = pbuf_alloc(PBUF_TRANSPORT, short_size, PBUF_REF);
    if (p != NULL) {
      p->payload = (void*)data;
#endif /* LWIP_NETIF_TX_SINGLE_PBUF */

      if (to_in != NULL) {
        inet_addr_to_ipaddr_p(remote_addr, &to_in->sin_addr);
        remote_port = ntohs(to_in->sin_port);
      } else {
        remote_addr = &sock->conn->pcb.raw->remote_ip;
        if (sock->conn->type == NETCONN_RAW) {
          remote_port = 0;
        } else {
          remote_port = sock->conn->pcb.udp->remote_port;
        }
      }

      LOCK_TCPIP_CORE();
      if (sock->conn->type == NETCONN_RAW) {
        err = sock->conn->last_err = raw_sendto(sock->conn->pcb.raw, p, remote_addr);
      } else {
#if LWIP_UDP
#if LWIP_CHECKSUM_ON_COPY && LWIP_NETIF_TX_SINGLE_PBUF
        err = sock->conn->last_err = udp_sendto_chksum(sock->conn->pcb.udp, p,
          remote_addr, remote_port, 1, chksum);
#else /* LWIP_CHECKSUM_ON_COPY && LWIP_NETIF_TX_SINGLE_PBUF */
        err = sock->conn->last_err = udp_sendto(sock->conn->pcb.udp, p,
          remote_addr, remote_port);
#endif /* LWIP_CHECKSUM_ON_COPY && LWIP_NETIF_TX_SINGLE_PBUF */
#else /* LWIP_UDP */
        err = ERR_ARG;
#endif /* LWIP_UDP */
      }
      UNLOCK_TCPIP_CORE();
      
      pbuf_free(p);
    } else {
      err = ERR_MEM;
    }
  }
#else /* LWIP_TCPIP_CORE_LOCKING */
  /* initialize a buffer */
  buf.p = buf.ptr = NULL;
#if LWIP_CHECKSUM_ON_COPY
  buf.flags = 0;
#endif /* LWIP_CHECKSUM_ON_COPY */
  if (to) {
    inet_addr_to_ipaddr(&buf.addr, &to_in->sin_addr);
    remote_port           = ntohs(to_in->sin_port);
    netbuf_fromport(&buf) = remote_port;
  } else {
    remote_port           = 0;
    ip_addr_set_any(&buf.addr);
    netbuf_fromport(&buf) = 0;
  }

  LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_sendto(%d, data=%p, short_size=%"U16_F", flags=0x%x to=",
              s, data, short_size, flags));
  ip_addr_debug_print(SOCKETS_DEBUG, &buf.addr);
  LWIP_DEBUGF(SOCKETS_DEBUG, (" port=%"U16_F"\n", remote_port));

  /* make the buffer point to the data that should be sent */
#if LWIP_NETIF_TX_SINGLE_PBUF
  /* Allocate a new netbuf and copy the data into it. */
  if (netbuf_alloc(&buf, short_size) == NULL) {
    err = ERR_MEM;
  } else {
#if LWIP_CHECKSUM_ON_COPY
    if (sock->conn->type != NETCONN_RAW) {
      u16_t chksum = LWIP_CHKSUM_COPY(buf.p->payload, data, short_size);
      netbuf_set_chksum(&buf, chksum);
      err = ERR_OK;
    } else
#endif /* LWIP_CHECKSUM_ON_COPY */
    {
      err = netbuf_take(&buf, data, short_size);
    }
  }
#else /* LWIP_NETIF_TX_SINGLE_PBUF */
  err = netbuf_ref(&buf, data, short_size);
#endif /* LWIP_NETIF_TX_SINGLE_PBUF */
  if (err == ERR_OK) {
    /* send the data */
    err = netconn_send(sock->conn, &buf);
  }

  /* deallocated the buffer */
  netbuf_free(&buf);
#endif /* LWIP_TCPIP_CORE_LOCKING */
  sock_set_errno(sock, err_to_errno(err));
  return (err == ERR_OK ? short_size : -1);
}

With extra left bracket, I have no idea that why my library(including this sockets.c source file)is compiled successfully.

So I want to standalone this one and compile it.

Thank you.

  • Andy Lin94 said:
    I only found a option "Build Selected File(s)",

    That is the correct one to use.

    Andy Lin94 said:
    but nothing happened after clicking it.

    I don't know why that would be. I see that you are in the CCS Debug perspective but that should not matter. But just to make sure, could you terminate your debug session or go back manually to the CCS Edit perspective and then try building the selected file. 

    Finally you could try cleaning your environment (in case of any corruption) using the suggestions in the General IDE section of this page.

    Hope this helps.

  • Thanks for your reply.
    I noticed that except project "lwip-1.4.0", I can build other projects.
    Because I can't build project lwip-1.4.0, I can't build single file in lwip-1.4.0 as well and this is not the matter of perspective view and debug session.

    an other weird thing is
    I search "size_t" within the whole workspace(ctrl+shift+f) and find no any original reference, but the project LWIPlib is built successfully....(Project LWIPlib is a library which including file sockets.c, and sockets.c also has size_t within it )

    please help
  • Andy Lin94 said:
    I search "size_t" within the whole workspace(ctrl+shift+f) and find no any original reference, but the project LWIPlib is built successfully....(Project LWIPlib is a library which including file sockets.c, and sockets.c also has size_t within it )

    Do you mean that it does not find any reference to size_t in any of the source files in the workspace even though there are references to it in a source file? If so, I can't explain why this would be without a reproducible test case. If you are able to share a test case we could look into it.

  • Since we haven’t received a reproducible test case, I’m assuming you were able to move past this issue or it is no longer relevant. If that is not the case, please feel free to post a reply with an update and test case. Thanks!
  • Yes, it's not an emergency as long as program can still run.
    What action can I take if I think the issue that I post is no longer relevant next time?
  • Andy Lin94 said:
    What action can I take if I think the issue that I post is no longer relevant next time?

    You could just post a reply saying the issue is no longer relevant, and/or if the issue is resolved mark the thread as "Answered".