Compiling problem

This forum is for topics specific to the Raspberry Pi and Arch Linux ARM

Compiling problem

Postby Fzero » Mon Nov 26, 2012 3:36 pm

Sup, guys

I'm trying to compile this code:

$this->bbcode_second_pass_code('', '
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/ioctl.h>
#include <pthread.h>

void* Servidor(void* arg)
{
char buffer_cliente[256];
int sockEntrada = *(int *) arg;
printf("Aguardando comandos....");
while(1) {
//lê o buffer que vem no cliente
read(sockEntrada, buffer_cliente, sizeof (buffer_cliente));
if (strcmp(buffer_cliente, "sair") != 0)
{
printf("%s\n", buffer_cliente);
}
else
{
close(sockEntrada);
pthread_exit((void*) 0);
}
}//if
}//função

int configura(){
int sockfd;
struct sockaddr_in serverAddr;
if ((sockfd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) <0)
{
memset(&serverAddr, 0, sizeof (serverAddr));
serverAddr.sin_family = AF_INET;
serverAddr.sin_addr.s_addr = htonl(INADDR_ANY);
serverAddr.sin_port = htons(271);
if (bind(sockfd, (struct sockaddr *) & serverAddr, sizeof (serverAddr)) < 0);
{ printf("Erro no socket\n");
exit(1);
}
if (listen(sockfd, 5) <0 )
{ printf("Erro no socket\n");
exit(1);
}
return sockfd;
}


int main(void){
struct sockaddr_in serverAddr;
int sockfd = configura();

while(1){
int clienteSockfd;
struct sockaddr_in clienteAddr;
unsigned int clntLen;
clntLen = sizeof (clienteAddr);
//Thread
pthread_t thread;
if ((clienteSockfd = accept(sockfd, (struct sockaddr *) &clienteAddr, &clntLen)) < 0)
{ printf("Erro no Socket\n");
exit(1);
}
if(pthread_create(&thread, NULL, Servidor, &clienteSockfd) != 0)
{
printf("Erro na Thread\n");
exit(1);
}
pthread_detach(thread);
}
exit(0);
}
return(0);
}

')

with this command:

gcc -lpthread -o servidor servidor.c

But I'm getting this error:

$this->bbcode_second_pass_code('', '/usr/lib/gcc/armv6l-unknown-linux-gnueabihf/4.7.2/../../../crt1.o: In function `_start':
:(.text+0x34): undefined reference to `main'
collect2: error: ld returned 1 exit status')

I've searched on the internet about this specific error, but all I found was problems about don't using a 'main' function, but I'm using.

Does anybody knows what to do?

Thanks!
Fzero
 
Posts: 1
Joined: Mon Nov 26, 2012 3:22 pm

Re: Compiling problem

Postby karog » Mon Nov 26, 2012 9:43 pm

It is probably because your main has the wrong signature. Try
$this->bbcode_second_pass_code('', '
int main(int argc, char* argv[])')
karog
 
Posts: 305
Joined: Thu Jan 05, 2012 7:55 pm


Return to Raspberry Pi

Who is online

Users browsing this forum: No registered users and 11 guests