hostingBlues
02-27-2008, 11:13 PM
A brief saga of connecting to my SQL using C++.
Chapter 1 - The strategy - use MySQL++ (http://tangentsoft.net/mysql++/). Download the tarball, change the configure file so ac_default_prefix = '~' instead of '/usr/local' cuz they won't let you copy the libs to /usr/local. Do the GNU thing - configure, make, make install. The MySQL++ lib is built and installed in /home/youruserid/lib.
Chapter 2 - Write your app. Follow the examples from MySQL++ - They're good and the API is really clean!
Chapter 3 - Compile your app making sure you tell gcc where to find the includes and libs:
g++ myapp.cpp –I ~/include/mysql++ -I /usr/include/mysql –L ~/lib –l mysqlpp –o myapp
Chapter 4 - Try and run your app. You can test it from the command line by adding:
LD_LIBRARY_PATH=~/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH
to your .bash_profile. This will not work when you run it as a script under the apache http server though because the process won't know where to find the MySQL++ shared object library. Someone more knowledgeable about such things may find otherwise, but hostingBlues couldn't find anyway with LD_LIBRARY_PATH, .htaccess SetEnv, PassEnv, etc. to get the server to find the .so file so it never ran.
Chapter 5 - Call BlueHost support. They will tell you to check permissions, open the machine code in an editor and tell you the file is corrupt because it contains garbage characters, etc. They were really very helpful and tried hard to resolve this, but just didn't seem to know too much about things outside the perl, php, python, etc. world.
Chapter 6 - Resolution - There's a linker flag -rpath 'dir' that will code the directory name in the executable so the loader will use it at run time to find the shared libs. Add it to the g++ cmd line above by using:
-Xlinker -rpath -Xlinker /home/youruserid/lib
and compile. Now it works!
Hope this little saga will save someone the hassle that hostingBlues had to endure :)
Chapter 1 - The strategy - use MySQL++ (http://tangentsoft.net/mysql++/). Download the tarball, change the configure file so ac_default_prefix = '~' instead of '/usr/local' cuz they won't let you copy the libs to /usr/local. Do the GNU thing - configure, make, make install. The MySQL++ lib is built and installed in /home/youruserid/lib.
Chapter 2 - Write your app. Follow the examples from MySQL++ - They're good and the API is really clean!
Chapter 3 - Compile your app making sure you tell gcc where to find the includes and libs:
g++ myapp.cpp –I ~/include/mysql++ -I /usr/include/mysql –L ~/lib –l mysqlpp –o myapp
Chapter 4 - Try and run your app. You can test it from the command line by adding:
LD_LIBRARY_PATH=~/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH
to your .bash_profile. This will not work when you run it as a script under the apache http server though because the process won't know where to find the MySQL++ shared object library. Someone more knowledgeable about such things may find otherwise, but hostingBlues couldn't find anyway with LD_LIBRARY_PATH, .htaccess SetEnv, PassEnv, etc. to get the server to find the .so file so it never ran.
Chapter 5 - Call BlueHost support. They will tell you to check permissions, open the machine code in an editor and tell you the file is corrupt because it contains garbage characters, etc. They were really very helpful and tried hard to resolve this, but just didn't seem to know too much about things outside the perl, php, python, etc. world.
Chapter 6 - Resolution - There's a linker flag -rpath 'dir' that will code the directory name in the executable so the loader will use it at run time to find the shared libs. Add it to the g++ cmd line above by using:
-Xlinker -rpath -Xlinker /home/youruserid/lib
and compile. Now it works!
Hope this little saga will save someone the hassle that hostingBlues had to endure :)