我正在尝试创建简单的 DER 解码器 - 控制台应用程序,仅输出给定数据结构的内容(以 DER 格式编码,例如 这个)。
我在运行此示例时遇到问题: A ''矩形'' 解码器 。
我正在尝试使用 MSVC 编译它,但在 #include
和 #include
方面遇到问题。此外,类型 ssize_t
未定义。
这是我现在所做的:
1. 在 Online ASN.1 Compiler 中,我将此代码粘贴到文本字段中:
RectangleModule1 DEFINITIONS ::=
BEGIN
Rectangle ::= SEQUENCE {
height INTEGER,
width INTEGER
}
END
2. 我选择了 “使用本机机器类型”和“生成 PER 支持”选项。
3.它“编译正常”,所以我下载了该输出.tgz
4. 在 Visual Studio 2010 中创建空项目,拖放从此 .tgz
提取的源文件
5. 将附加包含目录设置为ASN1C的“骨骼”目录
6. 尝试构建它。
我缺少什么?
任何帮助将不胜感激
I'm trying to create simple DER decoder - console application that just outputs content of given data structure (encoded in DER format, like this one).
I have problems with running this example: A ''Rectangle'' Decoder .
I'm trying to compile it with MSVC and I have problems with #include <inttypes.h>
and #include <netinet/in.h>
. Also type ssize_t
is undefined.
Here's what I've done for now:
1. At Online ASN.1 Compiler I pasted this code into textfield:
RectangleModule1 DEFINITIONS ::=
BEGIN
Rectangle ::= SEQUENCE {
height INTEGER,
width INTEGER
}
END
2. I selected "Use native machine types" and "Generate PER support" options.
3. It "Compiled OK" so I downloaded that output .tgz
4. Created empty project int Visual Studio 2010, drag-n-dropped source files extracted from this .tgz
5. Set additional include directory to "skeletons" directory of ASN1C
6. Tried to build it.
What am I missing?
Any help would be appreciated
发布评论
评论(2)
问题是ASN1C生成的代码必须修改才能用MSVC编译并在Windows环境中使用。
#include
应替换为#define ssize_t SSIZE_T
#include
应替换带有#include
inline
应从定义在中的static
函数中删除asn_internal.h
之后,一切正常;)
The problem is that code generated by ASN1C must be modified in order to compile it with MSVC and to use it in Windows environment.
#include <inttypes.h>
should be replaced with#define ssize_t SSIZE_T
#include <netinet/in.h>
should be replaced with#include <Winsock2.h>
inline
should be removed fromstatic
functions defined inasn_internal.h
After that, everything works fine ;)
确保您有正确的 ASN 定义文件。然后转到链接
http://lionet.info/asn1c/asn1c.cgi
将您的 ASN 定义粘贴到给定窗口中。按“继续 ASN.1 编译”按钮。如果出现任何编译错误,请纠正这些错误。编译成功后,它将生成解码器的代码。尝试一下它的好处。
Make sure that you have a correct ASN defintion file. Then go to link
http://lionet.info/asn1c/asn1c.cgi
paste your ASN definition in the given window. Press the button "Proceed with ASN.1 compilation". If you get any compilation error rectify those. After the compilation is successful it will generate the code for your decoder. Give it a try its good.