1

I'm getting a linker error 'undefined reference to' when linking a library with my program. I've read this post and I understand that the order of libraries matter. Does the order of '-Lpath/to/lib' also matter? The problem i'm facing solved when I change the order of '-L..' option rather than '-l'. please shed some light.

Pessy
  • 21
  • 1

1 Answers1

1

-L controls link directories, -l for link libraries (actual files). So, by changing order of -L flags, you can cause a different library with the same filename to be selected - directories are searched by the order provided with -L (left to right)

In your case, sounds like the library file originally selected did not contain some of the functionality - that's why you got 'undefined reference to'.

In general it may be worth either using -l with full path to the specific library, or a build system (I like CMake) where you can set this as an explicit option (and maybe print the selected file in a message during build).

Yuri Feldman
  • 2,354
  • 1
  • 20
  • 23