Linux Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsOperating SystemsLinux Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 30th, 2012, 06:38 AM
kannan_pmk kannan_pmk is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2011
Posts: 9 kannan_pmk User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 37 m
Reputation Power: 0
Compilation

Hi,
I am facing problem in Compilation,I don't know how to compile properly in Linux

This is my .c file which will create a.out file

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <dlfcn.h>
int main()
{
void* hdll;
typedef int (*Hello)();
Hello fnpHello;


hdll = dlopen("/home/local/Desktop/Simulation/TCP/Sample.so",RTLD_NOW);

if(hdll != NULL)
{
printf("Sample.so is Loaded ya\n");
fnpHello = dlsym(hdll, "Hello");
fnpHello();
}
else

printf("TCP DLL is not Loaded ya\n");

return 1;
}


The above program will call the Sample.c


# include <stdio.h>

# include <stdlib.h>

# include <string.h>

#include <dlfcn.h>



/* for windows */

typedef int (*fnSimulateTCP)();

fnSimulateTCP fnpointer;

int Hello()

{

void *hdll = NULL;

hdll = dlopen("/home/local/Desktop/Simulation/TCP/Sample1.so",RTLD_NOW);

if (hdll != NULL)

{

printf("Sample 1 is Loaded Successfully\n");

fnpointer = dlsym(hdll, "fnSimulateTCP");

fnpointer();

}

return 0;



}


The above program will call further Sample1.c

# include <stdio.h>
# include <stdlib.h>
# include <string.h>

/* for windows */

int fnSimulateTCP()
{

printf("hello world\n");
return 0;

}





I am not getting the Correct output.

Reply With Quote
  #2  
Old April 30th, 2012, 07:03 AM
JClasen JClasen is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Jun 2007
Posts: 1,513 JClasen User rank is General 7th Grade (Above 100000 Reputation Level)JClasen User rank is General 7th Grade (Above 100000 Reputation Level)JClasen User rank is General 7th Grade (Above 100000 Reputation Level)JClasen User rank is General 7th Grade (Above 100000 Reputation Level)JClasen User rank is General 7th Grade (Above 100000 Reputation Level)JClasen User rank is General 7th Grade (Above 100000 Reputation Level)JClasen User rank is General 7th Grade (Above 100000 Reputation Level)JClasen User rank is General 7th Grade (Above 100000 Reputation Level)JClasen User rank is General 7th Grade (Above 100000 Reputation Level)JClasen User rank is General 7th Grade (Above 100000 Reputation Level)JClasen User rank is General 7th Grade (Above 100000 Reputation Level)JClasen User rank is General 7th Grade (Above 100000 Reputation Level)JClasen User rank is General 7th Grade (Above 100000 Reputation Level)JClasen User rank is General 7th Grade (Above 100000 Reputation Level)JClasen User rank is General 7th Grade (Above 100000 Reputation Level)JClasen User rank is General 7th Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Weeks 5 Days 7 h 10 m 22 sec
Reputation Power: 1422
First of all, please use code or highlight tags, when posting source code in this forum.

Furthermore, please post your previous attempts and describe your results. Just posting your source code will typically not yield your intended results. With a "question" like yours, I could reply with a "works flawlessly here" and you would not be any whiser.

That said, it does work flawlessly here:

Code:
user@host ~/path $ gcc -c -fPIC Sample.c -o Sample.o
user@host ~/path $ gcc -c -fPIC Sample1.c -o Sample1.o
user@host ~/path $ gcc -shared -Wl,-soname,Sample.so -o Sample.so Sample.o 
user@host ~/path $ gcc -shared -Wl,-soname,Sample1.so -o Sample1.so Sample1.o 
user@host ~/path $ gcc -Wall -rdynamic main.c -ldl -o main
user@host ~/path $ ./main 
Sample.so is Loaded ya
Sample 1 is Loaded Successfully
hello world


Regards, Jens

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsLinux Help > Compilation

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap