LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Yet another undefined reference (https://www.linuxquestions.org/questions/linux-general-1/yet-another-undefined-reference-850983/)

CollieJim 12-17-2010 10:05 PM

Yet another undefined reference
 
I'm trying to compile and link a program to test parapin.
Code:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "parapin.h"

int main(int argc, char *argv[])
{ ...

Code:

lib$ cd /usr/lib
lib$ ls -al libparapin*
-rwxr-xr-x 1 root root 2602 Dec 18 09:57 libparapin.a

When I compile, I get:
Code:

noppp$ gcc -O -lparapin -o testpp test.c
/tmp/cc3tvN9s.o: In function `main':
test.c:(.text+0x19): undefined reference to `pin_init_user'
test.c:(.text+0x3d): undefined reference to `pin_input_mode'
test.c:(.text+0x49): undefined reference to `pin_output_mode'
test.c:(.text+0x69): undefined reference to `set_pin'
test.c:(.text+0x75): undefined reference to `clear_pin'
test.c:(.text+0x81): undefined reference to `pin_is_set'
collect2: ld returned 1 exit status

It looks like the library is found (no error anyway) but the functions in it are not seen. Text at the beginning of libparapin.a includes function names as used in the test program, and parapin.h declares them.

What am I missing?
TIA

paulsm4 12-17-2010 10:47 PM

Hi -

I think it probably would have been better to post this in the "Programming" section...

... but

1) it sounds like you're basically doing everything correctly.

2) You can use "nm" to verify which symbols are in the library
Quote:

EXAMPLES:
nm libparapin.a | less
nm libparapin.a | grep pin_init_user
3) A longshot ... but maybe it would help if you put the "-lparapin" at the END of your link command:
Quote:

gcc -g -Wall -pedantic -o testpp test.c -lparapin

CollieJim 12-17-2010 11:08 PM

Thanks. I need to have my eyes examined, I think. I looked, but missed the programming section.

Putting -lparapin at the end worked.


All times are GMT -5. The time now is 04:27 PM.