PDA

View Full Version : g++ question


bo01
January 18th, 2009, 09:37 PM
Hello
I searched it but didn't find an answer.

I compile and run some programs in c++ with g++ and I use the flag -lpq in order to manage the build a program that uses an external library (database lib).

My question is what exactly does this (or these?) flag/s? First of all, I think -lpq is not one argument but I don't know (and I cannot find it) what -l does or -p or -pq or -q...

Is it so obvious???

THANX in advance

Catalyst2Death
January 18th, 2009, 09:48 PM
I think (someone correct me) that the -lpq option refers to libpq. This flag tells the linker that it needs code from the libpq library.

bo01
January 18th, 2009, 10:06 PM
Thank u Catalyst.
So its one flag and not two or three together in one? Can u be more specific? Why is this flag necessary as I have included the library in my program?
Thanks again

pansz
January 18th, 2009, 10:41 PM
-lpq means link (-l) the libpq.a or libpq.so library, which should be in the library search path specified by -L

man gcc should give you everything detail.

snova
January 18th, 2009, 10:44 PM
So its one flag and not two or three together in one? Can u be more specific? Why is this flag necessary as I have included the library in my program?

Short answer; there are headers, and then there are libraries. You need both.

#include merely makes the library available to you by exposing its interface, but you need to link the library in before the finished program can actually use the code. This is what -lpq is for- it specifies a library to be linked in.

bo01
January 19th, 2009, 09:43 AM
Thanks a lot guys. Its clear now!