how to compile with popt lib?

Asked by Kevin Hunter

This is hopefully a simple question but after 90 minutes of googling, forum and man page perusal, I'm having a difficult time compiling an example popt program. I'm currently using the example code provided in Maverick's "$ man popt", and receiving this error:

$ gcc -o popt_test popt_test.c
popt_test.c: In function ‘main’:
popt_test.c:32: warning: passing argument 3 of ‘poptGetContext’ from incompatible pointer type
/usr/include/popt.h:261: note: expected ‘const char **’ but argument is of type ‘char **’
/tmp/cc83vlH8.o: In function `usage':
popt_test.c:(.text+0x2f): undefined reference to `poptPrintUsage'
/tmp/cc83vlH8.o: In function `main':
popt_test.c:(.text+0x1e2): undefined reference to `poptHelpOptions'
popt_test.c:(.text+0x213): undefined reference to `poptGetContext'
popt_test.c:(.text+0x22e): undefined reference to `poptSetOtherOptionHelp'
popt_test.c:(.text+0x259): undefined reference to `poptPrintUsage'
popt_test.c:(.text+0x2fa): undefined reference to `poptGetNextOpt'
popt_test.c:(.text+0x31c): undefined reference to `poptGetArg'
popt_test.c:(.text+0x33c): undefined reference to `poptPeekArg'
popt_test.c:(.text+0x375): undefined reference to `poptStrerror'
popt_test.c:(.text+0x38c): undefined reference to `poptBadOption'
popt_test.c:(.text+0x490): undefined reference to `poptFreeContext'
collect2: ld returned 1 exit status

I've tried to link against the object files I /think/ it's missing, namely directly adding -l/lib/libpopt.so.0 to the gcc line, but I'm having no love. Have I perhaps overlooked a necessary apt-get?

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu popt Edit question
Assignee:
No assignee Edit question
Solved by:
Kevin Hunter
Solved:
Last query:
Last reply:
Revision history for this message
Kevin Hunter (hunteke) said :
#1

Okay. That's embarrassing. Missed the -l popt argument to gcc. Problem answered:

$ gcc -o popt_test.c -l popt popt_test

Sorry for the noise.