mouse07410 / asn1c

The ASN.1 Compiler
http://lionet.info/asn1c/
BSD 2-Clause "Simplified" License
93 stars 70 forks source link

ImportError: undefined symbols in Shared Library #188

Closed anvigo12 closed 3 months ago

anvigo12 commented 4 months ago

Thank you for all your great work, this ASN1C project has been invaluable to me so far! however, I am very new to ASN1C and this is my first project where I want to create a Python library using SWIG from the ASN definition files below.

options used to generate code: -pdu=all -fcompound-names -fincludes-quoted -findirect-choice -funnamed-unions -no-gen-XER -no-gen-JER -no-gen-OER -no-gen-example -no-gen-random-fill

ETSI-ITS-CDD.asn (https://forge.etsi.org/rep/ITS/asn1/cdd_ts102894_2/-/blob/v2.1.1/docs/ETSI-ITS-CDD.md#user-content-objectperceptionquality) CPM-OriginatingStationContainers.asn (https://forge.etsi.org/rep/ITS/asn1/cpm_ts103324/-/raw/v2.1.1/asn/CPM-OriginatingStationContainers.asn) CPM-SensorInformationContainer.asn (https://forge.etsi.org/rep/ITS/asn1/cpm_ts103324/-/raw/v2.1.1/asn/CPM-SensorInformationContainer.asn) CPM-PerceptionRegionContainer.asn (https://forge.etsi.org/rep/ITS/asn1/cpm_ts103324/-/raw/v2.1.1/asn/CPM-PerceptionRegionContainer.asn) CPM-PerceivedObjectContainer.asn (https://forge.etsi.org/rep/ITS/asn1/cpm_ts103324/-/raw/v2.1.1/asn/CPM-PerceivedObjectContainer.asn) CPM-PDU-Descriptions.asn (https://forge.etsi.org/rep/ITS/asn1/cpm_ts103324/-/raw/v2.1.1/asn/CPM-PDU-Descriptions.asn)

I used SWIG to create a Python file and a cxx wrap file which I was able to compile into a shared library along with all other C source files generated by this asn1c compiler. The problem is that there are missing symbols in this shared library which I assume need to be resolved during runtime. Missing symbols are for:

_constraint _decode_aper _decode_ber _decode_uper _encode_aper _encode_der _encode_uper _free _print I have tried to compile C source files into a shared runtime library from the skeletons folder using 'gcc -c -fPIC -I. *.c' but it failed. I tried to compile a single C source file into an object file using the command 'gcc -c -fPIC asn_application.c' and got below errors: In file included from ./constr_TYPE.h:39, from ./asn_application.h:14, from ./asn_internal.h:14, from asn_application.c:5: ./der_encoder.h:25:27: error: unknown type name ‘asn_app_consume_bytes_f’ 25 | asn_app_consume_bytes_f *consume_bytes_cb, | ^~~~~~~~~~~~~~~~~~~~~~~ ./der_encoder.h:44:24: error: unknown type name ‘asn_app_consume_bytes_f’ 44 | ber_tlv_tag_t tag, asn_app_consume_bytes_f *consume_bytes_cb, /* Callback */ | ^~~~~~~~~~~~~~~~~~~~~~~ ./der_encoder.h:61:24: error: unknown type name ‘asn_app_consume_bytes_f’ 61 | asn_app_consume_bytes_f *consume_bytes_cb, | ^~~~~~~~~~~~~~~~~~~~~~~ In file included from ./constr_TYPE.h:47, from ./asn_application.h:14, from ./asn_internal.h:14, from asn_application.c:5: ./xer_encoder.h:30:27: error: unknown type name ‘asn_app_consume_bytes_f’ 30 | asn_app_consume_bytes_f *consume_bytes_cb, | ^~~~~~~~~~~~~~~~~~~~~~~ ./xer_encoder.h:75:5: error: unknown type name ‘asn_app_consume_bytes_f’ 75 | asn_app_consume_bytes_f *consume_bytes_cb, /* Callback */ | ^~~~~~~~~~~~~~~~~~~~~~~ In file included from ./constr_TYPE.h:55, from ./asn_application.h:14, from ./asn_internal.h:14, from asn_application.c:5: ./jer_encoder.h:32:27: error: unknown type name ‘asn_app_consume_bytes_f’ 32 | asn_app_consume_bytes_f *consume_bytes_cb, | ^~~~~~~~~~~~~~~~~~~~~~~ ./jer_encoder.h:77:5: error: unknown type name ‘asn_app_consume_bytes_f’ 77 | asn_app_consume_bytes_f *consume_bytes_cb, /* Callback */ | ^~~~~~~~~~~~~~~~~~~~~~~ In file included from ./constr_TYPE.h:69, from ./asn_application.h:14, from ./asn_internal.h:14, from asn_application.c:5: ./constraints.h:43:5: error: unknown type name ‘asn_app_constraint_failed_f’ 43 | asn_app_constraint_failed_f *optional_callback, /* Log the error */ | ^~~~~~~~~~~~~~~~~~~~~~~~~~~ ./constraints.h:51:1: error: unknown type name ‘asn_constr_check_f’ 51 | asn_constr_check_f asn_generic_no_constraint; /* No constraint whatsoever */ | ^~~~~~~~~~~~~~~~~~ ./constraints.h:52:1: error: unknown type name ‘asn_constr_check_f’ 52 | asn_constr_check_f asn_generic_unknown_constraint; /* Not fully supported */ | ^~~~~~~~~~~~~~~~~~ In file included from ./oer_decoder.h:9, from ./constr_TYPE.h:78, from ./asn_application.h:14, from ./asn_internal.h:14, from asn_application.c:5: ./oer_support.h:40:45: error: unknown type name ‘asn_app_consume_bytes_f’ 40 | ssize_t oer_serialize_length(size_t length, asn_app_consume_bytes_f *cb, void *app_key); | ^~~~~~~~~~~~~~~~~~~~~~~ In file included from ./constr_TYPE.h:79, from ./asn_application.h:14, from ./asn_internal.h:14, from asn_application.c:5: ./oer_encoder.h:24:27: error: unknown type name ‘asn_app_consume_bytes_f’ 24 | asn_app_consume_bytes_f *consume_bytes_cb, | ^~~~~~~~~~~~~~~~~~~~~~~ ./oer_encoder.h:44:5: error: unknown type name ‘asn_app_consume_bytes_f’ 44 | asn_app_consume_bytes_f *consume_bytes_cb, /* Callback */ | ^~~~~~~~~~~~~~~~~~~~~~~ ./oer_encoder.h:57:27: error: unknown type name ‘asn_app_consume_bytes_f’ 57 | asn_app_consume_bytes_f *consume_bytes_cb, | ^~~~~~~~~~~~~~~~~~~~~~~ ./oer_encoder.h:64:1: error: unknown type name ‘oer_type_encoder_f’; did you mean ‘per_type_encoder_f’? 64 | oer_type_encoder_f oer_encode_primitive; | ^~~~~~~~~~~~~~~~~~ | per_type_encoder_f In file included from ./asn_application.h:14, from ./asn_internal.h:14, from asn_application.c:5: ./constr_TYPE.h:133:5: error: unknown type name ‘asn_app_consume_bytes_f’ 133 | asn_app_consume_bytes_f *callback, void *app_key); | ^~~~~~~~~~~~~~~~~~~~~~~ ./constr_TYPE.h:186:5: error: unknown type name ‘asn_struct_print_f’ 186 | asn_struct_print_f *print_struct; /* Human readable output */ | ^~~~~~~~~~~~~~~~~~ ./constr_TYPE.h:190:5: error: unknown type name ‘der_type_encoder_f’ 190 | der_type_encoder_f *der_encoder; /* Canonical DER encoder */ | ^~~~~~~~~~~~~~~~~~ ./constr_TYPE.h:192:5: error: unknown type name ‘xer_type_encoder_f’ 192 | xer_type_encoder_f *xer_encoder; /* [Canonical] XER encoder */ | ^~~~~~~~~~~~~~~~~~ ./constr_TYPE.h:194:5: error: unknown type name ‘jer_type_encoder_f’ 194 | jer_type_encoder_f *jer_encoder; /* Generic JER encoder */ | ^~~~~~~~~~~~~~~~~~ ./constr_TYPE.h:196:5: error: unknown type name ‘oer_type_encoder_f’ 196 | oer_type_encoder_f *oer_encoder; /* Canonical OER encoder */ | ^~~~~~~~~~~~~~~~~~ ./constr_TYPE.h:215:5: error: unknown type name ‘asn_constr_check_f’ 215 | asn_constr_check_f *general_constraints; | ^~~~~~~~~~~~~~~~~~ asn_application.c: In function ‘asn_encode_internal’: asn_application.c:250:16: error: called object is not a function or function pointer 250 | if(td->op->print_struct(td, sptr, 1, callback_count_bytes_cb, | ^~ asn_application.c:279:18: warning: implicit declaration of function ‘der_encode’; did you mean ‘aper_encode’? [-Wimplicit-function-declaration] 279 | er = der_encode(td, sptr, callback, callback_key); | ^~~~~~~~~~ | aper_encode asn_application.c:279:18: error: incompatible types when assigning to type ‘asn_enc_rval_t’ {aka ‘struct asn_enc_rval_s’} from type ‘int’ asn_application.c:310:18: warning: implicit declaration of function ‘oer_encode’; did you mean ‘aper_encode’? [-Wimplicit-function-declaration] 310 | er = oer_encode(td, sptr, callback, callback_key); | ^~~~~~~~~~ | aper_encode asn_application.c:310:18: error: incompatible types when assigning to type ‘asn_enc_rval_t’ {aka ‘struct asn_enc_rval_s’} from type ‘int’ asn_application.c:416:18: warning: implicit declaration of function ‘xer_encode’; did you mean ‘aper_encode’? [-Wimplicit-function-declaration] 416 | er = xer_encode(td, sptr, xer_flags, callback, callback_key); | ^~~~~~~~~~ | aper_encode asn_application.c:416:18: error: incompatible types when assigning to type ‘asn_enc_rval_t’ {aka ‘struct asn_enc_rval_s’} from type ‘int’ asn_application.c:446:18: warning: implicit declaration of function ‘jer_encode’; did you mean ‘aper_encode’? [-Wimplicit-function-declaration] 446 | er = jer_encode(td, sptr, jer_flags, callback, callback_key); | ^~~~~~~~~~ | aper_encode asn_application.c:446:18: error: incompatible types when assigning to type ‘asn_enc_rval_t’ {aka ‘struct asn_enc_rval_s’} from type ‘int’ When I checked in the asn_application.h file, there is the definition of 'asn_app_consume_bytes_f' but I don't know why it says error: unknown type name ‘asn_app_consume_bytes_f’ I have also attached ASN file links, log output files for module generation and missing symbols using the 'nm' tool. What should I do to resolve these missing symbols? Please let me know if you need more information, I am stuck at this point and need help. Thank you again! [1nmsymbols.txt](https://github.com/mouse07410/asn1c/files/14893010/1nmsymbols.txt) [skeletonsRuntimeLibraryLog.txt](https://github.com/mouse07410/asn1c/files/14893011/skeletonsRuntimeLibraryLog.txt) [1moduleBuild.log](https://github.com/mouse07410/asn1c/files/14893013/1moduleBuild.log) [1undefinedSymbols.txt](https://github.com/mouse07410/asn1c/files/14893015/1undefinedSymbols.txt)
mouse07410 commented 4 months ago

I m truly sorry, but I've neither time nor (frankly) desire to wade through the huge ASN.1 files you listed. However:

this is my first project where I want to create a Python library using SWIG from the ASN definition files

Based on the above, you don't have any experience with the work-path you're trying - and yet you chose to dive in the "full project". That's next to hopeless, IMHO.

What I'd recommend is pick a simple ASN.1 file, maybe something like

ImagesModule DEFINITIONS ::= BEGIN

  Image ::= SEQUENCE
  {
    data  OCTET STRING (SIZE (40..81920)),
    count INTEGER (0..81920),
  }

END

and try to work out the flow with that one first.

Also, the normal result of asn1c is a set of source files plus makefiles that allow you to actually build a library.

Start there, and let's debug your workflow first. Maybe others here could help you with the "big" project.

anvigo12 commented 4 months ago

Thanks a lot @mouse07410 🙏

mouse07410 commented 4 months ago

@anvigo12 you're welcome - and please feel free to post successes and/or problems getting the simplified example above to work. Once you get that figured out and done - the likelihood of success in your "big" project would be much higher.