cross compiling a c program for imx6

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

cross compiling a c program for imx6

3,781 Views
sameerarvikar
Contributor III

Hello,

I am trying to cross compile following c (tcp socket server)program for imx6

using following command

arm-poky-linux-gnueabi-gcc tcpserver.c --sysroot=/opt/fsl-imx-x11/4.1.15-2.0.1/sysroots/cortexa9hf-neon-poky-linux-gnueabi/usr/lib -o server_tcp -I/opt/fsl-imx-x11/4.1.15-2.0.1/sysroots/cortexa9hf-neon-poky-linux-gnueabi/usr/include

I have include -I option cause error was coming stdio.h

Now error is coming

/opt/fsl-imx-x11/4.1.15-2.0.1/sysroots/cortexa9hf-neon-poky-linux-gnueabi/usr/include/gnu/stubs.h:7:29: fatal error: gnu/stubs-soft.h: No such file or directory

so i edited stubs.h

so it won't use stubs-soft.h

Now following error is coming

/opt/fsl-imx-x11/4.1.15-2.0.1/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/5.3.0/real-ld: cannot find crt1.o: No such file or directory
/opt/fsl-imx-x11/4.1.15-2.0.1/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/5.3.0/real-ld: cannot find crti.o: No such file or directory
/opt/fsl-imx-x11/4.1.15-2.0.1/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/5.3.0/real-ld: cannot find crtbegin.o: No such file or directory
/opt/fsl-imx-x11/4.1.15-2.0.1/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/5.3.0/real-ld: cannot find -lgcc
/opt/fsl-imx-x11/4.1.15-2.0.1/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/5.3.0/real-ld: cannot find -lgcc_s
/opt/fsl-imx-x11/4.1.15-2.0.1/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/5.3.0/real-ld: cannot find -lc
/opt/fsl-imx-x11/4.1.15-2.0.1/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/5.3.0/real-ld: cannot find -lgcc
/opt/fsl-imx-x11/4.1.15-2.0.1/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/5.3.0/real-ld: cannot find -lgcc_s
/opt/fsl-imx-x11/4.1.15-2.0.1/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/5.3.0/real-ld: cannot find crtend.o: No such file or directory
/opt/fsl-imx-x11/4.1.15-2.0.1/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/5.3.0/real-ld: cannot find crtn.o: No such file or directory
collect2: error: ld returned 1 exit status

how to solve the issue ,the program is compiling and running without problem in ubuntu(on pc)

tcpserver.c

/****************** SERVER CODE ****************/

#include <stdio.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <string.h>

int main(){
  int welcomeSocket, newSocket;
  char buffer[1024];
  struct sockaddr_in serverAddr;
  struct sockaddr_storage serverStorage;
  socklen_t addr_size;

  /*---- Create the socket. The three arguments are: ----*/
  /* 1) Internet domain 2) Stream socket 3) Default protocol (TCP in this case) */
  welcomeSocket = socket(PF_INET, SOCK_STREAM, 0);
 
  /*---- Configure settings of the server address struct ----*/
  /* Address family = Internet */
  serverAddr.sin_family = AF_INET;
  /* Set port number, using htons function to use proper byte order */
  serverAddr.sin_port = htons(7891);
  /* Set IP address to localhost */
  serverAddr.sin_addr.s_addr = inet_addr("127.0.0.1");
  /* Set all bits of the padding field to 0 */
  memset(serverAddr.sin_zero, '\0', sizeof serverAddr.sin_zero);  

  /*---- Bind the address struct to the socket ----*/
  bind(welcomeSocket, (struct sockaddr *) &serverAddr, sizeof(serverAddr));

  /*---- Listen on the socket, with 5 max connection requests queued ----*/
  if(listen(welcomeSocket,5)==0)
    printf("Listening\n");
  else
    printf("Error\n");

  /*---- Accept call creates a new socket for the incoming connection ----*/
  addr_size = sizeof serverStorage;
 
  int n = 0, k;
  char recvBuff[1024];
 while(1)
 {
  newSocket = accept(welcomeSocket, (struct sockaddr *) &serverStorage, &addr_size);
 /*---- Send message to the socket of the incoming connection ----*/
  strcpy(buffer,"Hello World\n");
  send(newSocket,buffer,13,0);
    n = recv(newSocket, recvBuff, 1023, 0);
     printf("Recd: %d bytes\n",n);
     printf("Data received: %s",recvBuff);
    /* printf("recvbuff --> %s  \n",recvBuff); */
  /*  for (k=0; k<16; ++k) { printf("%d: 0x%02s, ", k, recvBuff[k]); }

     sleep(1);*/
    printf("\n");
 }
 

  return 0;
}

Labels (2)
Tags (2)
0 Kudos
1 Reply

1,595 Views
gusarambula
NXP TechSupport
NXP TechSupport

Hello sameerarvikar,

This error may be related to the libraries not being found when cross-compiling. One alternative would be looking for the libraries on your gcc location and adding them to LIBRARY_PATH.

I would recommend looking at the following thread where they set a flag to point to where the target sysroot is, which allows the cross compiler to find the libraries:

https://community.nxp.com/thread/394804

Regards,

0 Kudos