LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   NS2 Simulator (https://www.linuxquestions.org/questions/linux-software-2/ns2-simulator-901216/)

raji27 09-05-2011 07:49 AM

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

knudfl 09-05-2011 01:32 PM

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'.

..

jschiwal 09-12-2011 01:17 AM

Moved: This thread is more suitable in Linux Software and has been moved accordingly to help your thread/question get the exposure it deserves.

NimeshaK 03-28-2012 09:35 AM

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.

knudfl 03-28-2012 09:53 AM

# 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

.

NimeshaK 03-28-2012 11:20 AM

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

knudfl 03-28-2012 01:13 PM

# 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.

.

NimeshaK 03-28-2012 03:05 PM

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

Thank you so much


All times are GMT -5. The time now is 09:49 AM.