tags:

views:

85

answers:

3

I'm new to gcc, and trying to compile a c++ program which includes mysql.h using the command:

g++ -o test test.cpp -L/usr/include/mysql -lmysqlclient -I/usr/include/mysql

It works without issue, but I was wondering if someone could explain the arguments to me. I don't like using commands I don't understand.

Thanks

+2  A: 

-o test means the output file is to be named "test".

test.cpp is your source file, of course.

-L/usr/include/mysql means to look for libraries in /usr/include/mysql, as well as in the usual link path. (It probably isn't finding any libraries here; my libmysqlclient.a is in the standard library directory /usr/lib. So I don't think you need this option.)

-lmysqlclient means to link with the mysqlclient library (actually named libmysqlclient.a)

-I/usr/include/mysql means to look for #include files in /usr/include/mysql, as well as in the usual include path.

Fred Larson
If I'm not wrong some of them are only required when the environment macros such as LD_LIBRARY_PATH , PATH are either not set or set to different path than you are expecting.
dicaprio
+1  A: 

try "man g++" for a full description of what the various options mean.

Matt H
A: 

man gcc will give you the details of all these options.

g++ -o test test.cpp -L/usr/include/mysql -lmysqlclient -I/usr/include/mysql

g++ : the compiler
-o test : name the resulting binary "test" 
test.cpp : your source file
-L : the directory to look in for libraries (that are specified by -l)
-l : named library to link against (looks for it in -L)
-I : the directory to look in for #included header files
Stephen