UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Adventurer
Adventurer
494 Views
Registered: ‎03-22-2018

PetaLinux can't build when I add a socket C code that sets the IP Address but does compile when I don't set it

Jump to solution

Hi,

I'm trying to work with some communication projects and writed a C code for a server and another for a client. Initially, my server and client did not specify the IP address for the communication, leaving it as INADDR_ANY. I added both as apps for my PetaLinux and them both compiled and runned on my ZedBoard perfectly.

Now, I modified the client code to specify an IP address, but, even the code compiling normaly on my Ubuntu, it doesn't compiles when I run petalinux-build.

Here is my client.cpp

// Client side C/C++ program to demonstrate Socket programming 
#include <stdio.h> 
#include <sys/socket.h> 
#include <stdlib.h> 
#include <netinet/in.h> 
#include <string.h> 
#include <arpa/inet.h>
#include <unistd.h>
#define PORT 8080 

int main(int argc, char const *argv[]) 
{ 
	struct sockaddr_in address; 
	int sock = 0, valread; 
	struct sockaddr_in serv_addr; 
	char *hello = "Hello from client"; 
	char buffer[1024] = {0}; 
	if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) 
	{ 
		printf("\n Socket creation error \n"); 
		return -1; 
	} 

	memset(&serv_addr, '0', sizeof(serv_addr)); 

	serv_addr.sin_family = AF_INET; 
	serv_addr.sin_port = htons(PORT); 
	serv_addr.sin_addr.s_addr = inet_addr("192.168.0.200");
	
	// Convert IPv4 and IPv6 addresses from text to binary form 
	if(inet_pton(AF_INET, "127.0.0.1", &serv_addr.sin_addr)<=0) 
	{ 
		printf("\nInvalid address/ Address not supported \n"); 
		return -1; 
	} 

	if (connect(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) 
	{ 
		printf("\nConnection Failed \n"); 
		return -1; 
	} 
	send(sock , hello , strlen(hello) , 0 ); 
	printf("Hello message sent\n"); 
	valread = read( sock , buffer, 1024); 
	printf("%s\n",buffer ); 
	return 0; 
} 

If I remove the line <serv_addr.sin_addr.s_addr = inet_addr("192.168.0.200");/> it compiles and runs normally.

The error I get is simillar to the following:Screenshot from 2019-03-17 11-32-11.png

 

I'm trying the figure out why it's happening. Can you helpe me?

Thanks in advance,

Tiago

0 Kudos
1 Solution

Accepted Solutions
Moderator
Moderator
432 Views
Registered: ‎09-12-2007

Re: PetaLinux can't build when I add a socket C code that sets the IP Address but does compile when I don't set it

Jump to solution

For the first issue:

"No rule to make target clean"

Can you update the makefile in 

project-spec\meta-user\recipes-apps\<app name>

clean:
    -rm -f $(APP) *.elf *.gdb *.o $(APP_OBJS)

 

Also, if you are suing sockets you would need to add the pthreads to the make file

LDLIBS += -lpthread

 

View solution in original post

2 Replies
Moderator
Moderator
433 Views
Registered: ‎09-12-2007

Re: PetaLinux can't build when I add a socket C code that sets the IP Address but does compile when I don't set it

Jump to solution

For the first issue:

"No rule to make target clean"

Can you update the makefile in 

project-spec\meta-user\recipes-apps\<app name>

clean:
    -rm -f $(APP) *.elf *.gdb *.o $(APP_OBJS)

 

Also, if you are suing sockets you would need to add the pthreads to the make file

LDLIBS += -lpthread

 

View solution in original post

Adventurer
Adventurer
407 Views
Registered: ‎03-22-2018

Re: PetaLinux can't build when I add a socket C code that sets the IP Address but does compile when I don't set it

Jump to solution
It worked! Thanks
0 Kudos