-1

I have begun to make a network simulation using ns-3.39. However, after installation, I met a problem to run a simulation. When I try to run first.cc in the tutorial folder, the terminal displays:

./first.cc: line 1: /bin: Is a directory
./first.cc: line 2: CMakeLists.txt: command not found
...
./first.cc: line 11: CMakeLists.txt: command not found
./first.cc: line 31: syntax error near unexpected token '"FirstScriptExample"'
./first.cc: line 31: 'NS_LOG_COMPONENT_DEFINE("FirstScriptExample");'

and then expires the code.

I checked every folder of ns3 but there exists 'CMakeLists.txt' file in the every folder. And I followed the process to 4.3.2 in the link below: https://www.nsnam.org/docs/manual/html/working-with-cmake.html

But nothing changed.

Alan Birtles
  • 32,622
  • 4
  • 31
  • 60
PSH
  • 1
  • how are you running `first.cc`? – Alan Birtles Jul 20 '23 at 07:04
  • I run the file using terminal. Speciffically, I run the file by these commands: ```cd ./ns-allinone-3.39/ns-3.39/examples/tutorial ./first.cc``` – PSH Jul 20 '23 at 07:13
  • @PSH It's a C++ source code, you shouldn't run it directly. ".cc" one of the C++ source file extension like ".cpp" or ".cxx". – cpprust Jul 20 '23 at 07:22
  • you need to run cmake, build the resulting project then run the executable, see the instructions in the webpage you linked to – Alan Birtles Jul 20 '23 at 08:08

1 Answers1

1

The "ns-allinone-3.39/ns-3.39/examples/tutorial/first.cc" you mentioned is C++ source code, not a script or executable, so you can't run it directly in terminal.

C++ source code can end with many kinds of extension, e.g. .cpp, .cc, .cxx (ref), and header end with .h, .hpp, etc. They are just text files and have to be compile to binary before you run it.

Install from apt

If you just want to use the program.

  • Run sudo apt install ns3 to install.

  • Run dpkg -L ns3 to see what do the package installed, usually the executable is installed under "/usr/bin".

Build from source

If you want to build it from source:

  1. configure (follow tutorial 4.3.1.1.)
  • cd to "ns-allinone-3.39/ns-3.39" and run

./ns3 configure -d release --enable-examples --enable-tests

This step create "cmake-cache" and "build" directory.

  1. build (found on "ns-allinone-3.39/ns-3.39/README.md")
./ns3

The examples are now living in the "ns-allinone-3.39/ns-3.39/build/examples".

Note

  • Many CMakeLists.txt: The developer put CMakeLists.txt in many directory is a common approach, check the link.

  • In Linux, usually executable have no extensions, and usually shell script have no extension or ".sh". (check the link for more information)

cpprust
  • 110
  • 4