Simpler Navigation for Servers and Operating Systems - Please Update Your Bookmarks
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
If you have bookmarked forums or discussion boards in Servers and Operating Systems, we suggest you check and update them as needed.
General
cancel
Showing results for 
Search instead for 
Did you mean: 

Linking C++ program to a C++ library

SOLVED
Go to solution
Vernon Brown_4
Trusted Contributor

Linking C++ program to a C++ library

I'm writing a simple little C++ program to act as a driver between a web browser and a MySQL database. This script compiles the program without error, but calls to MySQL functions fail, indicating that the MySQL client library is not linked.

g++ admacct.cpp /usr/lib64/mysql/libmysqlclient_r.so.15

mv a.out /var/www/cgi-bin/admacct.cgi

Does anyone have a clue about how to set up the include path for compiling C++ programs. I'm searching the documentation at:

http://dev.mysql.com/doc/refman/5.1/en/index.html

Any clue greatly appriciated.

4 REPLIES
Vernon Brown_4
Trusted Contributor

Re: Linking C++ program to a C++ library

Follow up: I think I only have to find out what goes into the #Include <....> statement. So far I've tried every combination of:
#Include
that I can guess. I have not been able to find any of the source files for mysql clients. I'm sure these would all have that include statement in them.
Heironimus
Honored Contributor
Solution

Re: Linking C++ program to a C++ library

Tou're best off using the mysql_config script to get the compile and link flags you need. The MySQL documentation talks about that in the section on compiling clients for the C API.

That's not the right syntax to link against a shared library, though it probably should work. You should use "-lmysqlclient_r", but you probably also need a "-lz" and possibly a few others.

Assuming that you're using the standard MySQL client library, the include file you want is probably mysql.h, but it might be under /usr/include/mysql instead of just /usr/include.
Vernon Brown_4
Trusted Contributor

Re: Linking C++ program to a C++ library

Thanks; you nailed it !!

The .h includes are located in /usr/include/mysql

I used quotes instead of the left and right brackets and it worked !!

#include "/usr/include/mysql/mysql.h"

Vernon Brown_4
Trusted Contributor

Re: Linking C++ program to a C++ library

Problem solved