0

How to resolve the below error while running a c program to connect to Ms SQL server from Linux fedora7 using mssqlodbc

Need to connect to Ms SQL server from c app on Linux fedora7 using msqlodbc

gcc -o prog prog.c -lc -lpthread -lodbcinst -lodbc -lm

/lib64/libpthread.so.0: undefined reference to `__h_errno@GLIBC_PRIVATE'

lib64/libpthread.so.0: undefined reference to `__mktemp@GLIBC_PRIVATE'

tried checking dependencies of libODBC using ldd and libc.so.6 is being pointed and also checked whether these symbols are present in libc.so.6 using nm -gdf libc.so.6. both the symbols are present in libc.so.6. still getting Undefined reference error.

James Z
  • 12,209
  • 10
  • 24
  • 44
Laurel
  • 1
  • That is weird. Is there another libc on the system? You shouldn't have to specify `-lc` or `-lm`. Try without those and see if there is a difference. Also, trying to access MS SQL server from Linux... Have you heard of `sqsh`? – Jason Feb 15 '23 at 14:15
  • Only one libc.so.6 is available. I got same error even after compiling without -lc,-lm. Able to connect to Ms SQL server thru sqlcmd.. – Laurel Feb 17 '23 at 13:52
  • Odd. So we are linking to the correct (only) libc and the symbols exist. This might be an issue with linking order then. Generally, you want to put the library that requires symbols *before* the library that has the symbols. Try building like this `gcc -o prog prog.c -lodbcinst -lodbc -lpthread -lm -lc`. See if that works, or at the very least, gives you a different error. – Jason Feb 17 '23 at 14:19
  • I just looked at a project of mine and I used `-pthread` instead of `-lpthread`. That actually might have something to do with the errors too. So I think the command should be `gcc -o prog prog.c -pthread -lodbcinst -lodbc -lm -lc`. I put it before the links because, for me, I used it as part of CFLAGS. – Jason Feb 17 '23 at 14:57
  • Tried the same way as you mentioned d. Still getting same errors.. __h_errno, __mktemp.. – Laurel Feb 20 '23 at 12:46
  • Wow... I'm kind of at a loss. I feel like this has to be something incredibly odd on your system, and I would need access to poke and prod at it to give you a good answer. It's not uncommon to have libraries get out of sync from incorrect usage of the package manager. But I don't see how that can happen to pthread and libc. Not only that, but you have poked the library yourself and saw that the symbol *are* present. Nevertheless, all I have is a shot in the dark. Try updating your system. If your libraries are out of sync, that would fix it. – Jason Feb 20 '23 at 13:27

0 Answers0