[Eclipse] Connect to MySQL

Post questions regarding programming in C/C++ in Linux/Unix.

Moderators: Darobat, RecursiveS, Dante Shamest, Bugdude, Wizard

[Eclipse] Connect to MySQL

Postby Dennis » Wed Mar 23, 2011 5:29 am

Hello everyone,

I want to connect to my MySQL server with C++ from Eclipse. (in Ubuntu 10.10)

I've added all mysql header files for linux in my eclipse project.
I created my source file (mysql1.cpp):
Code: Select all
/*
* mysql1.cpp
*
*  Created on: Mar 21, 2011
*      Author: dennis
*/
#include <stdlib.h>
#include <stdio.h>

#include "driver.h"

#include "mysql_driver.h"
#include "mysql_connection.h"

using namespace std;

int main(void)
{
   sql::mysql::MySQL_Driver *driver;

   driver = sql::mysql::get_driver_instance();

   printf("done\n");
   return EXIT_SUCCESS;
}


But when I run it I get a error code.
Complete compiling code in Eclipse:
**** Build of configuration Debug for project mysql1 ****

make all
Building file: ../mysql1.cpp
Invoking: GCC C++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"mysql1.d" -MT"mysql1.d" -o"mysql1.o" "../mysql1.cpp"
Finished building: ../mysql1.cpp

Building target: mysql1
Invoking: GCC C++ Linker
g++ -o"mysql1" ./mysql1.o
./mysql1.o: In function `main':
/home/dennis/Documents/cppWorkspace/workspace1/mysql1/Debug/../mysql1.cpp:21: undefined reference to `sql::mysql::get_driver_instance()'
collect2: ld returned 1 exit status
make: *** [mysql1] Error 1


In the downloaded pack were some files with this names:
libmysqlcppconn.so
libmysqlcppconn.so.5
libmysqlcppconn.so.5.1.1.0
libmysqlcppconn-static.a

But I don't what to do with these.

I hope someone could help me with my MySQL/C++ problem.

Thanks,
Dennis
Dennis
 
Posts: 1
Joined: Wed Mar 23, 2011 4:52 am

Re: [Eclipse] Connect to MySQL

Postby ventsyv » Thu Mar 24, 2011 8:54 am

The problem is that the linker is not finding the files. The linker looks through a list of directories that are specified in your project settings, if it doesn't find the files it needs, it generates the errors you see. I haven't used Eclipse in a while so I don't remember where you have to go to add directories to the linker list, but try right clicking on your project and select properties.
Or you can just google "add linker directories Eclipse" or something similar.
User avatar
ventsyv
 
Posts: 2810
Joined: Mon Sep 22, 2003 5:25 pm
Location: MD USA

Re: [Eclipse] Connect to MySQL

Postby ventsyv » Thu Mar 24, 2011 10:15 am

Actually now that I think about it, it's probably looking at your environmental variables, so you should probably add the directories to you LINKER (or similarly named) variable.
User avatar
ventsyv
 
Posts: 2810
Joined: Mon Sep 22, 2003 5:25 pm
Location: MD USA

Re: [Eclipse] Connect to MySQL

Postby exomo » Sun Mar 27, 2011 11:31 am

ventsyv wrote:Actually now that I think about it, it's probably looking at your environmental variables, so you should probably add the directories to you LINKER (or similarly named) variable.
It looks like he didn't add any librarys to the linker options at all.

Open the linker settings of your project: http://help.eclipse.org/ganymede/topic/org.eclipse.nab.mwt.doc/html/dir04/dir00033.html
Put the mysql library files somewhere where the linker can find them or add the directory where they are to the linker options (-L/path/to/files)
Add the library you want to use to the linker options: something like -lmysqlcppconn-static if you want to use the static linking (everything is included in your binary). Or you can link to one of the .so files (dynamic linking, your binary needs the .so files to run), but I'm not exactly sure how this works on linux.
Who needs a signature anyway.
User avatar
exomo
 
Posts: 879
Joined: Fri Sep 26, 2003 12:30 pm
Location: germany->baden


Return to Unix/Linux

Who is online

Users browsing this forum: No registered users and 0 guests