我在Windows中编译cryptopp项目时遇到以下错误。
C:\Users\Sajith\AppData\Local\Temp\ccxq8O8x.o:aescbc.cpp:(.text$_ZN8CryptoPP20AllocatorWithCleanupIhLb1EE8allocateEjPKv[
__ZN8CryptoPP20AllocatorWithCleanupIhLb1EE8allocateEjPKv]+0x2e): undefined reference to `CryptoPP::AlignedAllocate(unsig
ned int)'
C:\Users\Sajith\AppData\Local\Temp\ccxq8O8x.o:aescbc.cpp:(.text$_ZN8CryptoPP20AllocatorWithCleanupIhLb1EE10deallocateEPv
j[__ZN8CryptoPP20AllocatorWithCleanupIhLb1EE10deallocateEPvj]+0x28): undefined reference to `CryptoPP::AlignedDeallocate
(void*)'
collect2.exe: error: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
下面是我的编译命令:
mingw32-g++.exe -o .\aestest2.exe .\aescbc.cpp -I "C:\cryptopp\Include" -L "C:\cryptopp\Lib" -lcryptopp
Run Code Online (Sandbox Code Playgroud)
我的libcryptopp.a位于C:\cryptopp\Lib
我试图找出AlignedDeallocate声明在哪里的地方,但我找不到。
引发此错误的程序部分如下:
try
{
cout << "plain text: " << plain << endl;
CBC_Mode< AES >::Encryption e;
e.SetKeyWithIV(key, sizeof(key), iv);
// The StreamTransformationFilter removes
// padding as required.
StringSource s(plain, true,
new StreamTransformationFilter(e,
new StringSink(cipher)
) // StreamTransformationFilter
); // StringSource
#if 0 …Run Code Online (Sandbox Code Playgroud) 编译器可以选择在内存中使用单个副本表示所有相同的字符串文字.例如 :
/*Case 1*/
char *s1 = "foo";
char *s2 = "foo";
printf("s1 points to : %p\n", s1);
printf("s2 points to : %p\n", s2);
Run Code Online (Sandbox Code Playgroud)
给
s1 points to : 0x40063c
s2 points to : 0x40063c
Run Code Online (Sandbox Code Playgroud)
然而,
/*Case 2*/
char *s1 = "foo";
char *s2 = (char[]){'f', 'o', 'o', '\0'};
printf("s1 points to : %p\n", s1);
printf("s2 points to : %p\n", s2);
Run Code Online (Sandbox Code Playgroud)
给
s1 points to : 0x40070c
s2 points to : 0x7ffe2866fcd0
Run Code Online (Sandbox Code Playgroud)
这是完全可以的,因为s1指向一些不变的东西,而s2则没有.
但是,有没有办法告诉编译器,在case2中,我们实际上希望将s2指向某些常量数据 - 但保持其声明样式 - 以便如果s2指向的数据与s1指向的数据相同,编译器可以在存储器中继续进行单个数据副本.
我试过了
const …Run Code Online (Sandbox Code Playgroud) 背景
IIRC,从版本2.0开始, C++将单字符常量存储为type char和NOT int.但是在Release 2.0之前的声明就像
cout<<'A'
Run Code Online (Sandbox Code Playgroud)
是有问题的,因为它显示'A'的ASCII值,即65,而:
char ch='A';
cout<<ch;
Run Code Online (Sandbox Code Playgroud)
会显示正确的值,即'A'.
由于问题已在版本2.0中得到纠正.我相信cout.put()失去了它的优势cout<<.
题
是否有任何其他理由提出cout.put()了cout<<用于打印字符?
背景
这篇文章说:
命令替换扩展为命令的输出。这些命令在子shell中执行。
但是bash手册subshell在其命令替换部分中什么都没有说。
我的测试如下
$ ps
PID TTY TIME CMD
26483 pts/25 00:00:00 bash
26866 pts/25 00:00:00 ps
$ hpid="$(ps | grep bash)"
$ echo "$hpid"
26483 pts/25 00:00:00 bash
26899 pts/25 00:00:00 bash
Run Code Online (Sandbox Code Playgroud)
显示了在命令替换期间生成了一个带有pid 26899的新shell。此时,我更改了PATH环境变量。
$ PATH="/some/rogue/path"
Run Code Online (Sandbox Code Playgroud)
做以下事情:
VAR="$(echo "Do|Die" | cut -d"|" -f 2)"
Run Code Online (Sandbox Code Playgroud)
并得到以下错误:
Command 'cut' is available in '/usr/bin/cut'
The command could not be located because '/usr/bin' is not included in the PATH environment variable.
cut: command …Run Code Online (Sandbox Code Playgroud) 我正在使用Mac机,并且需要连接到远程机(Linux)并删除远程机中目录的内容。尝试使用
ssh root@server-address rm -rf testdir
Run Code Online (Sandbox Code Playgroud)
它提示我在终端中输入密码。有什么方法可以删除目录的内容,而无需手动输入远程计算机的密码?我想使用shell脚本来做到这一点。由于我是shell的新手,因此不胜感激。
假设我有x作为字符串参数的宏#define a(x) "this is x".如果我打电话给a(test),字符串形成应该是"this is test".
以下是/usr/include/x86_64-linux-gnu/gnu/stubs-32.h文件的内容:
#include <bits/wordsize.h>
#if __WORDSIZE == 32
# include <gnu/stubs-32.h>
#elif __WORDSIZE == 64
# include <gnu/stubs-64.h>
#else
# error "unexpected value for __WORDSIZE macro"
#endif
Run Code Online (Sandbox Code Playgroud)
我在64位计算机上,所以
#include<stdio.h>
main()
{
printf("Word size : %d\n",__WORDSIZE);
}
Run Code Online (Sandbox Code Playgroud)
是
Word size : 64
Run Code Online (Sandbox Code Playgroud)
因此,这里的问题是系统变量__WORDSIZE的作用是什么?我正在开发32位应用程序(使用mingw 32位编译器),并且由于我的__WORDSIZE是64位,因此该文件/usr/include/x86_64-linux-gnu/gnu/stubs-32.h最终导致包含/usr/include/x86_64-linux-gnu/gnu/stubs-64.h。我对这部分感到困惑。此操作的后果是什么?这是正常现象/usr/include/x86_64-linux-gnu/gnu/stubs-32.h吗?如果没有,我该如何强行纳入?
先感谢您。
我正在使用一个 shell 脚本,其中包括以下两个选项:
OPT1=false
OPT2=false
while getopts "Alfqru:p:x:s:a:b:c:t:z:" opt; do
case $opt in
A) OPT1=true
;;
a) OPT2=true
;;
esac
done
Run Code Online (Sandbox Code Playgroud)
现在,当我使用 -a 或 -A 运行此脚本时,OPT1 设置为 true,OPT2 设置为 false。当我颠倒两种情况时,情况正好相反。我想要的是 -A 使 OPT1 为真,-a 使 OPT2 为真。那么如何使这些选项区分大小写呢?
下面的代码只是我稍后使用的一个例子:
/* Extract digits from an integer and store in an array in reverse order*/
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
int oct=316;
int* array=malloc(0*sizeof(int*)); //Step 1
int* temp;
size_t size=0;
while(oct/10>0 || oct%10>0){
temp=realloc(array,++size*sizeof(int)); // Step2 requires Step1
if(temp==NULL){
printf("Can't reallocate memory");
exit(-1);
}
else{
array=temp;
}
array[size-1]=oct%10;
oct/=10;
}
for(int i=0;i<size;i++)
printf("%d\n",array[i]);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
realloc参考文献[1]指出:
重新分配给定的内存区域.它必须先由malloc(),calloc(),realloc()分配...
最初我编译了没有step1的代码,并且在运行它时我遇到了分段错误.然后我包括step1,现在代码编译得很好.我不想没有找到一个整数存储,所以我使用了大小分配一些空间零用malloc的.然而,malloc参考文献[2]指出:
如果size为零,则返回值取决于特定的库实现(它可能是也可能不是空指针),但返回的指针不应被解除引用.
现在,我怀疑我的实现是否可移植.我该如何解决这个问题?
我尝试过,int* array=NULL;但我遇到了分段错误.
考虑
//#include stuff
const int x=5;
.
.
int main()
{
static int var=x;
.
.
}
Run Code Online (Sandbox Code Playgroud)
如果我理解正确,
static int var;单独设置var为零并且static int var=x;也将首先设置var为初始化zero.static int var=x;一个常量表达式初始化,其中IIRC在零初始化之后完成.是静态变量initialized multiple times- 尽管这个短语与自身矛盾吗?
下面的代码在一个程序中运行良好,并在另一个程序中导致总线错误
char *temp1;
temp1=(char*)malloc(2);
for(b=3;b>=0;b--)
{
sprintf(temp1,"%02x",s_ip[b]);
string temp2(temp1);
temp.append(temp2);
}
Run Code Online (Sandbox Code Playgroud)
s_ip [b]的类型为byte,temp是一个字符串.导致此总线错误的原因是什么?而且,这种奇怪行为的原因是什么?