On 18 October 2015 at 04:15, <tonyp at acm.org> wrote: > I just tried one more time with the -lm switch and this time it worked. > Hmm... > > Problem solved. Thanks.
You might find that specifying -lm *after* the .c files works but -lm before the .c files doesn't. The linker processes libraries/object files in the order they appear on the command line, and tends to only take unresolved symbols from libraries. So if the linker sees libm first, it looks at the symbols exported by the library (which includes the 'log' function), but ignores them all because it isn't yet aware of any unresolved symbols. Then it looks at the object file derived from sqlite3.c, and finds it has an unresolved symbol 'log'. But the linker only works with one object file at a time and doesn't go backwards, and since there are no more objects/libraries following sqlite3.c, the linker has no opportunity to resolve 'log'. Of course if the library appears after sqlite3.c, when the linker asks "hmm, do I have any unresolved symbols which are exported by libm?" it finds 'log' and you're all good. Cheers, -Rowan