-
October 19th, 2010, 04:28 AM
#16
Re: MySQL Connector C++ "linker" error.
Correct I noticed Debian isn't on that list, but in most cases it will run either way. Ubuntu and Debian can run together, from my experience.
I will try that, thanks!
-
October 19th, 2010, 04:04 PM
#17
Re: MySQL Connector C++ "linker" error.
Okay some updates.
I can now compile it and it compiles, but:
Code:
g++ hw.cpp -o ./hw -lmysqlcppconn
/usr/bin/ld: warning: libstdc++.so.5, needed by /usr/local/lib/libmysqlcppconn.so, may conflict with libstdc++.so.6
But then I want to execute my hw file.
It compiles now, but surely it does not work
How am I supposed to get around that? :S
Last edited by realchamp; October 19th, 2010 at 04:56 PM.
-
October 19th, 2010, 10:10 PM
#18
Re: MySQL Connector C++ "linker" error.
Howdy RealChamp. At this link [link]http://blog.ulf-wendel.de/?p=215[/link] about two thirds down the page there's a bit that says
Code:
As said, you need to link both "mysqlcppconn-static.lib" and "libmysql.lib". Add both to the list of additional dependencies.
. On this post they are using Visual Studio. But still if both of those libraries are needed in that for that compiler then maybe you'll also need it. I wouldn't be surprised if i was way off. I'm just reading as much as I can on C++ and everything actually on this website; and figured it was worth taking a look into.
-
October 20th, 2010, 04:53 AM
#19
Re: MySQL Connector C++ "linker" error.
Originally Posted by viperbyte
Howdy RealChamp. At this link [link]http://blog.ulf-wendel.de/?p=215[/link] about two thirds down the page there's a bit that says
Code:
As said, you need to link both "mysqlcppconn-static.lib" and "libmysql.lib". Add both to the list of additional dependencies.
. On this post they are using Visual Studio. But still if both of those libraries are needed in that for that compiler then maybe you'll also need it. I wouldn't be surprised if i was way off. I'm just reading as much as I can on C++ and everything actually on this website; and figured it was worth taking a look into.
Thanks alot! I linked the mysqlcppconn-static to the project too(on Debian, still).
Code:
# g++ hw.cpp -o hw -lmysqlcppconn-static -lmysqlcppconn
/usr/bin/ld: warning: libstdc++.so.5, needed by /usr/local/lib/libmysqlcppconn.so, may conflict with libstdc++.so.6
# ./hw
terminate called after throwing an instance of 'sql::InvalidArgumentException'
what(): You should not call directly the constructor
Aborted
Tell me if I'm compiling it wrong, because I do not know. Also I've changed abit in the code, but this run error annoyes me(the terminate called after throwing an instance of 'sql::InvalidARgumentException')
New code:
Code:
#include <iostream>
#include <stdlib.h>
#include <mysql_connection.h>
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
#include <cppconn/prepared_statement.h>
int main(){
sql::Driver *driver;
sql::Connection *con;
sql::Statement *stmt;
sql::ResultSet *res;
sql::PreparedStatement *pstmt;
try{
driver = get_driver_instance();
con = driver->connect("tcp://127.0.0.1:3306", "root", "root");
con->setSchema("test");
stmt = con->createStatement();
stmt->execute("insert into example values(4,'four'),(5, 'five')");
delete stmt;
pstmt = con->prepareStatement("select * from example");
res = pstmt->executeQuery();
while (res->next())
std::cout<<res->getInt("id")<<" "<<res->getString("data")<<std::endl;
delete res;
delete pstmt;
pstmt = con->prepareStatement("delete from example where id=?");
pstmt->setInt(1,4);
pstmt->executeUpdate();
pstmt->setInt(1,5);
pstmt->executeUpdate();
delete pstmt;
delete con;
}catch(sql::SQLException &e){
std::cout<<e.what();
}
}
Been on Google to find a result for my problem, but it's not really the same I think.
It's something about memory, but I doubt that's the problem
Last edited by realchamp; October 20th, 2010 at 04:55 AM.
-
October 20th, 2010, 05:28 AM
#20
Re: MySQL Connector C++ "linker" error.
Originally Posted by realchamp
Tell me if I'm compiling it wrong, because I do not know. Also I've changed abit in the code, but this run error annoyes me(the terminate called after throwing an instance of 'sql::InvalidARgumentException')
Before you do anything else, are you using a debugger?
That exception is being thrown because one of those calls you're making caused the error, but you failed to mention at all which one of those lines is throwing the exception. This gives the impression that you're not using a debugger. You seem to be writing code and hoping something works, which is not the way a programmer is supposed to approach writing something such as you're doing.
You don't need Google searches -- what you need to do is identify the line that is causing the problem, and from there either debug into the library, or read the library documentation carefully to make sure you are doing things correctly.
Secondly, I don't know about the particular API you're using, but it is bad design to blindly call "delete" like that, unless it is documented that you must do this to release the memory. Usually the API takes care of the cleanup automatically, or the API gives you a function that you call to clean up the resources yourself.
If you supposed to call delete, then RAII certainly isn't high on this particular C++ wrapper's list, which is a shame.
Regards,
Paul McKenzie
-
October 20th, 2010, 05:50 AM
#21
Re: MySQL Connector C++ "linker" error.
Thanks for reply. I was not given a specific line where the error is from. But I will go check the documentation for a debug compiler, thanks!
Okay I've installed the g++ Debug. (apt-get install gdb) and compiled my program with an adionnally paramenter(-g).
Code:
This GDB was configured as "x86_64-linux-gnu"...
(gdb) run
Starting program: hw
[Thread debugging using libthread_db enabled]
Could not open /proc/25899/status
Could not open /proc/25899/status seems to be the problem and that is ... something about stats..
I've set a breakpoint at the initailization of the program(about line 1) and it throws me that error or incase I skip to the next error it's just something about a function..(Cannot find bounds of current function).
This line is the problem.
Code:
driver = get_driver_instance();
Last edited by realchamp; October 20th, 2010 at 06:32 AM.
-
October 20th, 2010, 06:36 AM
#22
Re: MySQL Connector C++ "linker" error.
Just for fun I would try also linking libmysql.lib if I knew how.
-
October 20th, 2010, 06:41 AM
#23
Re: MySQL Connector C++ "linker" error.
Originally Posted by viperbyte
Just for fun I would try also linking libmysql.lib if I knew how.
There are no such library, atleast not for Linux.
-
October 20th, 2010, 08:56 AM
#24
Re: MySQL Connector C++ "linker" error.
Originally Posted by realchamp
I've set a breakpoint at the initailization of the program(about line 1) and it throws me that error or incase I skip to the next error it's just something about a function..(Cannot find bounds of current function).
This line is the problem.
Code:
driver = get_driver_instance();
I suggest resorting to the old technique of putting printf()'s or couts to really see how far your program goes before it throws the exception:
Code:
printf("I am at point 1\n");
some SQL code...
printf("I am at point 2\n");
some SQL code...
etc...
So if the debugger is giving you a problem, at least you have that technique as a poor-mans debugger.
Secondly, if that line is the one that is actually throwing an exception, then I would conclude there is something wrong with the build, as that is the initialization function and nothing else needs to be done to call it.
Many times, library code just bombing out at the very function call indicates a build problem of the library (wrong build, bad build, etc.), or your own code is being built with the wrong switches used (more likely the latter if that library was already built for you). If you build your app with the wrong switches, improper constants, structs, etc. would be used by your app, differing what is in the library code. Yes, you get a build, but the build is a big mess where the same struct, class, etc. is defined differently in two places, causing random crashes.
Check that you built your code with the correct switches.
Regards,
Paul McKenzie
-
October 20th, 2010, 09:09 AM
#25
Re: MySQL Connector C++ "linker" error.
I hope you're not having that big mess that Paul said might be happening. I would go nuts if that was happening to me. I found this article usefull for me by the way in case you would be interested in it: http://dev.mysql.com/tech-resources/...ector-cpp.html
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|