Linking .lib of MySQL in C/C - c++

So, after whole day of trial and effort, I still couldn't figure answer to this question.
I'm perfectly aware of
this thread and this one
but they don't quite give answer to the question.
So, the problem is when compiling program, let's say, like this one:
#include <iostream>
#include <windows.h>
#include <mysql.h>
using namespace std;
int main()
{
MYSQL *connection, mysql;
MYSQL_RES *result;
MYSQL_ROW row;
mysql_init(&mysql);
}
and I get linker error
undefined reference to `mysql_init#4'
I tried adding to input section libmesql.lib and mysqclient.lib, both simultaneously and separately. Tried copying .lib files to Visual Studio default folder, than attempted compiling it by setting path in Linker->General->Additional Library Directories. Tried #pragma comment as well - still to no avail.
So if anyone out there could explain what am I doing wrong (and possibly a way to solve this problem) it would be much appreciated.
p.s. And please, don't answer with links to MySQL documentation - I got them here.

Link your code with mysqlclient.lib.
Properties->Linker->General->Additional Libraries
Add the path to your library here.

Related

Why does "cout" keep giving me error C1083?

I was using Visual C++ 6.0 just now, and I keep getting this error:
fatal error C1083: Cannot open include file: 'streambuf': No such file or directory
My code is just a simple hello world program.
#include "stdafx.h"
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
cout<<"Hello World.";
return 1;
}
Then I went and checked my INCLUDE folder and found a file called STREAMBF, but the compiler was looking for STREAMBUF. Notice that the file that is present is missing the U, between the B and the F. This was from a good copy of VC++6.0, directly from the actual CD, not a pirated copy. So there should be all the files needed. But it appears that a file is missing! Is this MS being stupid again, and yet making another big mistake, and forgetting to include an important file on their CDs? I'd hate to think that every single CD for VC++6.0 that was pressed that came out of MS factories had this problem. And I know that it is a missing file, not just a misnamed file, as renaming STREAMBF to STREAMBUF just led to more errors.
Anybody know where I can find a copy of the file STREAMBUF? Or am I just overlooking something here? Is this exact error a known problem with running old copies of VC++ on modern OS's like Windows 7? Is it possible that the only reason that it's looking for STREAMBUF is that this is a newer file associated with Win7, and that if it was running in a different environment (an older OS), it would actually be looking for the correct file, STREAMBF? Can somebody help me here?
Your installation is either broken, deprecated or interpretes your code in wrong way.
You should only use older compiles if you are trying to build project developed entirely for this version.
Try to compile same code with new compiler, if you want to use VS then you should look for Visual Studio Express 2013.
Your code does not have any errors.
Modify your program to, you should be able to see it okay.
#include <iostream.h>
using namespace std;
int main()
{
cout<<"Hello World.";
return 1;
}
However,
your compiler is pretty old. You need to an upgrade.
There are C++ compilers for Windows from Microsoft Express Visual Studios Link and Info VS2013 to
some other non-Microsoft like GCC for Windows.
If you don't have installation access there are some portable c++ compilers.
Finally there are some online compilers for simple test. web based online compilers.
For my win 10 installation of VC 6.0, I had the same problem ... fatal error C1083: Cannot open include file: 'streambuf': No such file or directory
Replacing with <iostream.h> does not solve the problem.
I have checked the header file installation folder (Program files\VS98\VC98\INCLUDE). For some (unknown) reason, some file names have been changed during installation. Restoring the original name has solved the problem, in my case, in example:
Turn STREAMBF into STREAMBUF, STDXCEPT into STDEXCEPT, XCEPTION into EXCEPTION, FCTIONAL into FUNCTIONAL.
Notice: other header file names might be wrong. I have listed above the file names wrong in my installation.
I hope this may help.

How do I include Boost.Interprocess and Boost.DateTime properly?

This is a really basic question because I am a C++ newbie. I want to use the Boost.Interprocess library, but am having trouble building it. I'm trying to follow these instructions, but it's not working for me. Here is what I have:
#define BOOST_DATE_TIME_NO_LIB
#include <boost/interprocess/shared_memory_object.hpp>
#include <iostream>
using namespace std;
int main() {
cout << "Hello, beautiful world!\n";
}
But I get this error:
boost_1_55_0\boost\date_time\gregorian_calendar.hpp(63) : fatal error C1083: Cannot open include file: 'boost/date_time/gregorian_calendar.ipp': No such file or directory
I know Boost is able to load properly, because I can get an example that uses #include <boost/lambda/lambda.hpp> to work just fine. It's just when I try to include the Boost.Interprocess library that I am having trouble. The cause is clearly because it's having trouble including the Boost.DateTime library properly, but according to the documentation (linked above) I should be able to get by without separately compiling Boost.DateTime if I define BOOST_DATE_TIME_NO_LIB, right?
What am I missing here?
You need to add it to the preprocessor
In VS go to - Project >> properties >> C/C++ >> Preprocessor in the 'Preprocessor Definitions' paste BOOST_DATE_TIME_NO_LIB.
You can download boost libraries here: https://www.boost.org/users/download/
After that, you can include them in your projects. Also, you can check this video on how to add boost libraries in eclipse IDE on Ubuntu: https://www.youtube.com/watch?v=gN8zrnWxFeI

How to connect to Oracle in C++?

I tried to connect to Oracle using C++ but it is giving me error stating that DBManger.h not found. I have also tried using occi.h but got the same error of not found or No Such Directory.
I have installed Oracle 11g and it contains the OCI Liabraries also.
I located the specififc folders also where the OCI libraries are present . In my system they are at location E:\app\user\product\11.1.0\db_1\OCI\lib\MSVC\vc8.
I have also set the Path starting with Oracle home. But, still my program is not able to find the header files.
Any help would be greatly appreciated? I Googled a lot but found the same solution stating that locate the folder where the OCI libraries are available. I am posting my code below written in Visual Studio 2008:
I have written a very small script and just included the header files. Not even done the connectivity:
#include <occi.h>
#include <iostream>
using namespace oracle::occi;
using namespace std;
class DataBaseConnectionTest
{
public:
void test()
{
cout<<"Hello from test"<<'\n';
}
};
void main()
{
DataBaseConnectionTest *dbc=new DataBaseConnectionTest();
dbc->test();
}
Modify your project properties, add the E:\app...vc8 directory name to the Addition include directories. It's under C++/General. No need to double every \ in that one.
You'll probably need a similar treatment for the OCI library file anyway. The include file is only half the puzzle, the other half is the LIB.
You could consider OTL as alternative to OCI. Then your code could be more portable. I used it many years ago, interfacing SqlServer, and was surprised by the clean design and the raw speed (way faster than MFC+ODBC...). Also, I had a problem and Sergei gave me immediate assistance.

C++ write and read from mysql database

I'm working on a project where we want to write to a mysql database, I've googled around and tried a few implementations but they all fail.
For example I tried this: http://markalexanderbain.suite101.com/using-a-mysql-databases-with-c-a70097
#include "StdAfx.h"
#include <iostream>
#include <my_global.h>
#include <mysql.h>
#pragma comment(lib, "libmysql")
#pragma comment(lib, "mysqlclient")
using namespace std;
MYSQL *connection, mysql;
MYSQL_RES *result;
MYSQL_ROW row;
int query_state;
int main()
{mysql_init(&mysql);
//connection = mysql_real_connect(&mysql,"host","user","password","database",0,0,0);
connection = mysql_real_connect(&mysql,"localhost","bainm","not_telling","cpp_data",0,0,0);
if (connection == NULL)
cout << mysql_error(&mysql) << endl;
return 1;
}
It compiles and generates an exe file, but it closes every time I try to run it, I've added a cin.get at the end so it wouldn't close.
But the program still closes and Visual Studio 2010 gives me the following error message: The program '[32856] mysql test.exe: Native' has exited with code -1073741515 (0xc0000135).
The only thing that is common in all these implementations is the Include files and the #pragma comment(lib, "libmysql") and #pragma comment(lib, "mysqlclient")
I'm using these files which are included with mysql ga 5.5.16 32 bit.
So I'm looking for a way to write to a mysql database, if any one knows how to fix this to make it work or knows another way with a tutorial please let me know.
Error code 0xc0000135 means "The Application Failed To Initialize Properly". This is almost certainly due to a missing DLL (or two); probably the ones relating to MySQL mentioned in your #pragma lib statements.
Either add them to your path or copy them to the same directory as the .exe.
EDIT: Follow the instructions from here, in order to compile with the correct options. The file mysqlclient.dll should be included with the MySQL installation (do a system file find if you cannot find it).

Berkeley DB(Unable to Locate Component)

I have a problem with berkeley DB. I get a dialog titled "Unable To Locate Componenent" saying "This application has failed to start because libdb48.dll was not found. Re-installing the application may fix this problem", then it crashes after clicking ok. I got the error message when running these simple code below:
#include <iostream>
#include <string>
#include <db_cxx.h>
using namespace std;
int main()
{
Db db(0, 0);
}
I already set the Additional include directories to the "build_windows" directory and I have linked to the "libdb48.lib". I honestly do not know what to do here. The funny part is, I googled and I had 0 pages returned.
I am using visual studio c++ 2008 and Berkeley DB 4.8.24
Thanks
Where is libdb48.dll? Is it installed? Where? A hackish solution that should make it work is to copy libdb48.dll into c:\windows\system32. If that solves the problem, then you know that the DLL just wasn't on the path. Then you can find a more appropriate place to put it.