Weird compilation error

Aug 06, 2023 Last reply: 2 years ago 6 Replies

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?


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

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

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

formatting link
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.

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

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

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.

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required