I just moved from RH (CentOS 6) with gcc 4.4.6 to Ubuntu 12 with gcc 4.6.3. I have a program that references a third party library. I have successfully build and installed the library on the Ubuntu machine. When I run updatedb and locate libXXX.so I get the same exact results. I look for the header file the same way and also get the same exact results.

I have a small test program that came from the CentOS box. It consists of one *.c file and a bash script to build and run it. It's all very simple. The script looks like this:


rm -f a.out
gcc -W -lpowerdna *.c

exit 0

I have LD_LIBRARY_PATH set (on both the CentOS and Ubuntu boxes) to the directory where the header file and *.so reside. I have double, triple, and quadruple checked that the spelling and the capitalization are correct.

And yet when I compile on the Ubuntu machine, I get the undefined reference to '<function name>' error for every function call in the test program. To add to the general oddness, their defined types are not generating errors. When I comment out the #include in my test file, the compiler generates errors for the types.

This is a very simple setup, with very few points of possible failure. I'm certain I'm doing something stupid, but for the life of me, I don't see it. For completeness, I'll post the pertinent parts.

Source file:

#include "PDNA.h"

// bare bones test program

Locate results:

[brian@localhost dmap403]$ locate PDNA.h  

[brian@localhost dmap403]$ locate libpowerdna  

Environment variable:

[brian@localhost dmap403]$ env | grep LD_

When I compile on Ubuntu, I get these results:

/tmp/ccJAa183.o: In function 'main':  
dmap403.c:(.text+0x6c): undefined reference to 'function name'  
collect2: ld returned 1 exit status

It looks like the compiler doesn't know where the *.so is, but I have it in the LD_LIBRARY_PATH. Heck, I even added -L/usr2/uei/DAQLib -lpowerdna to the gcc options to no avail.

EDIT: Perhaps this should be moved to the Linux site?
EDIT: Updated title to better reflect the question.


Hmmm... I moved the *.c before the libraries and it compiled fine. I didn't know that the order mattered. Go figure...

Original: gcc -W -I/usr2/uei/DAQLib -L/usr2/uei/DAQLib -lpowerdna *.c

Current: gcc -W *.c -I/usr2/uei/DAQLib -L/usr2/uei/DAQLib -lpowerdna

C'est la vie.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.