At the end of my rope - rant

Started by
16 comments, last by Katie 12 years, 8 months ago
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.
Advertisement

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.


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

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


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.

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.


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?

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


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


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.
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.
"It's like naming him Asskicker Monstertrucktits O'Ninja" -Khaiy

This topic is closed to new replies.

Advertisement