error: ‘memcpy’ was not declared in this scope 解决

本文解决在编译C++2D范围树librangetree-v1.2时遇到的error:‘memcpy’wasnotdeclaredinthisscope错误,通过添加头文件<cstring>并进行代码修改成功解决问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

0. 在编译librangetree-v1.2(C++ 2D 范围树)时,出现 error: ‘memcpy’ was not declared in this scope 错误,原因是没有包含相关头文件

1. 错误如下:

[ghui@StuOS librangetree-v1.2]$ pwd
/home/Ghui/Desktop/librangetree-v1.2
[ghui@StuOS librangetree-v1.2]$ ls
bench  COPYING  doc  lrtypes.h  Makefile  ranget.h  test
[ghui@StuOS librangetree-v1.2]$ make
g++  ranget.h
make -C test
make[1]: Entering directory `/home/Ghui/Desktop/librangetree-v1.2/test'
g++ -Wall -Wextra -I ..   simple.cpp ../ranget.h   -o simple
In file included from test.h:8:0,
                 from simple.cpp:1:
../ranget.h: In instantiation of ‘void rangetree<point, data>::mergekids(rangetree<point, data>::pty*&, u32&, rangetree<point, data>::node*, rangetree<point, data>::node*) const [with point = short unsigned int; data = const char; u32 = unsigned int]’:
../ranget.h:417:65:   required from ‘void rangetree<point, data>::build() [with point = short unsigned int; data = const char]’
../ranget.h:114:9:   required from ‘void rangetree<point, data>::finalize() [with point = short unsigned int; data = const char]’
simple.cpp:11:16:   required from here
../ranget.h:535:30: error: ‘memcpy’ was not declared in this scope
      (rmax - r) * sizeof(pty));
                              ^
../ranget.h:539:30: error: ‘memcpy’ was not declared in this scope
      (lmax - l) * sizeof(pty));
                              ^
make[1]: *** [simple] Error 1
make[1]: Leaving directory `/home/Ghui/Desktop/librangetree-v1.2/test'
make: *** [all] Error 2


2. 在ranget.h头文件中添加#include <cstring>,如下:

#include <cstring>
#ifndef LIBRANGET
#define LIBRANGET

#include "lrtypes.h"


3. 修改后再次编译:

[ghui@StuOS librangetree-v1.2]$ make
g++  ranget.h
make -C test
make[1]: Entering directory `/home/Ghui/Desktop/librangetree-v1.2/test'
g++ -Wall -Wextra -I ..   simple.cpp ../ranget.h   -o simple
g++ -Wall -Wextra -I ..   x-search-before-fin.cpp ../ranget.h   -o x-search-before-fin
g++ -Wall -Wextra -I ..   period.cpp ../ranget.h   -o period
g++ -Wall -Wextra -I ..   random.cpp ../ranget.h   -o random
g++ -Wall -Wextra -I ..   individual.cpp ../ranget.h   -o individual
individual.cpp: In function ‘int main()’:
individual.cpp:14:26: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
   tree.add(i, i, (u16 *) i);
                          ^
g++ -Wall -Wextra -I ..   identica.cpp ../ranget.h   -o identica
g++ -Wall -Wextra -I ..   mem-too-little.cpp ../ranget.h   -o mem-too-little
g++ -Wall -Wextra -I ..   signed.cpp ../ranget.h   -o signed
Running test simple... 
Running test x-search-before-fin... 
Running test period... 
Running test random... 
Running test individual... 
Running test identica... 
Running test mem-too-little... 
Running test signed... 

	All tests passed!

make[1]: Leaving directory `/home/Ghui/Desktop/librangetree-v1.2/test'
[ghui@StuOS librangetree-v1.2]$ 

By iomato

iomato.dev@Gmail.com

09:30 - 2013.01.05


35 0 F:\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\cstdint In file included from F:/Dev-Cpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/cstdint 6 C:\Users\余伟杰\Desktop\哈希算法.cpp from C:\Users\余伟杰\Desktop\哈希算法.cpp 32 2 F:\Dev-Cpp\MinGW64\lib\gcc\x86_64-w64-mingw32\4.9.2\include\c++\bits\c++0x_warning.h [Error] #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options. 18 7 C:\Users\余伟杰\Desktop\哈希算法.cpp [Error] 'uint32_t' does not name a type 52 23 C:\Users\余伟杰\Desktop\哈希算法.cpp [Error] 'uint8_t' does not name a type 100 5 C:\Users\余伟杰\Desktop\哈希算法.cpp [Error] 'uint32_t' does not name a type 101 5 C:\Users\余伟杰\Desktop\哈希算法.cpp [Error] 'uint32_t' does not name a type 102 5 C:\Users\余伟杰\Desktop\哈希算法.cpp [Error] 'uint8_t' does not name a type 105 26 C:\Users\余伟杰\Desktop\哈希算法.cpp [Error] 'uint8_t' does not name a type 182 30 C:\Users\余伟杰\Desktop\哈希算法.cpp [Error] 'uint8_t' does not name a type 182 46 C:\Users\余伟杰\Desktop\哈希算法.cpp [Error] 'uint32_t' has not been declared 192 30 C:\Users\余伟杰\Desktop\哈希算法.cpp [Error] 'uint32_t' does not name a type 192 47 C:\Users\余伟杰\Desktop\哈希算法.cpp [Error] 'uint8_t' has not been declared 202 40 C:\Users\余伟杰\Desktop\哈希算法.cpp [Error] 'uint8_t' does not name a type C:\Users\余伟杰\Desktop\哈希算法.cpp In member function 'void MD5::reset()': 43 9 C:\Users\余伟杰\Desktop\哈希算法.cpp [Error] 'state' was not declared in this scope 47 9 C:\Users\余伟杰\Desktop\哈希算法.cpp [Error] 'count' was not declared in this scope 48 16 C:\Users\余伟杰\Desktop\哈希算法.cpp [Error] 'buffer' was not declared in this scope C:\Users\余伟杰\Desktop\哈希算法.cpp In member function 'void MD5::update(const int*, size_t)': 53 9 C:\Users\余伟杰\Desktop\哈希算法.cpp [Error] 'uint32_t' was not declared in this scope 55 9 C:\Users\余伟杰\Desktop\哈希算法.cpp [Error] 'index' was not declared in this scope 55 18 C:\Users\余伟杰\Desktop\哈希算法.cpp [Error] 'count' was not declared in this scope 60 9 C:\Users\余伟杰\Desktop\哈希算法.cpp [Error] 'partLen' was not declared in this scope 62 21 C:\Users\余伟杰\Desktop\哈希算法.cpp [Error] 'buffer' was not declared in this scope 64 18 C:\Users\余伟杰\Desktop\哈希算法.cpp [Error] 'i' was not declared in this scope 69 13 C:\Users\余伟杰\Desktop\哈希算法.cpp [Error] 'i' was not declared in this scope 71 17 C:\Users\余伟杰\Desktop\哈希算法.cpp [Error] 'buffer' was not declared in this scope 71 39 C:\Users\余伟杰\Desktop\哈希算法.cpp [Error] 'i' was not declared in this scope C:\Users\余伟杰\Desktop\哈希算法.cpp In member function 'std::string MD5::final()': 76 9 C:\Users\余伟杰\Desktop\哈希算法.cpp [Error] 'uint8_t' was not declared in this scope 77 9 C:\Users\余伟杰\Desktop\哈希算法.cpp [Error] 'uint32_t' was not declared in this scope 78 17 C:\Users\余伟杰\Desktop\哈希算法.cpp [Error] expected ';' before 'digest' 79 22 C:\Users\余伟杰\Desktop\哈希算法.cpp [Error] 'uint8_t' does not name a type 82 16 C:\Users\余伟杰\Desktop\哈希算法.cpp [Error] 'count' was not declared in this scope 82 23 C:\Users\余伟杰\Desktop\哈希算法.cpp [Error] 'bits' was not declared in this scope 85 9 C:\Users\余伟杰\Desktop\哈希算法.cpp [Error] 'index' was not declared in this scope 86 9 C:\Users\余伟杰\Desktop\哈希算法.cpp [Error] 'padLen' was not declared in this scope 87 16 C:\Users\余伟杰\Desktop\哈希算法.cpp [Error] 'PADDING' was not declared in this scope 93 16 C:\Users\余伟杰\Desktop\哈希算法.cpp [Error] 'state' was not declared in this scope 93 23 C:\Users\余伟杰\Desktop\哈希算法.cpp [Error] 'digest' was not declared in this scope C:\Users\余伟杰\Desktop\哈希算法.cpp In member function 'void MD5::transform(const int*)': 106 9 C:\Users\余伟杰\Desktop\哈希算法.cpp [Error] 'uint32_t' was not declared in this scope 107 18 C:\Users\余伟杰\Desktop\哈希算法.cpp [Error] expected ';' before 'x' 109 23 C:\Users\余伟杰\Desktop\哈希算法.cpp [Error] 'x' was not declared in this scope 112 12 C:\Users\余伟杰\Desktop\哈希算法.cpp [Error] 'a' was not declared in this scope 112 15 C:\Users\余伟杰\Desktop\哈希算法.cpp [Error] 'b' was not declared in this scope 112 18 C:\Users\余伟杰\Desktop\哈希算法.cpp [Error] 'c' was not declared in this scope 112 21 C:\Users\余伟杰\Desktop\哈希算法.cpp [Error] 'd' was not declared in this scope 112 35 C:\Users\余伟杰\Desktop\哈希算法.cpp [Error] 'T' was not declared in this scope 112 39 C:\Users\余伟杰\Desktop\哈希算法.cpp [Error] 'FF' was not declared in this scope 122 40 C:\Users\余伟杰\Desktop\哈希算法.cpp [Error] 'GG' was not declared in this scope 132 40 C:\Users\余伟杰\Desktop\哈希算法.cpp [Error] 'HH' was not declared in this scope 142 40 C:\Users\余伟杰\Desktop\哈希算法.cpp [Error] 'II' was not declared in this scope 151 9 C:\Users\余伟杰\Desktop\哈希算法.cpp [Error] 'state' was not declared in this scope C:\Users\余伟杰\Desktop\哈希算法.cpp In static member function 'static void MD5::decode(const int*, int*, size_t)': 184 27 C:\Users\余伟杰\Desktop\哈希算法.cpp [Error] 'uint32_t' was not declared in this scope 184 36 C:\Users\余伟杰\Desktop\哈希算法.cpp [Error] expected ')' before 'input' C:\Users\余伟杰\Desktop\哈希算法.cpp In function 'int main()': 219 39 C:\Users\余伟杰\Desktop\哈希算法.cpp [Error] expected '>' before 'uint8_t' 219 39 C:\Users\余伟杰\Desktop\哈希算法.cpp [Error] expected '(' before 'uint8_t' 219 39 C:\Users\余伟杰\Desktop\哈希算法.cpp [Error] 'uint8_t' was not declared in this scope 219 47 C:\Users\余伟杰\Desktop\哈希算法.cpp [Error] expected primary-expression before '>' token 228 43 C:\Users\余伟杰\Desktop\哈希算法.cpp [Error] expected '>' before 'uint8_t' 228 43 C:\Users\余伟杰\Desktop\哈希算法.cpp [Error] expected '(' before 'uint8_t' 228 51 C:\Users\余伟杰\Desktop\哈希算法.cpp [Error] expected primary-expression before '>' token 232 43 C:\Users\余伟杰\Desktop\哈希算法.cpp [Error] expected '>' before 'uint8_t' 232 43 C:\Users\余伟杰\Desktop\哈希算法.cpp [Error] expected '(' before 'uint8_t' 232 51 C:\Users\余伟杰\Desktop\哈希算法.cpp [Error] expected primary-expression before '>' token 修改代码
最新发布
07-07
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值