英文:
ns3 running failure due to CMakeLists.txt
问题
我已经开始使用ns-3.39制作网络模拟。然而,在安装后,我遇到了运行模拟的问题。当我尝试在教程文件夹中运行first.cc时,终端显示:
./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");'
然后代码终止运行。
我检查了ns3的每个文件夹,但每个文件夹中都存在'CMakeLists.txt'文件。而且,我按照以下链接中的4.3.2步骤进行操作:https://www.nsnam.org/docs/manual/html/working-with-cmake.html
但是没有任何变化。
英文:
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.
答案1
得分: 1
你提到的"ns-allinone-3.39/ns-3.39/examples/tutorial/first.cc"是C++源代码,不是脚本或可执行文件,所以你不能直接在终端中运行它。
C++源代码可以以许多种扩展名结尾,例如.cpp、.cc、.cxx(参考),而头文件以.h、.hpp等结尾。它们只是文本文件,在运行之前必须编译成二进制文件。
从apt安装
如果你只想使用该程序。
-
运行
sudo apt install ns3进行安装。 -
运行
dpkg -L ns3查看安装的包通常位于"/usr/bin"下的可执行文件。
从源代码构建
如果你想从源代码构建:
- 配置(参考tutorial 4.3.1.1。)
- 切换到"ns-allinone-3.39/ns-3.39"目录并运行
./ns3 configure -d release --enable-examples --enable-tests
这一步会创建"cmake-cache"和"build"目录。
- 构建(详见"ns-allinone-3.39/ns-3.39/README.md")
./ns3
示例现在位于"ns-allinone-3.39/ns-3.39/build/examples"目录中。
注意
-
许多CMakeLists.txt:开发人员通常在许多目录中放置CMakeLists.txt,这是一种常见的方法,请查看链接了解更多信息。
-
在Linux中,通常可执行文件没有扩展名,通常Shell脚本没有扩展名或".sh"扩展名。请查看链接以获取更多信息。
英文:
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 ns3to install. -
Run
dpkg -L ns3to 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:
- 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.
- 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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论