Menu

Readline linking error

Help
apostenet2
2007-12-17
2012-07-26
  • apostenet2

    apostenet2 - 2007-12-17

    Hi,
    I have a problem when linking a program which is meant to use readline. I am disappointed.
    I try to compile under winXP with DevCpp 4.9.9.2, so mingw.
    I got developpers files containing headers and lib (static and import).
    I choosed to use static import.
    So I added to my makefile
    INCS=-Ipath_to_readline/include and
    LIB=path_to_readline/lib/libreadline.a path_to_readline/lib/libhistory.a

    but in this case, imports are not realized.
    I got the following errors :

    xxx.o(.text+0x6e9):xxx.c:451: undefined reference to _imp__readline' xxx.o(.text+0x71d):xxx.c:456: undefined reference to_imp__add_history'

    and other errors as characteristics as these.

    In looking into realine.h, I saw that without any declaration, preprocessor was considering that I wanted to use the dll. So I added following to compiler declaration:
    CC=gcc ${READLINE}
    READLINE=-DUSE_READLINE_STATIC

    After that, errors come from readline and history library imports :

    path_to_readline/lib/libreadline.a(vi_mode.o)(.text+0x3717):vi_mode.c: undefined reference to mbrtowc' path_to_readline/libreadline.a(vi_mode.o)(.text+0x3767):vi_mode.c: undefined reference towcrtomb'
    path_to_readline/readline/lib/libreadline.a(complete.o)(.text+0x1f72):complete.c: undefined reference to lstat64' path_to_readline/readline/lib/libreadline.a(complete.o)(.text+0x20bf):complete.c: undefined reference tostat64'
    ...
    path_to_readline/readline/lib/libreadline.a(complete.o)(.text+0x3040):complete.c: undefined reference to mbrlen' path_to_readline/readline/lib/libreadline.a(bind.o)(.text+0x3b9a):bind.c: undefined reference tostat64'
    etc

    As I looked previously to compile advices, I thought Perhaps I needed to link against ligw32c, what I done, but it didn't seem to change anything.

    Can anyone help me or give me a hint for where to search?
    I was already some hours searching on the net for these functions, but found nothing really consistent.
    They seem to be included in glibc under unix systems, what pushes into the direction of libgw32c.
    I saw references to msvcrt.dll, so I verified I have it (I was sure, but doubt is whispering).

    thank you in advance.

     
    • GnuWin

      GnuWin - 2007-12-17

      You must also link with libmsvcp60 and libgw32c, and these libraries must be after libreadline in the linking statement; so e.g.

      LIBS = -lreadline -lmsvcp60 -lgw32c

       
      • apostenet2

        apostenet2 - 2007-12-18

        Thank you very much :-D
        Now I am very happy, because I see readline partially working.
        But I have still things to understand.
        I inferred rl_attempted_completion_function like in the example given in the documentation (fileman.c), but i cannot see it called.
        I tried to print things to screen to see if it was returning null but none of them was printed, as if function was never entered. Whereas I can print completion function pointer adress.
        Can you see a possible cause of this?
        Is there a way to see that there is a bad adress. Normally, if it was, should it not cause a segmentation fault or something?
        I also tried to compile my code under cygwin.
        There, I get undefined references for __imp_errno.
        Is there a particular import to add for cygwin.
        I hope it is not too confused.
        Thank you once again.

         
    • apostenet2

      apostenet2 - 2007-12-18

      Just a precision on the last message I posted yesterday:
      program make file completion without any problem. That is part of the "partially working" I mentionned.
      I tried another thing to test call to rl_attempted_completion_function:
      just in one of the commands that can be launched, I put it with a constant substring of many commmands and its length, then gathered and printed results. It seems to work. At least I see custom completer called and results consistent.

      char **testchar;

      testchar = rl_attempted_completion_function("start_", 0, 5);
      if (testchar == NULL) printf("testchar NULL\n");
      else
      {
      uc = 0;
      while((testchar[uc] && testchar[uc][0]) && uc < 255)
      {
      printf("uc: %i\n testchar[uc] : %s\n", uc, testchar[uc]);
      uc++;
      }
      }

      So I am happy to see it working but I don't undestand why it is not called on completion event whereas the pointer is correct and the return not NULL with standard entry.
      Could I have missed something?

       
    • apostenet2

      apostenet2 - 2007-12-19

      Hi,
      I don't understand. As I didn't manage to do my completer called, I tried to compile code provided in readline doc (fileman).
      After few changes, code compiled properly. But even in this case, the custom completer (for command list) is not called and only file completion is done.
      Am I missing something?
      I would really like to have command completion working because I find it is a nice feature. And that is not possible to make the link in other ways than with rl_completion_entry_function or rl_attempted_completion_function.

       
    • apostenet2

      apostenet2 - 2007-12-20

      Hi,
      I eventually found the reason. When trying to compile under cygwin (with cygreadline now) I had a segmentation fault. So I realized during debug that my command array that I built manually was not enough large compared to what was needed (malloc too small). When I have had this problem corrected, It worked also under gnuwin32 readline. Arf, it was quite a dumb problem.
      Excuse me for so long messages and thank you very much for the help.

       
    • apostenet2

      apostenet2 - 2008-06-26

      Hi,
      Now, I tried to link the same program under ms visual cpp 6.0. Don't really know if this is supported because all developpement advices are related to mingw gcc (but I thought it was rather more for building readline executables themselves).
      So I done a nmake file.
      I use import libraries because only the dll is avalaible in precompiled format (not the static library for ms vcpp, I thought it was...but Im am not sure anymore).
      LIBS = readline/lib/readline.lib readline/lib/history.lib
      with includes :
      INCS = -Ireadline/include
      But I don't manage to make the things compiled.

      See errors :
      readline/include\readline/readline.h(356) : error C2375: 'rl_make_bare_keymap' : redefinition; different linkage
      readline/include\readline/keymaps.h(74) : see declaration of 'rl_make_bare_keymap'
      readline/include\readline/readline.h(357) : error C2375: 'rl_copy_keymap' : redefinition; different linkage
      readline/include\readline/keymaps.h(77) : see declaration of 'rl_copy_keymap'
      readline/include\readline/readline.h(358) : error C2375: 'rl_make_keymap' : redefinition; different linkage
      readline/include\readline/keymaps.h(82) : see declaration of 'rl_make_keymap'
      readline/include\readline/readline.h(359) : error C2375: 'rl_discard_keymap' : redefinition; different linkage
      readline/include\readline/keymaps.h(85) : see declaration of 'rl_discard_keymap'
      readline/include\readline/readline.h(361) : error C2375: 'rl_get_keymap_by_name' : redefinition; different linkage
      readline/include\readline/keymaps.h(91) : see declaration of 'rl_get_keymap_by_name'
      readline/include\readline/readline.h(363) : error C2375: 'rl_set_keymap' : redefinition; different linkage
      readline/include\readline/keymaps.h(97) : see declaration of 'rl_set_keymap'
      readline/include\readline/readline.h(364) : error C2375: 'rl_get_keymap' : redefinition; different linkage
      readline/include\readline/keymaps.h(94) : see declaration of 'rl_get_keymap'
      NMAKE : fatal error U1077: 'cl' : return code '0x2'

      I thought these were the import libraries. But I found something strange.
      I took the files from the developper file archives.
      I saw in readline.h header that not specifying anything was equivalent to specifying USE_READLINE_DLL. That means define links to import libraries with __declspec(dllimport) (plus extern keyword I was not waiting for...). As it wasn't working, I tried to specify to use static library :
      CC = cl
      CFLAGS = $(MACROS) $(INCS) -c
      MACROS = -DWIN32 -D_WIN32 -D_WINDOWS -D_WIN32_WINDOWS=0x501 $(READLINE)
      READLINE = -DUSE_READLINE_STATIC
      Then it worked (but only with 0.5-1, not with 0.5).
      Could someone give me some comprehension hints about that?
      I would be gratefull