memset、memcpy 未引用
memset, memcpy not reference
我想运行first.cc(ns3库enter link description here上的一个例子,网络模拟)ubuntu最新版本21,gcc版本9.3.0
这里是CMakeLists.txt内容:
cmake_minimum_required(VERSION 3.15)
project(cmake-demo LANGUAGES CXX)
SET(CMAKE_CXX_COMPILER "g++")
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(SOURCE tutorial/first.cc)
include_directories(
"usr/include"
"/home/quan/ns-allinone-3.29/ns-3.29/build"
"/home/quan/ns-allinone-3.29/ns-3.29/build/ns3"
)
link_directories(
"/home/quan/ns-allinone-3.29/ns-3.29/build/lib"
)
add_executable(${PROJECT_NAME} ${SOURCE})
这里是示例的小代码
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/internet-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/applications-module.h"
using namespace ns3;
NS_LOG_COMPONENT_DEFINE ("FirstScriptExample");
int
main (int argc, char *argv[])
{
CommandLine cmd;
cmd.Parse (argc, argv);
Time::SetResolution (Time::NS);
LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);
NodeContainer nodes;
nodes.Create (2);
PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
NetDeviceContainer devices;
devices = pointToPoint.Install (nodes);
InternetStackHelper stack;
stack.Install (nodes);
Ipv4AddressHelper address;
address.SetBase ("10.1.1.0", "255.255.255.0");
Ipv4InterfaceContainer interfaces = address.Assign (devices);
UdpEchoServerHelper echoServer (9);
ApplicationContainer serverApps = echoServer.Install (nodes.Get (1));
serverApps.Start (Seconds (1.0));
serverApps.Stop (Seconds (10.0));
UdpEchoClientHelper echoClient (interfaces.GetAddress (1), 9);
echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.0)));
echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
ApplicationContainer clientApps = echoClient.Install (nodes.Get (0));
clientApps.Start (Seconds (2.0));
clientApps.Stop (Seconds (10.0));
Simulator::Run ();
Simulator::Destroy ();
return 0;
}
但是当我构建这个例子时,我得到一些关于 memset 的错误,memcpy 函数没有引用
这是错误:
[main] Building folder: examples
[build] Starting build
[proc] Executing command: /usr/bin/cmake --build /home/quan/ns-allinone-3.29/ns-3.29/examples/build --config Debug --target all -j 18 --
[build] [ 50%] Building CXX object CMakeFiles/cmake-demo.dir/tutorial/first.cc.o
[build] In file included from /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/hash-function.h:24,
[build] from /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/hash.h:29,
[build] from /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/type-id.h:29,
[build] from /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/object-base.h:23,
[build] from /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/object.h:29,
[build] from /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/scheduler.h:25,
[build] from /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/calendar-scheduler.h:24,
[build] from /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/core-module.h:19,
[build] from /home/quan/ns-allinone-3.29/ns-3.29/examples/tutorial/first.cc:17:
[build] /usr/include/c++/9/cstring:77:11: error: ‘::memchr’ has not been declared
[build] 77 | using ::memchr;
[build] | ^~~~~~
[build] /usr/include/c++/9/cstring:78:11: error: ‘::memcmp’ has not been declared
[build] 78 | using ::memcmp;
[build] | ^~~~~~
[build] /usr/include/c++/9/cstring:79:11: error: ‘::memcpy’ has not been declared
[build] 79 | using ::memcpy;
[build] | ^~~~~~
[build] /usr/include/c++/9/cstring:80:11: error: ‘::memmove’ has not been declared
[build] 80 | using ::memmove;
[build] | ^~~~~~~
[build] /usr/include/c++/9/cstring:81:11: error: ‘::memset’ has not been declared
[build] 81 | using ::memset;
[build] | ^~~~~~
[build] /usr/include/c++/9/cstring:82:11: error: ‘::strcat’ has not been declared
[build] 82 | using ::strcat;
[build] | ^~~~~~
[build] /usr/include/c++/9/cstring:83:11: error: ‘::strcmp’ has not been declared
[build] 83 | using ::strcmp;
[build] | ^~~~~~
[build] /usr/include/c++/9/cstring:84:11: error: ‘::strcoll’ has not been declared
[build] 84 | using ::strcoll;
[build] | ^~~~~~~
[build] /usr/include/c++/9/cstring:85:11: error: ‘::strcpy’ has not been declared
[build] 85 | using ::strcpy;
[build] | ^~~~~~
[build] /usr/include/c++/9/cstring:86:11: error: ‘::strcspn’ has not been declared
[build] 86 | using ::strcspn;
[build] | ^~~~~~~
[build] /usr/include/c++/9/cstring:87:11: error: ‘::strerror’ has not been declared
[build] 87 | using ::strerror;
[build] | ^~~~~~~~
[build] /usr/include/c++/9/cstring:88:11: error: ‘::strlen’ has not been declared
[build] 88 | using ::strlen;
[build] | ^~~~~~
[build] /usr/include/c++/9/cstring:89:11: error: ‘::strncat’ has not been declared
[build] 89 | using ::strncat;
[build] | ^~~~~~~
[build] /usr/include/c++/9/cstring:90:11: error: ‘::strncmp’ has not been declared
[build] 90 | using ::strncmp;
[build] | ^~~~~~~
[build] /usr/include/c++/9/cstring:91:11: error: ‘::strncpy’ has not been declared
[build] 91 | using ::strncpy;
[build] | ^~~~~~~
[build] /usr/include/c++/9/cstring:92:11: error: ‘::strspn’ has not been declared
[build] 92 | using ::strspn;
[build] | ^~~~~~
[build] /usr/include/c++/9/cstring:93:11: error: ‘::strtok’ has not been declared
[build] 93 | using ::strtok;
[build] | ^~~~~~
[build] /usr/include/c++/9/cstring:94:11: error: ‘::strxfrm’ has not been declared
[build] 94 | using ::strxfrm;
[build] | ^~~~~~~
[build] /usr/include/c++/9/cstring:95:11: error: ‘::strchr’ has not been declared
[build] 95 | using ::strchr;
[build] | ^~~~~~
[build] /usr/include/c++/9/cstring:96:11: error: ‘::strpbrk’ has not been declared
[build] 96 | using ::strpbrk;
[build] | ^~~~~~~
[build] /usr/include/c++/9/cstring:97:11: error: ‘::strrchr’ has not been declared
[build] 97 | using ::strrchr;
[build] | ^~~~~~~
[build] /usr/include/c++/9/cstring:98:11: error: ‘::strstr’ has not been declared
[build] 98 | using ::strstr;
[build] | ^~~~~~
[build] In file included from /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/hash.h:29,
[build] from /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/type-id.h:29,
[build] from /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/object-base.h:23,
[build] from /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/object.h:29,
[build] from /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/scheduler.h:25,
[build] from /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/calendar-scheduler.h:24,
[build] from /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/core-module.h:19,
[build] from /home/quan/ns-allinone-3.29/ns-3.29/examples/tutorial/first.cc:17:
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/hash-function.h: In member function ‘virtual uint32_t ns3::Hash::Function::Hash64::GetHash32(const char*, std::size_t)’:
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/hash-function.h:169:5: error: ‘memcpy’ was not declared in this scope
[build] 169 | memcpy (&hash32, &hash64, sizeof (hash32));
[build] | ^~~~~~
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/hash-function.h:25:1: note: ‘memcpy’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
[build] 24 | #include <cstring> // memcpy
[build] +++ |+#include <cstring>
[build] 25 | #include "simple-ref-count.h"
[build] In file included from /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/address-utils.h:23,
[build] from /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/network-module.h:10,
[build] from /home/quan/ns-allinone-3.29/ns-3.29/examples/tutorial/first.cc:18:
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/buffer.h: In member function ‘void ns3::Buffer::Iterator::WriteU8(uint8_t, uint32_t)’:
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/buffer.h:893:12: error: ‘memset’ is not a member of ‘std’
[build] 893 | std::memset (&(m_data[m_current]), data, len);
[build] | ^~~~~~
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/buffer.h:899:12: error: ‘memset’ is not a member of ‘std’
[build] 899 | std::memset (buffer, data, len);
[build] | ^~~~~~
[build] In file included from /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/address-utils.h:25,
[build] from /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/network-module.h:10,
[build] from /home/quan/ns-allinone-3.29/ns-3.29/examples/tutorial/first.cc:18:
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/ipv6-address.h: In function ‘bool ns3::operator==(const ns3::Ipv6Address&, const ns3::Ipv6Address&)’:
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/ipv6-address.h:591:17: error: ‘memcmp’ is not a member of ‘std’; did you mean ‘memchr’?
[build] 591 | return (!std::memcmp (a.m_address, b.m_address, 16));
[build] | ^~~~~~
[build] | memchr
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/ipv6-address.h: In function ‘bool ns3::operator!=(const ns3::Ipv6Address&, const ns3::Ipv6Address&)’:
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/ipv6-address.h:596:15: error: ‘memcmp’ is not a member of ‘std’; did you mean ‘memchr’?
[build] 596 | return std::memcmp (a.m_address, b.m_address, 16);
[build] | ^~~~~~
[build] | memchr
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/ipv6-address.h: In function ‘bool ns3::operator<(const ns3::Ipv6Address&, const ns3::Ipv6Address&)’:
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/ipv6-address.h:601:16: error: ‘memcmp’ is not a member of ‘std’; did you mean ‘memchr’?
[build] 601 | return (std::memcmp (a.m_address, b.m_address, 16) < 0);
[build] | ^~~~~~
[build] | memchr
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/ipv6-address.h: In function ‘bool ns3::operator==(const ns3::Ipv6Prefix&, const ns3::Ipv6Prefix&)’:
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/ipv6-address.h:606:17: error: ‘memcmp’ is not a member of ‘std’; did you mean ‘memchr’?
[build] 606 | return (!std::memcmp (a.m_prefix, b.m_prefix, 16));
[build] | ^~~~~~
[build] | memchr
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/ipv6-address.h: In function ‘bool ns3::operator!=(const ns3::Ipv6Prefix&, const ns3::Ipv6Prefix&)’:
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/ipv6-address.h:611:15: error: ‘memcmp’ is not a member of ‘std’; did you mean ‘memchr’?
[build] 611 | return std::memcmp (a.m_prefix, b.m_prefix, 16);
[build] | ^~~~~~
[build] | memchr
[build] In file included from /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/address-utils.h:27,
[build] from /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/network-module.h:10,
[build] from /home/quan/ns-allinone-3.29/ns-3.29/examples/tutorial/first.cc:18:
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/mac64-address.h: In function ‘bool ns3::operator==(const ns3::Mac64Address&, const ns3::Mac64Address&)’:
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/mac64-address.h:162:10: error: ‘memcmp’ was not declared in this scope
[build] 162 | return memcmp (a.m_address, b.m_address, 8) == 0;
[build] | ^~~~~~
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/mac64-address.h:1:1: note: ‘memcmp’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
[build] +++ |+#include <cstring>
[build] 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/mac64-address.h: In function ‘bool ns3::operator!=(const ns3::Mac64Address&, const ns3::Mac64Address&)’:
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/mac64-address.h:166:10: error: ‘memcmp’ was not declared in this scope
[build] 166 | return memcmp (a.m_address, b.m_address, 8) != 0;
[build] | ^~~~~~
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/mac64-address.h:166:10: note: ‘memcmp’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/mac64-address.h: In function ‘bool ns3::operator<(const ns3::Mac64Address&, const ns3::Mac64Address&)’:
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/mac64-address.h:170:10: error: ‘memcmp’ was not declared in this scope
[build] 170 | return memcmp (a.m_address, b.m_address, 8) < 0;
[build] | ^~~~~~
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/mac64-address.h:170:10: note: ‘memcmp’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
[build] In file included from /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/address-utils.h:28,
[build] from /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/network-module.h:10,
[build] from /home/quan/ns-allinone-3.29/ns-3.29/examples/tutorial/first.cc:18:
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/mac48-address.h: In function ‘bool ns3::operator==(const ns3::Mac48Address&, const ns3::Mac48Address&)’:
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/mac48-address.h:205:10: error: ‘memcmp’ was not declared in this scope
[build] 205 | return memcmp (a.m_address, b.m_address, 6) == 0;
[build] | ^~~~~~
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/mac48-address.h:1:1: note: ‘memcmp’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
[build] +++ |+#include <cstring>
[build] 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/mac48-address.h: In function ‘bool ns3::operator!=(const ns3::Mac48Address&, const ns3::Mac48Address&)’:
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/mac48-address.h:209:10: error: ‘memcmp’ was not declared in this scope
[build] 209 | return memcmp (a.m_address, b.m_address, 6) != 0;
[build] | ^~~~~~
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/mac48-address.h:209:10: note: ‘memcmp’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/mac48-address.h: In function ‘bool ns3::operator<(const ns3::Mac48Address&, const ns3::Mac48Address&)’:
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/mac48-address.h:213:10: error: ‘memcmp’ was not declared in this scope
[build] 213 | return memcmp (a.m_address, b.m_address, 6) < 0;
[build] | ^~~~~~
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/mac48-address.h:213:10: note: ‘memcmp’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
[build] In file included from /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/address-utils.h:29,
[build] from /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/network-module.h:10,
[build] from /home/quan/ns-allinone-3.29/ns-3.29/examples/tutorial/first.cc:18:
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/mac16-address.h: In function ‘bool ns3::operator==(const ns3::Mac16Address&, const ns3::Mac16Address&)’:
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/mac16-address.h:155:10: error: ‘memcmp’ was not declared in this scope
[build] 155 | return memcmp (a.m_address, b.m_address, 2) == 0;
[build] | ^~~~~~
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/mac16-address.h:1:1: note: ‘memcmp’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
[build] +++ |+#include <cstring>
[build] 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/mac16-address.h: In function ‘bool ns3::operator!=(const ns3::Mac16Address&, const ns3::Mac16Address&)’:
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/mac16-address.h:159:10: error: ‘memcmp’ was not declared in this scope
[build] 159 | return memcmp (a.m_address, b.m_address, 2) != 0;
[build] | ^~~~~~
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/mac16-address.h:159:10: note: ‘memcmp’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/mac16-address.h: In function ‘bool ns3::operator<(const ns3::Mac16Address&, const ns3::Mac16Address&)’:
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/mac16-address.h:163:10: error: ‘memcmp’ was not declared in this scope
[build] 163 | return memcmp (a.m_address, b.m_address, 2) < 0;
[build] | ^~~~~~
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/mac16-address.h:163:10: note: ‘memcmp’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
[build] In file included from /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/packet.h:27,
[build] from /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/net-device.h:28,
[build] from /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/node.h:29,
[build] from /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/application.h:28,
[build] from /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/application-container.h:26,
[build] from /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/network-module.h:12,
[build] from /home/quan/ns-allinone-3.29/ns-3.29/examples/tutorial/first.cc:18:
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/packet-metadata.h: In constructor ‘ns3::PacketMetadata::PacketMetadata(uint64_t, uint32_t)’:
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/packet-metadata.h:701:3: error: ‘memset’ was not declared in this scope
[build] 701 | memset (m_data->m_data, 0xff, 4);
[build] | ^~~~~~
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/packet-metadata.h:29:1: note: ‘memset’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
[build] 28 | #include "ns3/type-id.h"
[build] +++ |+#include <cstring>
[build] 29 | #include "buffer.h"
[build] make[2]: *** [CMakeFiles/cmake-demo.dir/build.make:63: CMakeFiles/cmake-demo.dir/tutorial/first.cc.o] Error 1
[build] make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/cmake-demo.dir/all] Error 2
[build] make: *** [Makefile:84: all] Error 2
[build] Build finished with exit code 2
任何建议都会帮助我解决这个问题,在此先感谢!
您需要从包含路径中删除 /home/quan/ns-allinone-3.29/ns-3.29/build/ns3
。查看示例代码,它总是在路径中得到 ncs
,你不需要在 include_directories
中添加它。 ns3 中的 string.h
与 STL
中定义的冲突
我想运行first.cc(ns3库enter link description here上的一个例子,网络模拟)ubuntu最新版本21,gcc版本9.3.0
这里是CMakeLists.txt内容:
cmake_minimum_required(VERSION 3.15)
project(cmake-demo LANGUAGES CXX)
SET(CMAKE_CXX_COMPILER "g++")
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(SOURCE tutorial/first.cc)
include_directories(
"usr/include"
"/home/quan/ns-allinone-3.29/ns-3.29/build"
"/home/quan/ns-allinone-3.29/ns-3.29/build/ns3"
)
link_directories(
"/home/quan/ns-allinone-3.29/ns-3.29/build/lib"
)
add_executable(${PROJECT_NAME} ${SOURCE})
这里是示例的小代码
#include "ns3/core-module.h"
#include "ns3/network-module.h"
#include "ns3/internet-module.h"
#include "ns3/point-to-point-module.h"
#include "ns3/applications-module.h"
using namespace ns3;
NS_LOG_COMPONENT_DEFINE ("FirstScriptExample");
int
main (int argc, char *argv[])
{
CommandLine cmd;
cmd.Parse (argc, argv);
Time::SetResolution (Time::NS);
LogComponentEnable ("UdpEchoClientApplication", LOG_LEVEL_INFO);
LogComponentEnable ("UdpEchoServerApplication", LOG_LEVEL_INFO);
NodeContainer nodes;
nodes.Create (2);
PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute ("DataRate", StringValue ("5Mbps"));
pointToPoint.SetChannelAttribute ("Delay", StringValue ("2ms"));
NetDeviceContainer devices;
devices = pointToPoint.Install (nodes);
InternetStackHelper stack;
stack.Install (nodes);
Ipv4AddressHelper address;
address.SetBase ("10.1.1.0", "255.255.255.0");
Ipv4InterfaceContainer interfaces = address.Assign (devices);
UdpEchoServerHelper echoServer (9);
ApplicationContainer serverApps = echoServer.Install (nodes.Get (1));
serverApps.Start (Seconds (1.0));
serverApps.Stop (Seconds (10.0));
UdpEchoClientHelper echoClient (interfaces.GetAddress (1), 9);
echoClient.SetAttribute ("MaxPackets", UintegerValue (1));
echoClient.SetAttribute ("Interval", TimeValue (Seconds (1.0)));
echoClient.SetAttribute ("PacketSize", UintegerValue (1024));
ApplicationContainer clientApps = echoClient.Install (nodes.Get (0));
clientApps.Start (Seconds (2.0));
clientApps.Stop (Seconds (10.0));
Simulator::Run ();
Simulator::Destroy ();
return 0;
}
但是当我构建这个例子时,我得到一些关于 memset 的错误,memcpy 函数没有引用 这是错误:
[main] Building folder: examples
[build] Starting build
[proc] Executing command: /usr/bin/cmake --build /home/quan/ns-allinone-3.29/ns-3.29/examples/build --config Debug --target all -j 18 --
[build] [ 50%] Building CXX object CMakeFiles/cmake-demo.dir/tutorial/first.cc.o
[build] In file included from /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/hash-function.h:24,
[build] from /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/hash.h:29,
[build] from /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/type-id.h:29,
[build] from /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/object-base.h:23,
[build] from /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/object.h:29,
[build] from /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/scheduler.h:25,
[build] from /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/calendar-scheduler.h:24,
[build] from /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/core-module.h:19,
[build] from /home/quan/ns-allinone-3.29/ns-3.29/examples/tutorial/first.cc:17:
[build] /usr/include/c++/9/cstring:77:11: error: ‘::memchr’ has not been declared
[build] 77 | using ::memchr;
[build] | ^~~~~~
[build] /usr/include/c++/9/cstring:78:11: error: ‘::memcmp’ has not been declared
[build] 78 | using ::memcmp;
[build] | ^~~~~~
[build] /usr/include/c++/9/cstring:79:11: error: ‘::memcpy’ has not been declared
[build] 79 | using ::memcpy;
[build] | ^~~~~~
[build] /usr/include/c++/9/cstring:80:11: error: ‘::memmove’ has not been declared
[build] 80 | using ::memmove;
[build] | ^~~~~~~
[build] /usr/include/c++/9/cstring:81:11: error: ‘::memset’ has not been declared
[build] 81 | using ::memset;
[build] | ^~~~~~
[build] /usr/include/c++/9/cstring:82:11: error: ‘::strcat’ has not been declared
[build] 82 | using ::strcat;
[build] | ^~~~~~
[build] /usr/include/c++/9/cstring:83:11: error: ‘::strcmp’ has not been declared
[build] 83 | using ::strcmp;
[build] | ^~~~~~
[build] /usr/include/c++/9/cstring:84:11: error: ‘::strcoll’ has not been declared
[build] 84 | using ::strcoll;
[build] | ^~~~~~~
[build] /usr/include/c++/9/cstring:85:11: error: ‘::strcpy’ has not been declared
[build] 85 | using ::strcpy;
[build] | ^~~~~~
[build] /usr/include/c++/9/cstring:86:11: error: ‘::strcspn’ has not been declared
[build] 86 | using ::strcspn;
[build] | ^~~~~~~
[build] /usr/include/c++/9/cstring:87:11: error: ‘::strerror’ has not been declared
[build] 87 | using ::strerror;
[build] | ^~~~~~~~
[build] /usr/include/c++/9/cstring:88:11: error: ‘::strlen’ has not been declared
[build] 88 | using ::strlen;
[build] | ^~~~~~
[build] /usr/include/c++/9/cstring:89:11: error: ‘::strncat’ has not been declared
[build] 89 | using ::strncat;
[build] | ^~~~~~~
[build] /usr/include/c++/9/cstring:90:11: error: ‘::strncmp’ has not been declared
[build] 90 | using ::strncmp;
[build] | ^~~~~~~
[build] /usr/include/c++/9/cstring:91:11: error: ‘::strncpy’ has not been declared
[build] 91 | using ::strncpy;
[build] | ^~~~~~~
[build] /usr/include/c++/9/cstring:92:11: error: ‘::strspn’ has not been declared
[build] 92 | using ::strspn;
[build] | ^~~~~~
[build] /usr/include/c++/9/cstring:93:11: error: ‘::strtok’ has not been declared
[build] 93 | using ::strtok;
[build] | ^~~~~~
[build] /usr/include/c++/9/cstring:94:11: error: ‘::strxfrm’ has not been declared
[build] 94 | using ::strxfrm;
[build] | ^~~~~~~
[build] /usr/include/c++/9/cstring:95:11: error: ‘::strchr’ has not been declared
[build] 95 | using ::strchr;
[build] | ^~~~~~
[build] /usr/include/c++/9/cstring:96:11: error: ‘::strpbrk’ has not been declared
[build] 96 | using ::strpbrk;
[build] | ^~~~~~~
[build] /usr/include/c++/9/cstring:97:11: error: ‘::strrchr’ has not been declared
[build] 97 | using ::strrchr;
[build] | ^~~~~~~
[build] /usr/include/c++/9/cstring:98:11: error: ‘::strstr’ has not been declared
[build] 98 | using ::strstr;
[build] | ^~~~~~
[build] In file included from /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/hash.h:29,
[build] from /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/type-id.h:29,
[build] from /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/object-base.h:23,
[build] from /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/object.h:29,
[build] from /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/scheduler.h:25,
[build] from /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/calendar-scheduler.h:24,
[build] from /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/core-module.h:19,
[build] from /home/quan/ns-allinone-3.29/ns-3.29/examples/tutorial/first.cc:17:
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/hash-function.h: In member function ‘virtual uint32_t ns3::Hash::Function::Hash64::GetHash32(const char*, std::size_t)’:
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/hash-function.h:169:5: error: ‘memcpy’ was not declared in this scope
[build] 169 | memcpy (&hash32, &hash64, sizeof (hash32));
[build] | ^~~~~~
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/hash-function.h:25:1: note: ‘memcpy’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
[build] 24 | #include <cstring> // memcpy
[build] +++ |+#include <cstring>
[build] 25 | #include "simple-ref-count.h"
[build] In file included from /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/address-utils.h:23,
[build] from /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/network-module.h:10,
[build] from /home/quan/ns-allinone-3.29/ns-3.29/examples/tutorial/first.cc:18:
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/buffer.h: In member function ‘void ns3::Buffer::Iterator::WriteU8(uint8_t, uint32_t)’:
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/buffer.h:893:12: error: ‘memset’ is not a member of ‘std’
[build] 893 | std::memset (&(m_data[m_current]), data, len);
[build] | ^~~~~~
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/buffer.h:899:12: error: ‘memset’ is not a member of ‘std’
[build] 899 | std::memset (buffer, data, len);
[build] | ^~~~~~
[build] In file included from /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/address-utils.h:25,
[build] from /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/network-module.h:10,
[build] from /home/quan/ns-allinone-3.29/ns-3.29/examples/tutorial/first.cc:18:
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/ipv6-address.h: In function ‘bool ns3::operator==(const ns3::Ipv6Address&, const ns3::Ipv6Address&)’:
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/ipv6-address.h:591:17: error: ‘memcmp’ is not a member of ‘std’; did you mean ‘memchr’?
[build] 591 | return (!std::memcmp (a.m_address, b.m_address, 16));
[build] | ^~~~~~
[build] | memchr
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/ipv6-address.h: In function ‘bool ns3::operator!=(const ns3::Ipv6Address&, const ns3::Ipv6Address&)’:
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/ipv6-address.h:596:15: error: ‘memcmp’ is not a member of ‘std’; did you mean ‘memchr’?
[build] 596 | return std::memcmp (a.m_address, b.m_address, 16);
[build] | ^~~~~~
[build] | memchr
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/ipv6-address.h: In function ‘bool ns3::operator<(const ns3::Ipv6Address&, const ns3::Ipv6Address&)’:
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/ipv6-address.h:601:16: error: ‘memcmp’ is not a member of ‘std’; did you mean ‘memchr’?
[build] 601 | return (std::memcmp (a.m_address, b.m_address, 16) < 0);
[build] | ^~~~~~
[build] | memchr
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/ipv6-address.h: In function ‘bool ns3::operator==(const ns3::Ipv6Prefix&, const ns3::Ipv6Prefix&)’:
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/ipv6-address.h:606:17: error: ‘memcmp’ is not a member of ‘std’; did you mean ‘memchr’?
[build] 606 | return (!std::memcmp (a.m_prefix, b.m_prefix, 16));
[build] | ^~~~~~
[build] | memchr
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/ipv6-address.h: In function ‘bool ns3::operator!=(const ns3::Ipv6Prefix&, const ns3::Ipv6Prefix&)’:
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/ipv6-address.h:611:15: error: ‘memcmp’ is not a member of ‘std’; did you mean ‘memchr’?
[build] 611 | return std::memcmp (a.m_prefix, b.m_prefix, 16);
[build] | ^~~~~~
[build] | memchr
[build] In file included from /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/address-utils.h:27,
[build] from /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/network-module.h:10,
[build] from /home/quan/ns-allinone-3.29/ns-3.29/examples/tutorial/first.cc:18:
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/mac64-address.h: In function ‘bool ns3::operator==(const ns3::Mac64Address&, const ns3::Mac64Address&)’:
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/mac64-address.h:162:10: error: ‘memcmp’ was not declared in this scope
[build] 162 | return memcmp (a.m_address, b.m_address, 8) == 0;
[build] | ^~~~~~
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/mac64-address.h:1:1: note: ‘memcmp’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
[build] +++ |+#include <cstring>
[build] 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/mac64-address.h: In function ‘bool ns3::operator!=(const ns3::Mac64Address&, const ns3::Mac64Address&)’:
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/mac64-address.h:166:10: error: ‘memcmp’ was not declared in this scope
[build] 166 | return memcmp (a.m_address, b.m_address, 8) != 0;
[build] | ^~~~~~
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/mac64-address.h:166:10: note: ‘memcmp’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/mac64-address.h: In function ‘bool ns3::operator<(const ns3::Mac64Address&, const ns3::Mac64Address&)’:
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/mac64-address.h:170:10: error: ‘memcmp’ was not declared in this scope
[build] 170 | return memcmp (a.m_address, b.m_address, 8) < 0;
[build] | ^~~~~~
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/mac64-address.h:170:10: note: ‘memcmp’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
[build] In file included from /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/address-utils.h:28,
[build] from /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/network-module.h:10,
[build] from /home/quan/ns-allinone-3.29/ns-3.29/examples/tutorial/first.cc:18:
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/mac48-address.h: In function ‘bool ns3::operator==(const ns3::Mac48Address&, const ns3::Mac48Address&)’:
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/mac48-address.h:205:10: error: ‘memcmp’ was not declared in this scope
[build] 205 | return memcmp (a.m_address, b.m_address, 6) == 0;
[build] | ^~~~~~
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/mac48-address.h:1:1: note: ‘memcmp’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
[build] +++ |+#include <cstring>
[build] 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/mac48-address.h: In function ‘bool ns3::operator!=(const ns3::Mac48Address&, const ns3::Mac48Address&)’:
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/mac48-address.h:209:10: error: ‘memcmp’ was not declared in this scope
[build] 209 | return memcmp (a.m_address, b.m_address, 6) != 0;
[build] | ^~~~~~
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/mac48-address.h:209:10: note: ‘memcmp’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/mac48-address.h: In function ‘bool ns3::operator<(const ns3::Mac48Address&, const ns3::Mac48Address&)’:
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/mac48-address.h:213:10: error: ‘memcmp’ was not declared in this scope
[build] 213 | return memcmp (a.m_address, b.m_address, 6) < 0;
[build] | ^~~~~~
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/mac48-address.h:213:10: note: ‘memcmp’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
[build] In file included from /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/address-utils.h:29,
[build] from /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/network-module.h:10,
[build] from /home/quan/ns-allinone-3.29/ns-3.29/examples/tutorial/first.cc:18:
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/mac16-address.h: In function ‘bool ns3::operator==(const ns3::Mac16Address&, const ns3::Mac16Address&)’:
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/mac16-address.h:155:10: error: ‘memcmp’ was not declared in this scope
[build] 155 | return memcmp (a.m_address, b.m_address, 2) == 0;
[build] | ^~~~~~
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/mac16-address.h:1:1: note: ‘memcmp’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
[build] +++ |+#include <cstring>
[build] 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/mac16-address.h: In function ‘bool ns3::operator!=(const ns3::Mac16Address&, const ns3::Mac16Address&)’:
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/mac16-address.h:159:10: error: ‘memcmp’ was not declared in this scope
[build] 159 | return memcmp (a.m_address, b.m_address, 2) != 0;
[build] | ^~~~~~
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/mac16-address.h:159:10: note: ‘memcmp’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/mac16-address.h: In function ‘bool ns3::operator<(const ns3::Mac16Address&, const ns3::Mac16Address&)’:
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/mac16-address.h:163:10: error: ‘memcmp’ was not declared in this scope
[build] 163 | return memcmp (a.m_address, b.m_address, 2) < 0;
[build] | ^~~~~~
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/mac16-address.h:163:10: note: ‘memcmp’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
[build] In file included from /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/packet.h:27,
[build] from /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/net-device.h:28,
[build] from /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/node.h:29,
[build] from /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/application.h:28,
[build] from /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/application-container.h:26,
[build] from /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/network-module.h:12,
[build] from /home/quan/ns-allinone-3.29/ns-3.29/examples/tutorial/first.cc:18:
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/packet-metadata.h: In constructor ‘ns3::PacketMetadata::PacketMetadata(uint64_t, uint32_t)’:
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/packet-metadata.h:701:3: error: ‘memset’ was not declared in this scope
[build] 701 | memset (m_data->m_data, 0xff, 4);
[build] | ^~~~~~
[build] /home/quan/ns-allinone-3.29/ns-3.29/build/ns3/packet-metadata.h:29:1: note: ‘memset’ is defined in header ‘<cstring>’; did you forget to ‘#include <cstring>’?
[build] 28 | #include "ns3/type-id.h"
[build] +++ |+#include <cstring>
[build] 29 | #include "buffer.h"
[build] make[2]: *** [CMakeFiles/cmake-demo.dir/build.make:63: CMakeFiles/cmake-demo.dir/tutorial/first.cc.o] Error 1
[build] make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/cmake-demo.dir/all] Error 2
[build] make: *** [Makefile:84: all] Error 2
[build] Build finished with exit code 2
任何建议都会帮助我解决这个问题,在此先感谢!
您需要从包含路径中删除 /home/quan/ns-allinone-3.29/ns-3.29/build/ns3
。查看示例代码,它总是在路径中得到 ncs
,你不需要在 include_directories
中添加它。 ns3 中的 string.h
与 STL