• Weird compilation error

    From The Natural Philosopher@3:770/3 to All on Sun Aug 6 15:54:00 2023
    XPost: comp.os.linux.misc

    Its been a bad day for coding. Fixed one problem by writing debug code
    deleted debug code and problem is back.

    But that's not the issue. This issues is conceptually simple.

    I want to use a library. specifically the libiw library

    I install the library using apt-get install libiw-dev

    I include the file <iwlib.h>

    The source code compiles fine, so its found iwlib.h Or at least I assume
    so.
    When I try to link with -liw though, it simple barfs on any reference to
    the library.

    I found libiw.so, and it contains all the right symbols.

    gcc doesn't say it cannot find the libary, only that it *cannot match
    the symbols*.

    Specifically

    gcc -liw -o scan scan.o
    /usr/bin/ld: scan.o: in function `main':
    scan.c:(.text+0x1f): undefined reference to `iw_sockets_open'
    /usr/bin/ld: scan.c:(.text+0x40): undefined reference to `iw_get_range_info' /usr/bin/ld: scan.c:(.text+0x7f): undefined reference to `iw_scan'
    collect2: error: ld returned 1 exit status

    I have never seen this behaviour before.
    Any clues?

    --
    Outside of a dog, a book is a man's best friend. Inside of a dog it's
    too dark to read.

    Groucho Marx

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From Martin Gregorie@3:770/3 to The Natural Philosopher on Sun Aug 6 15:18:02 2023
    XPost: comp.os.linux.misc

    On Sun, 6 Aug 2023 15:54:00 +0100, The Natural Philosopher wrote:

    The source code compiles fine, so its found iwlib.h Or at least I assume
    so.
    When I try to link with -liw though, it simple barfs on any reference to
    the library.

    I found libiw.so, and it contains all the right symbols.

    gcc doesn't say it cannot find the libary, only that it *cannot match
    the symbols*.

    Specifically

    gcc -liw -o scan scan.o /usr/bin/ld: scan.o: in function `main': scan.c:(.text+0x1f): undefined reference to `iw_sockets_open'
    /usr/bin/ld: scan.c:(.text+0x40): undefined reference to
    `iw_get_range_info'
    /usr/bin/ld: scan.c:(.text+0x7f): undefined reference to `iw_scan'
    collect2: error: ld returned 1 exit status

    I have never seen this behaviour before.
    Any clues?

    Anything wrong with the contents of the iwlib.h file? I assume it was
    replaced correctly by the update?



    --

    Martin | martin at
    Gregorie | gregorie dot org

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From Richard Kettlewell@3:770/3 to The Natural Philosopher on Sun Aug 6 17:13:46 2023
    XPost: comp.os.linux.misc

    The Natural Philosopher <tnp@invalid.invalid> writes:
    gcc -liw -o scan scan.o
    /usr/bin/ld: scan.o: in function `main':
    scan.c:(.text+0x1f): undefined reference to `iw_sockets_open'
    /usr/bin/ld: scan.c:(.text+0x40): undefined reference to `iw_get_range_info' /usr/bin/ld: scan.c:(.text+0x7f): undefined reference to `iw_scan'
    collect2: error: ld returned 1 exit status

    I have never seen this behaviour before.
    Any clues?

    The library needs to be listed after the object files that depend on it,
    not before.

    https://gcc.gnu.org/onlinedocs/gcc/Link-Options.html:

    It makes a difference where in the command you write this option; the
    linker searches and processes libraries and object files in the order
    they are specified. Thus, ‘foo.o -lz bar.o’ searches library ‘z’ after
    file foo.o but before bar.o. If bar.o refers to functions in ‘z’,
    those functions may not be loaded.

    --
    https://www.greenend.org.uk/rjk/

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From Andy Burns@3:770/3 to The Natural Philosopher on Sun Aug 6 16:40:16 2023
    XPost: comp.os.linux.misc

    On 06/08/2023 15:54, The Natural Philosopher wrote:

    I have never seen this behaviour before.
    Any clues?


    Does it need to pick up .so files from LD_LIBRARY_PATH ?

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From The Natural Philosopher@3:770/3 to Martin Gregorie on Mon Aug 7 09:08:10 2023
    XPost: comp.os.linux.misc

    On 06/08/2023 16:18, Martin Gregorie wrote:
    On Sun, 6 Aug 2023 15:54:00 +0100, The Natural Philosopher wrote:

    The source code compiles fine, so its found iwlib.h Or at least I assume
    so.
    When I try to link with -liw though, it simple barfs on any reference to
    the library.

    I found libiw.so, and it contains all the right symbols.

    gcc doesn't say it cannot find the libary, only that it *cannot match
    the symbols*.

    Specifically

    gcc -liw -o scan scan.o /usr/bin/ld: scan.o: in function `main':
    scan.c:(.text+0x1f): undefined reference to `iw_sockets_open'
    /usr/bin/ld: scan.c:(.text+0x40): undefined reference to
    `iw_get_range_info'
    /usr/bin/ld: scan.c:(.text+0x7f): undefined reference to `iw_scan'
    collect2: error: ld returned 1 exit status

    I have never seen this behaviour before.
    Any clues?

    Anything wrong with the contents of the iwlib.h file? I assume it was replaced correctly by the update?



    As with all these things it is complex, but looks healthy enough.
    The compiler didnt barf


    --
    Climate Change: Socialism wearing a lab coat.

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From The Natural Philosopher@3:770/3 to Richard Kettlewell on Mon Aug 7 09:14:06 2023
    XPost: comp.os.linux.misc

    On 06/08/2023 17:13, Richard Kettlewell wrote:
    The library needs to be listed after the object files that depend on it,
    not before.

    Ah. That seems to have fixed it, thanks.

    Code doesn't work very well, but it does link ;)

    --
    Those who want slavery should have the grace to name it by its proper
    name. They must face the full meaning of that which they are advocating
    or condoning; the full, exact, specific meaning of collectivism, of its
    logical implications, of the principles upon which it is based, and of
    the ultimate consequences to which these principles will lead. They must
    face it, then decide whether this is what they want or not.

    Ayn Rand.

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From The Natural Philosopher@3:770/3 to Andy Burns on Mon Aug 7 09:10:04 2023
    XPost: comp.os.linux.misc

    On 06/08/2023 16:40, Andy Burns wrote:
    On 06/08/2023 15:54, The Natural Philosopher wrote:

    I have never seen this behaviour before.
    Any clues?


    Does it need to pick up .so files from LD_LIBRARY_PATH ?

    That is the strange thing. I tried introducing a random library to the
    command, , and ld says 'cant find file' so it would seem to be finding
    the .so file OK


    --
    Climate Change: Socialism wearing a lab coat.

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)