LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices



Reply
 
Search this Thread
Old 09-05-2011, 08:49 AM   #1
raji27
LQ Newbie
 
Registered: Sep 2011
Posts: 13

Rep: Reputation: Disabled
NS2 Simulator


Hi, I'm doing a project in ad hoc, in NS2 for simultaion.I need help in simulating C++ codes. Can u say me how to run c++ files using NS2
 
Old 09-05-2011, 02:32 PM   #2
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen, DK
Distribution: pclos2014.08, Slack14.1 DebWheezy, +50+ other Linux OS, for test only.
Posts: 14,279

Rep: Reputation: 2664Reputation: 2664Reputation: 2664Reputation: 2664Reputation: 2664Reputation: 2664Reputation: 2664Reputation: 2664Reputation: 2664Reputation: 2664Reputation: 2664
cd ns-allinone-2.34/ns-2.34/ && cp Makefile Makefile-new
&& cp ns ns.orig && make clean

Assume test.cc : Add test.o to 'Makefile-new', line 330. ( Section OBJ_CC ).

Then run 'make -f Makefile-new' in ns-allinone-2.34/ns-2.34/,
and your code will be compiled into the new 'ns'.

..

Last edited by knudfl; 09-10-2011 at 06:52 AM.
 
1 members found this post helpful.
Old 09-12-2011, 02:17 AM   #3
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655
Moved: This thread is more suitable in Linux Software and has been moved accordingly to help your thread/question get the exposure it deserves.
 
Old 03-28-2012, 10:35 AM   #4
NimeshaK
LQ Newbie
 
Registered: Mar 2012
Posts: 8

Rep: Reputation: Disabled
ns-2

hi,
I changed ns-2 according to the below command as u mentioned.
"cd ns-allinone-2.34/ns-2.34/ && cp Makefile Makefile-new
&& cp ns ns.orig && make clean

Assume test.cc : Add test.o to 'Makefile-new', line 330. ( Section OBJ_CC ).

Then run 'make -f Makefile-new' in ns-allinone-2.34/ns-2.34/,
and your code will be compiled into the new 'ns'."

But yet,i cannot find a suitable way 2 complie & run C++ program in ns-2.Please help me.
 
Old 03-28-2012, 10:53 AM   #5
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen, DK
Distribution: pclos2014.08, Slack14.1 DebWheezy, +50+ other Linux OS, for test only.
Posts: 14,279

Rep: Reputation: 2664Reputation: 2664Reputation: 2664Reputation: 2664Reputation: 2664Reputation: 2664Reputation: 2664Reputation: 2664Reputation: 2664Reputation: 2664Reputation: 2664
# 4

You cannot run a c++ program in ns2.

When your new object is compiled into a new binary ns,
you can write e.g. a tcl file, that use the new function.
And run that file : ./ns file.tcl


If you have problems with compiling, please specify your errors.
And : Tell which Linux OS, you are using. Like CentOS 6, Fedora 16.
Which g++ compiler is used ? ?
http://www.linuxquestions.org/linux/...Ask_a_Question
http://linuxsilo.net/docs/smart-questions_en.html

.
 
Old 03-28-2012, 12:20 PM   #6
NimeshaK
LQ Newbie
 
Registered: Mar 2012
Posts: 8

Rep: Reputation: Disabled
ns-2

I can run ".tcl" files.But I can't run C++ programs.This is the program i want to run.

//sim.cc
main(){
float delay = 0, d_i = 1;
int i, num_nodes = 11;
for(i = 1; i < num_nodes; i++)
delay += d_i;
printf("Overall Packet Delay is %2.1f seconds.\n",
delay);
}
I save this as sim.cc.When I give the command to compile "gcc -o sim.cc" ,I get this error."gcc: fatal error: no input files
compilation terminated.". What is the wrong in this program?

I am using Fedora 14.and ns-2.35

Last edited by NimeshaK; 03-28-2012 at 12:23 PM.
 
Old 03-28-2012, 02:13 PM   #7
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen, DK
Distribution: pclos2014.08, Slack14.1 DebWheezy, +50+ other Linux OS, for test only.
Posts: 14,279

Rep: Reputation: 2664Reputation: 2664Reputation: 2664Reputation: 2664Reputation: 2664Reputation: 2664Reputation: 2664Reputation: 2664Reputation: 2664Reputation: 2664Reputation: 2664
# 6 . First : Use CODE tags for code.
Write [/code] at code end, and [code] at code start.
Or use the # button in the 'Advanced Editor'.
http://www.linuxquestions.org/questi....php?do=bbcode
Please edit post # 6 : code tags.
Quote:
gcc -o sim.cc
Wrong syntax, and not a c program. Use g++ for c++ programs.

g++ sim.cc -o sim : Should work ( If it wasn't an ns2 program.)

Short : There can only be one binary in ns2 : 'ns'
New files must be compiled into 'ns'. Ref. post # 2.
If you don't, you will miss "the 300 functions" that make up the simulation.

.

Last edited by knudfl; 03-28-2012 at 02:17 PM.
 
Old 03-28-2012, 04:05 PM   #8
NimeshaK
LQ Newbie
 
Registered: Mar 2012
Posts: 8

Rep: Reputation: Disabled
Smile ns-2

I compiled my program with "g++ sim.cc -o sim" command.
It worked well!!

Thank you so much

Last edited by NimeshaK; 03-28-2012 at 04:30 PM.
 
  


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
Any network simulator 2 (ns2) experts around? Titanas25 Programming 1 06-12-2012 07:24 AM
ns2- network simulator problem vivekr Linux - Networking 5 02-16-2011 01:25 PM
NS2 simulator to work with Rocketfuel Topology itwitter Linux - Virtualization and Cloud 2 02-05-2011 04:15 AM
How to install NS2 simulator(version 2.29) in Fedora 7. mrbhush General 1 05-06-2009 02:41 AM
NS2 - network simulator liquid.o Linux - Networking 0 11-24-2006 11:36 AM


All times are GMT -5. The time now is 12:55 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration