C Compiling with mysql cpp connector (-lmysqlcppconn) - core dumped

Hello,

trying to compile a simpliest project with mysql support:
C++:
#include <iostream>

using namespace std;

int main(){
    cout << "Hello world" << endl;

    return 0;
}

compile with g++:
$g++ main.cpp -Wall -std=c++11 -lmysqlcppconn -o mysql-test
$ ./mysql-test
Segmentation fault (core dumped)


compile with c++:

$ c++ main.cpp -Wall -std=c++11 -lmysqlcppconn -o mysql-test
...
/usr/bin/ld: cannot find -lmysqlcppconn


in addition:

$ ll /usr/local/include/mysql*.h
-rw-r--r-- 1 root wheel uarch 5460 May 10 2017 /usr/local/include/mysql_connection.h
-rw-r--r-- 1 root wheel uarch 2825 May 10 2017 /usr/local/include/mysql_driver.h
-rw-r--r-- 1 root wheel uarch 1562 May 10 2017 /usr/local/include/mysql_error.h

$ pkg info | grep mysql
mysql-connector-c++-1.1.9_5 MySQL database connector for C++
mysql57-client-5.7.23 Multithreaded SQL database (client)
mysql57-server-5.7.23 Multithreaded SQL database (server)

 
Do you mind compiling with c++ -Wall -g -O0? This will disable optimizations (-O0) and will include debug information (-g) in the executable. Next start through gdb(1): gdb ./mysql-test, run, and ask for a stack trace: backtrace; info shared might also come in handy.

Perhaps you'll have to use right compiler; not sure if you can mix C++ objects built with clang(1) and g++ (GNU C++ compiler).

/usr/bin/ld: cannot find -lmysqlcppconn
Just add -L/usr/local/lib (location, where libmysqlcppconn.so is) in the link phase.
 
any suggestion why GCC cause segmentation fault ? I got cross platform project built with GCC....

my gcc verstion: gcc version 7.3.0 (FreeBSD Ports Collection)
built from ports: lang/gcc
 
any suggestion why GCC cause segmentation fault ? I got cross platform project built with GCC....
Perhaps you'll have to use right compiler; not sure if you can mix C++ objects built with clang(1) and g++ (GNU C++ compiler).
Like if databases/mysql-connector-c++ is built with clang(1), you'll have to use c++ when compiling C++ code to link against it. If you insist on using g++, you'll have to remove the port and compile mysql-connector with g++. Otherwise you mix two C++ runtimes.
 
yeah, you are right ... sory for stupid question, I realized it too late ... Thanks!
Hi, Though it is a stupid question for you, I can't understand this. What would happen if we keep port? and after removing the port also there is the same error when I execute the query? please help me.
 
Back
Top