We help IT Professionals succeed at work.
Get Started

Compiling C prog in Linux can not find function reference in library

UnderSeven
UnderSeven asked
on
707 Views
Last Modified: 2012-08-13
I'm attempting to compile a program in linux using C.  my linux version is 2.6.32.5-686

This is the command I am using to compile:

gcc test2.c /usr/local/lib/libtdsodbc.a

As you can see I have a library in /usr/local/lib that this program requires.  I do not have my instance set up to look in there automatically so I have to tell it to find the library there.  This works part way, but then one of the functions invoked within the library itself seems to then run into a similar problem, I get this error:

test2.c: In function âmainâ:
test2.c:18: warning: incompatible implicit declaration of built-in function âmallocâ
/usr/local/lib/libtdsodbc.a(connectparams.o): In function `myGetPrivateProfileString':
/home/username/freetds-0.92.dev.20110819/src/odbc/connectparams.c:143: undefined reference to `SQLGetPrivateProfileString'
collect2: ld returned 1 exit status

The function it is trying to find is infact within the very library I am already telling it where to find.  So in some round about way, something invoked by code related to the libraries I'm including are trying to then look at libraries that it can not find, as demonstrated by this grep:

grep SQLGetPrivateProfileString /usr/local/lib/*.*
Binary file /usr/local/lib/libodbcinst.so matches
Binary file /usr/local/lib/libodbcinst.so.1 matches
Binary file /usr/local/lib/libodbcinst.so.1.0.0 matches
Binary file /usr/local/lib/libodbc.so matches
Binary file /usr/local/lib/libodbc.so.1 matches
Binary file /usr/local/lib/libodbc.so.1.0.0 matches
Binary file /usr/local/lib/libtdsodbc.a matches
Binary file /usr/local/lib/libtdsodbc.so matches
Binary file /usr/local/lib/libtdsodbc.so.0 matches
Binary file /usr/local/lib/libtdsodbc.so.0.0.0 matches

As you can see, the function is in libtdsodbc.a, which I'm already pointing it to.

I need to know how to make this program compile.  I assume this is an issue with proper library paths.

Comment
Watch Question
Commented:
This problem has been solved!
Unlock 2 Answers and 4 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE