LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer
User Name
Password
Linux - Embedded & Single-board computer This forum is for the discussion of Linux on both embedded devices and single-board computers (such as the Raspberry Pi, BeagleBoard and PandaBoard). Discussions involving Arduino, plug computers and other micro-controller like devices are also welcome.

Notices


Reply
  Search this Thread
Old 09-14-2012, 12:00 AM   #1
Pankajgoyal38
LQ Newbie
 
Registered: Sep 2012
Posts: 9

Rep: Reputation: Disabled
Red face Ldflags


I am having problem with LDFALGS. how can i set these variables. I am getting a prob with Makefile also. If i am compiling my source file with cc than its working fine. but If i am doing this with Makefile than it says like "Fatal Error:stdio.h (all other also as i've tried) are not found".

what should i do???
please help...
 
Old 09-14-2012, 12:40 AM   #2
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,726

Rep: Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706
Hi,

sounds like your Makefile is a bit of a mess. If you post it here we might be able to help.

Evo2.
 
Old 09-14-2012, 01:06 AM   #3
Pankajgoyal38
LQ Newbie
 
Registered: Sep 2012
Posts: 9

Original Poster
Rep: Reputation: Disabled
MakeFile

Thanks for this early relpy..
Please tell me difference b/w Linux Drivers makefile and Linux system prgrming make file
I have created a UDP socket. Having one client and one server in one directory. and including header file is in another directory.
like
in include (mt_include.h)
in source (server.c and client.c)

Now how to make a Makefile
my make file is like

all: multithread
LDFLAGS += -lpthread
multithread: server.c client.c
$(cc) $^ $(LDFLAGS) -o $@
#server:server.o
#client:client.o
 
Old 09-14-2012, 01:32 AM   #4
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,726

Rep: Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706
Hi,

can you show me how you would compile this manually?

Evo2.
 
Old 09-14-2012, 01:58 AM   #5
Pankajgoyal38
LQ Newbie
 
Registered: Sep 2012
Posts: 9

Original Poster
Rep: Reputation: Disabled
MakeFile

I can compile them on different tty. one server and client on another terminal. using
cc server.c
and
cc client.c
 
Old 09-14-2012, 02:27 AM   #6
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,726

Rep: Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706
Hi,

so you don't actually want to link pthread?

Evo2.
 
Old 09-14-2012, 03:26 AM   #7
Pankajgoyal38
LQ Newbie
 
Registered: Sep 2012
Posts: 9

Original Poster
Rep: Reputation: Disabled
hey,
no no no ...
its not like that...i have to link them..using -lpthread.
actually i forgot to write that.
 
Old 09-17-2012, 08:42 PM   #8
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,726

Rep: Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706
Hi,

you say you've been able to get this to compile on the command line but you are having trouble with the Makefile. Since you have not provided with the code or the procedure for compiling on the command line I'd just be guessing if I tried to tell you what to put in your Makefile.

Evo2.

PS. This is begging to look like a homework problem.
 
Old 09-17-2012, 10:13 PM   #9
Pankajgoyal38
LQ Newbie
 
Registered: Sep 2012
Posts: 9

Original Poster
Rep: Reputation: Disabled
hahaha...yaa..
u can think like a homework problem. actually i am with Torres Network. Handling a dummy project I need to do all these things.
thats why.
but don't worry...i have resolved it now.
I have made a Makefile.
Both server and client source file are there. but i will not give them a combine name. ".o" file will be created and then i will execute them on different terminal.
by d way..thanks for your response. really..thanks again.
my Name is Pankaj Goyal and Basically I am fresher engineering graduate hired in this company for UNIX system Programming and Network Device Driver.
 
Old 09-17-2012, 11:21 PM   #10
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,726

Rep: Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706Reputation: 1706
Hi,

glad you were able to get this working. See you around LQ.

Cheers,

Evo2.
 
Old 09-18-2012, 12:39 AM   #11
Pankajgoyal38
LQ Newbie
 
Registered: Sep 2012
Posts: 9

Original Poster
Rep: Reputation: Disabled
hi..it will be very nice..can u plz explain me something abt thread affinity.
my server code is:-


//////////////////////////////////////////////////////////////////////////////////////////////
//This file's code is serving as SERVER for Multi Threading Programe. Its having two threads//
//data is transferring from main thread to thread1 and then from thread1 to thread2. For //
//fulfilling the purpose of data transferring we are using shared memory. For communicating //
//between two process we are using UDP server. And whichever packet client is sending will //
//be saved to shared memory and used afterwards. //
// //
/////////////////////////////////////////////////////////////////////////////////////////////


#include "/home/torres/Desktop/Pankaj_Exercises/multi_thread/trial_multithread/include/mt_include.h"
int main()
{
cpu_set_t cpuset1;
int i;
key=2;
cl_size=sizeof(struct sockaddr_in);
server.sin_family=AF_INET; //setting server attributes
server.sin_port=htons(7000);
//server.sin_addr.s_addr=inet_addr("127.0.0.1");
server.sin_addr.s_addr=INADDR_ANY;

//printf("in Server\n");

//creating shared memory//

shmid=shmget(key, 40, IPC_CREAT|0666); //Allocating shared memory of 40 bytes.
if(shmid==-1) //shmget returns -1 on failure and zero on success
{
syslog(PRI, "Error in creatin Shared Memory at server side\n");
exit(EXIT_FAILURE);
}
else
{
ptr=(char*)shmat(shmid,NULL,0); //shared memory is pointing by pointer ptr which is a char pointer
syslog(PRI,"Shared Memory is created with %d id\n", shmid);
}

//creating socket//

sockid=socket(AF_INET, SOCK_DGRAM, 0); //an UDP socket is created.
if(sockid==-1) //socket function also returns -1 on failure and socket id on success
{
syslog(PRI,"Problem in creating a socket at server side\n");
exit(EXIT_FAILURE);
}
else
{
int b=bind(sockid, (struct sockaddr*)&server, sizeof(server)); //binding to socket id
if(b==-1)
{
syslog(PRI, "SERVER:Problem with Binding\n");
exit(EXIT_FAILURE);
}
else
{
syslog(PRI, "Socket bounded with local address\n");
printf("Press ! Ctrl+C to disconnect\n");
while(1)
{
ret=recvfrom(sockid, ptr, 40, 0, (struct sockaddr*)&client, &cl_size); //receiving from client
if(ret==-1)
{
syslog(PRI, "Server not receiving\n");
exit(EXIT_FAILURE);
}
else
{
CPU_SET(0,&cpuset1);
pthread_create(&PID1, NULL, thread1, ptr); //creating thread with PID1 and function thread1
pthread_setaffinity_np(PID1, sizeof(cpuset1), &cpuset1);
pthread_join(PID1,(void**)&s); //joining of thread1
}
}


}
}
shmdt(ptr); //detaching the shared memory
return 0; //returning

}
void * thread1(void *data)
{
cpu_set_t cpuset2;
int end, *status;
CPU_SET(1,&cpuset2);
syslog(PRI,"Message from client=%s\n",data);
printf("Message from client :- %s\n", data);
pthread_create(&PID2, NULL, thread2, data);
pthread_setaffinity_np(PID2, sizeof(cpuset2), &cpuset2);
pthread_getaffinity_np(PID2, sizeof(cpuset2), &cpuset2);
printf("affinity=%d\n",cpuset2);
while(1)
{
pthread_join(PID2, (void**)&status); //joining thread 2
}
pthread_exit(&end); //exiting from thread1
}
void * thread2(void *data)
{
int bye;
printf("Message to Client :- ", exBuff);
fflush(stdin); //flushing the input buffer
fgets(send_message,sizeof(send_message),stdin);
strcpy(data,send_message);
sendto(sockid, data, 40, 0, (struct sockaddr*)&client, sizeof(client)); //sending data to client
syslog(PRI, "Message to Client=%s\n",data);
pthread_exit(&bye);
}


client code is :


////////////////////////////////////////-----client.c---//////////////////////////////////////////
// This file's code is serving as a client for our programme. Communication will be started by //
// the client only. First it will send data through shared memory using UDP socket. Then after //
// it will receive by server. This client-server will execute synchronously on different tty's //
// ///////////////////////////////////////////////////////////////////////////////////////////////


#include "/home/torres/Desktop/Pankaj_Exercises/multi_thread/trial_multithread/include/mt_include.h"
int main()
{
int i;
key=2;
cl_size=sizeof(struct sockaddr_in);
pthread_t PID1, PID2; //PID1 and PID2 are thread id's
server.sin_family=AF_INET;
server.sin_port=htons(7000);
server.sin_addr.s_addr=INADDR_ANY;
client.sin_family=AF_INET; //setting client and server attributes
client.sin_port=htons(8000); //htons=host to network short
client.sin_addr.s_addr=INADDR_ANY; //AF_INET used for domain. like internet ipv4
//inet_addr converts into binary format

//creating shared memory//

shmid=shmget(key, 40, IPC_CREAT|0666); //creating shared memory with same key so that client also can user this.
if(shmid==-1)
{
syslog(PRI, "Error in creating Shared Memory at client section\n");
exit(EXIT_FAILURE);
}
else
{

ptr=(char*)shmat(shmid,NULL,0); //accessing shared memory with rd/wr mode.
syslog(PRI, "Shared Memory is Created in client with %d id\n", shmid);
}

//creating socket//

cl_sockid=socket(AF_INET, SOCK_DGRAM, 0); //an UDP socket is creating at client side with cl_sockid is the socket id
if(cl_sockid==-1)
{

syslog(PRI,"Problem in Creating a socket at client side\n");
exit(EXIT_FAILURE);
}
else
{
syslog(PRI, "Socket is created in client\n");
int b=bind(cl_sockid, (const struct sockaddr*)&client, sizeof(client)); //binding to socket
if(b==-1)
{
syslog(PRI, "Problem with bind in client\n");
exit(EXIT_FAILURE);
}
else
{
while(1) //loop will be continued till ctrl+C
{
printf(" Message to server :- ");
fflush(stdin);
fgets(send_message,sizeof(send_message), stdin);
strcpy(ptr, send_message);
ret=sendto(cl_sockid, ptr, 40, 0, (struct sockaddr*)&server, sizeof(server));
if(ret==-1)
{
syslog(PRI, "Server Not Receiving\n");
exit(EXIT_FAILURE);
}
else
{
syslog(PRI, "Message to server=%s\n",ptr);
recvfrom(cl_sockid, ptr, 40, 0, (struct sockaddr*)&server, &serv_size);
printf("Message from Server :- %s",ptr);
}
}


}
}
return 0; //returning

}
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Fedora 13 - LDFLAGS AlvaroG Fedora 8 07-22-2010 03:50 PM
CFLAGS and LDFLAGS configuration problem vofka Linux - General 3 11-06-2009 04:28 PM
CFLAGS and LDFLAGS question versaulis Linux - Software 1 11-07-2008 11:33 AM
What are LDFLAGS and AM_LDFLAGS!? wimnat Linux - Software 2 11-21-2005 04:08 AM
how to use LDFLAGS while running ./configure Kilahchris Linux - Newbie 1 08-27-2004 10:12 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware > Linux - Embedded & Single-board computer

All times are GMT -5. The time now is 10:45 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration