Sign in to follow this  
Quasimojo

At the end of my rope - rant

Recommended Posts

Quasimojo    279
I've long wanted to get away from all of the GUI IDE's and learn some no frills C++ programming. What better way to do so than trudging through development of a very basic text based RPG. Better yet, I want to do this on Linux. If I ever host the server side of this, I'll want the least expensive hosting service I can find, and that means Linux.

Let me tell you why I've tried countless times to do something like this. It's always the same with Linux. It doesn't matter what distro I choose (though I've learned after several hard lessons *not* to start with Gentoo), I always end up scratching my head wondering what freaking masochist came up with this OS. Seriously, I meticulously pick through packages in the package manager, trying to get everything I need to simply compile C++ code with MySQL database access. There are some 50 different packages that all look like they could be necessary! It doesn't matter which ones I choose, however, as I never get all of them I need.

Of course, none of this is made clear to me until I start trying to compile my code. It's at that point I get all kinds of "blahblah() not defined", "cannot instantiate class of type abstract because the seventy-eleven methods listed below are virtual/abstract/something" and other cryptic crap that sends me scurrying to the web trying to find half a clue as to what's going on. This is code straight out of basic code examples found online, not me trying to use libraries with which I'm not familiar.

I copied and pasted the simplest of examples of connecting to a MySQL server and running a select statement - not even against a particular database, but merely one to return a string constant (e.g. SELECT 'hello World" as message). The closest I've gotten it to compile, it reports "unidentified reference to get_driver_instance(). Yeah, I've see all Please check the examples/ directory of your MySQL Connector/C++ installation for complete programs.the suggested fixes, and none work. Some make things worse, creating dozens more compiler errors. Some solutions have said something like "make sure you use -lmysqlclient" - that's it. No explanation as to how to "use" it or even where. I had to dig deeper to find out that it is simply a compiler switch - no idea what it does. Then there are bits of info here and there that suggest I add something to ld.so.conf. What, add it to the end of the file? The first line is "#include such/and/such". Should this new line also start with #include??

I started pouring over the documentation on the MySQL web site. It seems very thorough. However, for example code (yay!) it instructs me: "Please check the examples/ directory of your MySQL Connector/C++ installation for complete programs." Where the hell is that?! I have no idea where it was "installed" (I used quotes there, because I always seem to find references to programs in a dozen different places in a Linux system. Which one would be the installation directory??)

I really want to do this. God knows how many days I've spent trying to get up to speed coding in Linux over the years. It always comes down to stumbling block after stumbling block after stumbling block. I know that there are a few core concepts with which I need to become familiar, and the rest will start clicking. Unfortunately the disjointed environment inherent in open source software has me reeling.

Does anyone have any tips for a Linux n00b on ensuring that my C++/MySQL programming environment is set up correctly? I would ***LOVE*** to find a simple, step-by-step guide, but that's probably expecting too much. I'll settle for solid advice on key points.

I know. I rambled and didn't get very specific with my questions. It's late, and like I said, I'm getting completely frustrated. I don't want to do this in Windows, but does programming on Linux really have to be this freaking complicated?

Thanks for listening.

Share this post


Link to post
Share on other sites
shadowisadog    3217
[quote name='Quasimojo' timestamp='1312859112' post='4846503']
I've long wanted to get away from all of the GUI IDE's and learn some no frills C++ programming. What better way to do so than trudging through development of a very basic text based RPG. Better yet, I want to do this on Linux. If I ever host the server side of this, I'll want the least expensive hosting service I can find, and that means Linux.

Let me tell you why I've tried countless times to do something like this. It's always the same with Linux. It doesn't matter what distro I choose (though I've learned after several hard lessons *not* to start with Gentoo), I always end up scratching my head wondering what freaking masochist came up with this OS. Seriously, I meticulously pick through packages in the package manager, trying to get everything I need to simply compile C++ code with MySQL database access. There are some 50 different packages that all look like they could be necessary! It doesn't matter which ones I choose, however, as I never get all of them I need.

Of course, none of this is made clear to me until I start trying to compile my code. It's at that point I get all kinds of "blahblah() not defined", "cannot instantiate class of type abstract because the seventy-eleven methods listed below are virtual/abstract/something" and other cryptic crap that sends me scurrying to the web trying to find half a clue as to what's going on. This is code straight out of basic code examples found online, not me trying to use libraries with which I'm not familiar.

I copied and pasted the simplest of examples of connecting to a MySQL server and running a select statement - not even against a particular database, but merely one to return a string constant (e.g. SELECT 'hello World" as message). The closest I've gotten it to compile, it reports "unidentified reference to get_driver_instance(). Yeah, I've see all Please check the examples/ directory of your MySQL Connector/C++ installation for complete programs.the suggested fixes, and none work. Some make things worse, creating dozens more compiler errors. Some solutions have said something like "make sure you use -lmysqlclient" - that's it. No explanation as to how to "use" it or even where. I had to dig deeper to find out that it is simply a compiler switch - no idea what it does. Then there are bits of info here and there that suggest I add something to ld.so.conf. What, add it to the end of the file? The first line is "#include such/and/such". Should this new line also start with #include??

I started pouring over the documentation on the MySQL web site. It seems very thorough. However, for example code (yay!) it instructs me: "Please check the examples/ directory of your MySQL Connector/C++ installation for complete programs." Where the hell is that?! I have no idea where it was "installed" (I used quotes there, because I always seem to find references to programs in a dozen different places in a Linux system. Which one would be the installation directory??)

I really want to do this. God knows how many days I've spent trying to get up to speed coding in Linux over the years. It always comes down to stumbling block after stumbling block after stumbling block. I know that there are a few core concepts with which I need to become familiar, and the rest will start clicking. Unfortunately the disjointed environment inherent in open source software has me reeling.

Does anyone have any tips for a Linux n00b on ensuring that my C++/MySQL programming environment is set up correctly? I would ***LOVE*** to find a simple, step-by-step guide, but that's probably expecting too much. I'll settle for solid advice on key points.

I know. I rambled and didn't get very specific with my questions. It's late, and like I said, I'm getting completely frustrated. I don't want to do this in Windows, but does programming on Linux really have to be this freaking complicated?

Thanks for listening.
[/quote]

I am by no means a Linux expert, but from my time with it... What distribution are you using, and what packages are you trying? This seems like fairly relevant information to be able to provide help...

Also you should probably spend a considerable bit more time learning C++... I wouldn't focus on MySQL for now..

Anyway you are trying to interact with databases using C++ in Linux... you set yourself up for a steep learning curve.... When you want low level/open source/infinite freedom to do infinite damage then you have to deal with frustration. If you don't want frustration then use an easier language or even an easier operating system...

Share this post


Link to post
Share on other sites
Sudi    761
well you have to link the mysql connector lib to your code. when you use an ide add "mysqlclient" to the linked libs. if you use the console use "-lmysqlclient".
problem now is i have no idea if there is a difference between c++ connector and the standard mysql api i guess there is so the lib probably is called differently. but yeah thats the error you get.

Share this post


Link to post
Share on other sites
Katie    2244
" Where the hell is that?! I have no idea where it was "installed""

Most installations these days should install/configure the "locate" tool.

Do: "sudo updatedb" to make sure the database is up to date (it usually updates in the middle of the night automatically).


Then you can do "locate X" and it will find you all the files containing X.

You probably want to try something like "locate examples | grep -i mysql"

Share this post


Link to post
Share on other sites
Quasimojo    279
[quote name='shadowisadog' timestamp='1312860052' post='4846507']
I am by no means a Linux expert, but from my time with it... What distribution are you using, and what packages are you trying? This seems like fairly relevant information to be able to provide help...

Also you should probably spend a considerable bit more time learning C++... I wouldn't focus on MySQL for now..

Anyway you are trying to interact with databases using C++ in Linux... you set yourself up for a steep learning curve.... When you want low level/open source/infinite freedom to do infinite damage then you have to deal with frustration. If you don't want frustration then use an easier language or even an easier operating system...
[/quote]

I'm using Fedora 15 (KDE). I was using Mint for a while, but uninstalling a bunch of mysql packages I had installed trying to get it to work rendered the system unbootable, don't ask me why. Being new to the OS, the easiest fix I knew of was to reinstall. OpenSUSE just booted to a blank screen - no command prompt or anything and wouldn't respond to any keyboard input.

As far as spending more time learning C++ goes, you're certainly right about that. However, this seems like a fundamental problem - linking libraries (heck, getting them installed on the system so they *can* be linked). I'm fairly comfortable with the basics of C++...well...present issues notwithstanding.

It's things tripping me up like the fact that, though I'm not really familiar with compiling from source (I mean I've followed instructions and done it with various software before, but the instructions have to be pretty good), but when I tried to do so with the MySQL Connector (thinking it should install everything I need), the instructions said to start by running cmake in the directory of the main .cpp file. I got it downloaded and unpacked and there was not a single .cpp file in the package - all .h files with a few .so files. I even read the README included, and it said the same thing. Locate the .cpp file(s). This source came straight from MySQL, so it's pretty clear the problem was a short between my chair and keyboard.

Share this post


Link to post
Share on other sites
Quasimojo    279
[quote name='Sudi' timestamp='1312861803' post='4846516']
well you have to link the mysql connector lib to your code. when you use an ide add "mysqlclient" to the linked libs. if you use the console use "-lmysqlclient".
problem now is i have no idea if there is a difference between c++ connector and the standard mysql api i guess there is so the lib probably is called differently. but yeah thats the error you get.
[/quote]

Thanks for the tip. On that note, 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?

Share this post


Link to post
Share on other sites
Quasimojo    279
[quote name='Katie' timestamp='1312875514' post='4846573']
" Where the hell is that?! I have no idea where it was "installed""

Most installations these days should install/configure the "locate" tool.

Do: "sudo updatedb" to make sure the database is up to date (it usually updates in the middle of the night automatically).


Then you can do "locate X" and it will find you all the files containing X.

You probably want to try something like "locate examples | grep -i mysql"
[/quote]

Yeah, I've used locate, trying to clear things up at times. It usually returned no results, causing me to go on a package installing spree. Or, in the case of "locate examples" I got several screens of results, none of which appeared to be mysql-related after parsing them all. :(

I wasn't aware of the updatedb command. I don't leave my laptop on overnight, so it may never get run. I'll keep that in mind. Thanks.

Share this post


Link to post
Share on other sites
Katie    2244
"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...

Share this post


Link to post
Share on other sites
Katie    2244
"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.

#include just grabs a file and pretends the entire contents of that file is present at that point. When you #include something like (for example) stdio.h or iostream, what actually gets included is a "header file".

The header file contains a bunch of statements which essentially say "So there's this function called printf. I don't wanna tell you about it now, I just wanna tell you it'll exist later."

So, you put in calls to "printf". The compiler lets you do this -- because the statements in the included header files have told it it'll all be OK in the end.

In order to finish off your program, you have to tie up all the loose ends. You have to supply all those functions. That's what the -lxxx bits are for -- to tell your linker (the last part of the compiler) which blobs of code might contain things it needs.

So... printf(). Printf and exit() and a bunch of others are sort of special. They live in a library which is automatically added in. Which is why you don't have to specify them. You can if you want ( by saying "-lc" ) but you don't have to.

The MySQL ones aren't so you have to explain that a second library is needed. Often there are more link instructions added on the end "-lpthread" and "-ldl" are quite common.

So; #includes usually tell the compiler that you'll tell it about some stuff later. -lxxx is the point where you actually do the telling.

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

[code]
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.
[/code]

For mysql, it's in the manual;

[code]

[b]19.8.16. Building Client Programs[/b]
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.

[/code]

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

Share this post


Link to post
Share on other sites
mrchrismnh    82
Blahblahblah() not defined sounds like a linker error. I always set aside some time and take a few deep breaths before I bring a new library into a project I am developing on Linux, especially when using c++. The seventy errors rlating to an abstract method sound like you zigged where you should have zagged OOPwise; I think if MYSQL wouldn't compile properly under any flavor of Linux that error would have been caught before the software was Sudo-able.

Share this post


Link to post
Share on other sites
Quasimojo    279
First, thank you very much for taking the time to help me out.

[quote name='Katie' timestamp='1312917400' post='4846825']
"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.[/quote]

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.

[quote name='Katie' timestamp='1312917400' post='4846825']
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

[code]
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.
[/code]

For mysql, it's in the manual;

[code]

[b]19.8.16. Building Client Programs[/b]
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.

[/code]

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

...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.

Share this post


Link to post
Share on other sites
Quasimojo    279
[quote name='Katie' timestamp='1312916533' post='4846819']
"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...
[/quote]

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:

Share this post


Link to post
Share on other sites
Quasimojo    279
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...

[code]driver/mysql_public_iface.h: No such file or directory[/code]

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

Share this post


Link to post
Share on other sites
Katie    2244
"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).

Share this post


Link to post
Share on other sites
Quasimojo    279
[quote name='Katie' timestamp='1312975250' post='4847123']
"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).
[/quote]

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.

Share this post


Link to post
Share on other sites
Katie    2244
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).

Share this post


Link to post
Share on other sites
Quasimojo    279
Excellent. I'll give those examples a shot. Should I expect to add the following to my makefile?

[code]-L /usr/include/mysql -lmysqlclient[/code]

Share this post


Link to post
Share on other sites
Katie    2244
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>"

Share this post


Link to post
Share on other sites
Sign in to follow this