【发布时间】:2012-05-24 08:05:35
【问题描述】:
我使用 openssl 编写了一个解密函数,我在一个独立程序中进行了测试,它运行良好。但是这个功能是一个巨大项目的一部分,所以它必须包含在那个程序中。 为了执行我的独立程序,我使用了以下运行良好的命令:
cc -c aaa.c -I/usr/local/ssl/include
gcc -o aaa aaa.o -I/usr/local/ssl/include -L/usr/local/ssl/lib -lcrypto -lm
./aaa
我已经为我的主程序制作了一个makefile,这个函数将在其中被调用。
这两个程序单独运行都很好,但是当我在我的程序中插入函数的定义时,它给了我在 openssl 头文件之一(即 des.h)中的那些变量的错误。 我使用了一些 DES_cblock 类型的变量:
typedef unsigned char DES_cblock[8];
还有另一种结构,定义如下:
typedef struct DES_ks
{
union
{
DES_cblock cblock;
DES_LONG deslong[2];
}ks[16];
} DES_key_schedule;
我已经在我的程序中像这样使用了这个结构
DES_key_schedule keysched1,keysched2,keysched3;
但它没有识别这些变量。而且由于在我执行独立程序时没有这样的错误,这意味着我无法在主程序中正确链接库文件。我如何使这项工作。 这些是我得到的错误:
Syntax error at line 1399, column 16,file/export/home/jayesho/src/custom/FRB/tgl_frbsenddata.ec:
Error at line 1399, column 16 in file /export/home/jayesho/src/custom/FRB/tgl_fr
bsenddata.ec
DES_cblock hex_key1,hex_key2,hex_key3,hex_ivec,iv;
...............1
PCC-S-02201, Encountered the symbol "hex_key1" when expecting one of the followi
ng:
; , = : ( [ * ? | & < > + - / % . ^ *= /= %= += -= <<= >>=
&&= ||= ^= | & == != <= >= << >> ++ -- ->
The symbol ";" was substituted for "hex_key1" to continue.
Syntax error at line 1402, column 22, file /export/home/jayesho/src/custom/FRB/tgl_frbsenddata.ec:
Error at line 1402, column 22 in file /export/home/jayesho/src/custom/FRB/tgl_fr
bsenddata.ec
DES_key_schedule keysched1,keysched2,keysched3;
.....................1
PCC-S-02201, Encountered the symbol "keysched1" when expecting one of the follow
ing:
; , = : ( [ * ? | & < > + - / % . ^ *= /= %= += -= <<= >>=
&&= ||= ^= | & == != <= >= << >> ++ -- ->
The symbol ";" was substituted for "keysched1" to continue.
Syntax error at line 1436, column 38, file /export/home/jayesho/src/custom/FRB/tgl_frbsenddata.ec:
Error at line 1436, column 38 in file /export/home/jayesho/src/custom/FRB/tgl_fr
bsenddata.ec
if (DES_set_key_checked((C_Block *)hex_key1, &keysched1))
现在我只需要在我的程序中正确链接库文件以使整个程序运行。前面提到的头文件是 des.h,它是 openssl 的一部分。 我也尝试通过 -lcrypto 包含加密库 以前这个 des.h 没有被正确包含,但现在我成功地包含了 des.h 而没有错误。 也有人建议只包含头文件是不够的,它的实现文件也需要linked,所以我现在想知道如何包含和链接什么? 如何找到需要链接的链接名称。
【问题讨论】:
-
如果它在你手动编译而不是在你使用 make 时工作,那么你的 Makefile 中有一些奇怪的东西。你的 Makefile 里有什么?