Monolithic build of static library

Marius Gerbershagen marius.gerbershagen at gmail.com
Tue Dec 1 19:15:15 UTC 2020


The generated library does indeed contain all systems that your library 
contains on. The undefined references are init functions, which need to 
be called via ecl_init_module after cl_boot to initialize the compiled 
libraries (see 
https://common-lisp.net/project/ecl/static/manual/System-building.html#Build-it-as-shared-library-and-use-in-C 
for more details).

Since you didn't specify an explicit init name yourself, init functions 
are automatically generated for each system contained in the final 
library. When compiling a monolithic library, it is preferable to 
specify an explicit init name yourself, for example as

(asdf:make-build :embedded-console :type :static-library :move-here 
#P"/my/output/dir" :monolithic t :init-name "init_lib_embedded_console")

and then invoke it using

extern void init_lib_embedded_console(cl_object);
/* ... */
cl_boot(argc, argv);
ecl_init_module(NULL, init_lib_embedded_console);

Am 29.11.20 um 13:17 schrieb Иван Трусков:
> Hello. I am trying to make a library that makes use of 'STR' package and 
> link it into my C program.
> I presumed that using :monolithic t flag would result in the static 
> library that contained all systems my library depends on. However it 
> seems that is not the case.
> 
> Here is my .asd file:
> 
> (defsystem "embedded-console"
>    :description "embedded console - ECL functions for smart snake game"
>    :author "Ivan Truskov <trus19 at gmail.com <mailto:trus19 at gmail.com>>"
>    :components ((:file "embedded-console"))
>    :depends-on ("str"))
> 
> I am compiling the library with command:
> 
> ecl -norc -eval '(require :ecl-quicklisp)'
>                      -eval '(push \"/my/src/dir/\" asdf:*central-registry*)'
>                      -eval '(asdf:make-build :embedded-console :type 
> :static-library :move-here \#P\"/my/output/dir}\" :monolithic t )'
>                      -eval '(quit)'
> 
> However, when i try to link with resulting library, this is what i get:
> 
> ... undefined reference to `init_lib_CL_PPCRE'
> ... undefined reference to `init_lib_BASE'
> ... undefined reference to `init_lib_CL_UNICODE'
> ... undefined reference to `init_lib_CL_PPCRE_UNICODE'
> ... undefined reference to `init_lib_CL_CHANGE_CASE'
> ... undefined reference to `init_lib_STR'
> ... undefined reference to `init_lib_EMBEDDED_CONSOLE'
> 
> And indeed, when i run nm over the built file 
> embedded-console--all-systems.a, this is output:
> 
> eclinitVtJU9J.o:
> 0000000000000000 b Cblock.10857
>                   U cl_boot
>                   U cl_symbols
>                   U _ecl_frs_push
>                   U ecl_init_module
>                   U ecl_make_codeblock
>                   U ecl_process_env
>                   U _GLOBAL_OFFSET_TABLE_
>                   U init_lib_BASE
>                   U init_lib_CL_CHANGE_CASE
>                   U init_lib_CL_PPCRE
>                   U init_lib_CL_PPCRE_UNICODE
>                   U init_lib_CL_UNICODE
>                   U init_lib_EMBEDDED_CONSOLE
> 0000000000000000 T init_lib_EMBEDDED_CONSOLE__ALL_SYSTEMS
>                   U init_lib_STR
> 0000000000000110 T main_lib_EMBEDDED_CONSOLE__ALL_SYSTEMS
>                   U _setjmp
> nm: cl-ppcre.a: File format not recognized
> nm: base.a: File format not recognized
> nm: cl-unicode.a: File format not recognized
> nm: cl-ppcre-unicode.a: File format not recognized
> nm: cl-change-case.a: File format not recognized
> nm: str.a: File format not recognized
> nm: embedded-console.a: File format not recognized
> 
> What am i doing wrong? What should i change to get static library 
> containing all systems i am intending to use (and maybe only them, if 
> possible)?




More information about the ecl-devel mailing list