简体   繁体   English

使用MINGW32在Debian上使用C ++和MySQL进行编译

[英]Compile with C++ & MySQL on Debian using MINGW32

I cannot get this to compile, I had to move around the files abit to get them included. 我无法编译此文件,我不得不四处移动文件以使其包含在内。

COMPILE.SH COMPILE.SH

#!/bin/bash
i586-mingw32msvc-g++ -o widget.exe main.cpp -I /usr/include/boost/ -L /usr/lib/x86_64-linux-gnu/libmysqlclient.so

ERROR 错误

/tmp/cci9fwk8.o:main.cpp:(.text+0x526): undefined reference to `__imp___ZN3sql5mysql19get_driver_instanceEv'
collect2: ld returned 1 exit status

I found more than 10 guides and I followed them exactly, installing all dependencies, adding the mysqlclient etc and nothing works. 我找到了10多个指南,并且完全遵循它们,安装了所有依赖项,添加了mysqlclient等,但没有任何效果。

MAIN.CPP (JUST A PART, REST OF CODE IS NOT NEEDED) MAIN.CPP(仅一部分,不需要其余代码)

    #include <cstdlib>
    #include <iostream>
    #include <string>
    #include <sstream>
    #include <cstdio>
    #include <windows.h>
    #include <fstream>
    #include <stdio.h>
    #include <direct.h>
    #include "/usr/include/cppconn/mysql_connection.h"
    #include "/usr/include/cppconn/mysql_driver.h"
    #include </usr/include/cppconn/cppconn/driver.h>
    #include </usr/include/cppconn/cppconn/exception.h>
    #include </usr/include/cppconn/cppconn/resultset.h>
    #include </usr/include/cppconn/cppconn/statement.h>
    using namespace std;


    sql::Connection *con;
    sql::Statement *stmt;
    sql::ResultSet *res;
    sql::mysql::MySQL_Driver *driver;
    driver = sql::mysql::get_driver_instance();
    con = driver->connect("", "", "");
    con->setSchema("");

ldd /usr/lib/x86_64-linux-gnu/libmysqlclient.so ldd /usr/lib/x86_64-linux-gnu/libmysqlclient.so

   linux-vdso.so.1 =>  (0x00007fff21eba000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fb027f52000)
        libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007fb027d3b000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fb027b36000)
        librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fb02792e000)
        libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fb027627000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fb0273a4000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fb02718e000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fb026e03000)
        /lib64/ld-linux-x86-64.so.2 (0x00007fb0286c0000)

Usually, errors like: 通常,错误如下:

undefined reference to `__imp___ZN3sql5mysql19get_driver_instanceEv'

happens when: 发生在以下情况:

  • there are not implemented methods 没有实现的方法
  • you have two or more version of library 您有两个或更多版本的库
  • header is in version x, source in vesion y. 标头在版本x中,来源在版本y中。

Tell you what to do it's a bit difficult if you don't have some linux skills... maybe mysql use a different version of libboost, I'm not sure. 告诉你该怎么做,如果您不具备一些Linux技能,那会有点困难...也许mysql使用其他版本的libboost,我不确定。

Try: 尝试:

ldd /usr/lib/x86_64-linux-gnu/libmysqlclient.so

This show you what libraries is needed by libmysqlclient.so 这显示了libmysqlclient.so需要哪些库

If there're a lot of dependecies, you can: 如果存在很多依赖关系,则可以:

ldd /usr/lib/x86_64-linux-gnu/libmysqlclient.so | grep boost

And check if boost version is the same: 并检查boost版本是否相同:

cat /usr/include/boost/version.hpp | grep "BOOST_LIB_VERSION"

edit: 编辑:

By the way I suggest you to compile with: 顺便说一句,我建议您编译:

-I /usr/include -L /usr/lib -lcppconn

that could be not necessary, but just for sure. 那可能不是必须的,但可以肯定。 And then include in main in this way: 然后以这种方式主要包含:

#include <cppconn/mysql_connection.h>
#include <cppconn/mysql_driver.h>
#include <cppconn/cppconn/driver.h>
#include <cppconn/cppconn/exception.h>
#include <cppconn/cppconn/resultset.h>
#include <cppconn/cppconn/statement.h>

All with <>, and not with "". 全部带有<>,而不带有“”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM