At the end of my rope - rant

Started by
16 comments, last by Katie 12 years, 8 months ago
First, thank you very much for taking the time to help me out.


"how does one determine which libraries need to be linked to in this manner and which ones are covered by #INCLUDE statements in my code?"

OK, that really does say that you need to learn C++ more -- #include does not cover ANY library linkage.


Maybe I worded that wrong. I understand (mostly) the differences between including and linking. My question was, once the MySQL libraries were installed, why couldn't I access them by using #INCLUDE <> like I do with <iostream>, for example? Is it because the MySQL libraries aren't in my system path or their location otherwise known by the compiler/linker? I think you explained that pretty well. Thank you again.


I know what you're thinking, you're thinking how do you know which -lxxx goes with which #include??

So there's several ways. One is to find whoever wrote the library and beat the information out of them with a length of rubber hose. However we save that until last resort because it discourages software development and also rubber hose is actually quite hard to come by in this day and age.

You can look in the manual pages. If you look in "man dlopen", for example, it says


SYNOPSIS
#include <dlfcn.h>
void *dlopen(const char *filename, int flag);
char *dlerror(void);
void *dlsym(void *handle, const char *symbol);
int dlclose(void *handle);
Link with -ldl.


For mysql, it's in the manual;



19.8.16. Building Client Programs
If you compile MySQL clients that you've written yourself or that you obtain from a third-party, they must be linked using the -lmysqlclient -lz options in the link command. You may also need to specify a -L option to tell the linker where to find the library. For example, if the library is installed in /usr/local/mysql/lib, use -L/usr/local/mysql/lib -lmysqlclient -lz in the link command. For clients that use MySQL header files, you may need to specify an -I option when you compile them (for example, -I/usr/local/mysql/include), so that the compiler can find the header files.



See -- this is why we very rarely have to beat the information out of people.


...and that's the kind of info I'm missing that will make my life a lot easier. Adding that to your tip about using grep with locate has really moved me forward in terms of understanding what's going on in this brave new world of Linux.
Advertisement

"OpenSUSE just booted to a blank screen - no command prompt or anything and wouldn't respond to any keyboard input."

I have come to the conclusion, as someone who currently specialises in supporting various flavours of Linux, this is pretty much OpenSUSE's designed-in behaviour and anyone who ever sees a login prompt from it should report the occurrence as a bug...


I believe you. Mine is a ThinkPad T500 - only a couple of years old, and a very capable laptop. That wasn't the first version of openSUSE I've tried in that time. Both instances resulted in booting to a blank screen.

Ahh well, there are plenty of other distro fish in the sea, luckily. :wink:
Ok, I've finally found the example code included with the MySQL client package. Working through it, I'm now getting the following error when compiling...

driver/mysql_public_iface.h: No such file or directory

Using locate didn't turn anything up. Any ideas?
"Using locate didn't turn anything up"

Have you installed the client developer package? Probably called something like; libmysqlclient10-dev

That contains the header files which go with the client library files. (They're split up like this because some people want a database server, some people want clients to run on a machine and some people want to compile clients on a machine. This way you get to pick which combination of the three you have).

"Using locate didn't turn anything up"

Have you installed the client developer package? Probably called something like; libmysqlclient10-dev

That contains the header files which go with the client library files. (They're split up like this because some people want a database server, some people want clients to run on a machine and some people want to compile clients on a machine. This way you get to pick which combination of the three you have).


The software manager shows a package named "mysql-devel" and the file list for that package includes /usr/lib64/mysql/libmysqlclient.so. I don't see anything else close.
OK, that should be everything you need -- but that header file isn't in the RPM. Actually most of the examples I can find use a "#include <mysql.h>"

Have a look at;

http://www.cyberciti.biz/tips/linux-unix-connect-mysql-c-api-program.html

and

http://www.kitebird.com/mysql-book/ch06-1ed.pdf


Both of those have example programs plus link info.

The mysql.h header file should be installed as /usr/include/mysql/mysql.h as shown by

http://rpm.pbone.net/index.php3/stat/6/idpl/16810454/dir/fedora_15/com/mysql-devel-5.5.14-2.fc15.x86_64.rpm

(I know it's not quite the same version, but it'll do for this purpose).
Excellent. I'll give those examples a shot. Should I expect to add the following to my makefile?

-L /usr/include/mysql -lmysqlclient
You'll probably need a "-Ixxx" (capital eye) for the header file location on the compilation line.

On the link line you'll need the "-L <librarypath> -l<libraryname>"

This topic is closed to new replies.

Advertisement