CLion:未定义的“_get_driver_instance"; [英] CLion: undefined "_get_driver_instance"

查看:68
本文介绍了CLion:未定义的“_get_driver_instance";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

IDE:CLion
系统:OS X
错误提示:

The IDE : CLion
System: OS X
Error message:

Scanning dependencies of target librarySystem
[ 66%] Building CXX object    CMakeFiles/librarySystem.dir/sqlConnection.cpp.o
[ 66%] Building CXX object CMakeFiles/librarySystem.dir/main.cpp.o
[100%] Linking CXX executable librarySystem
Undefined symbols for architecture x86_64:
  "_get_driver_instance", referenced from:
  sqlConnection::sqlConnection() in sqlConnection.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see     invocation)
make[2]: *** [librarySystem] Error 1
make[1]: *** [CMakeFiles/librarySystem.dir/all] Error 2
make: *** [all] Error 2

我写了一个名为sqlConnection的类来连接mysql.

I write a class named sqlConnection to connect mysql.

sqlConection.h

sqlConection.h

#include "sqlConnection.h"

sqlConnection::sqlConnection() {
    driver = get_driver_instance();
    con = driver->connect("567aaffa1a70e.sh.cdb.myqcloud.com:xxxx", "xxxx", "xxxx");
    con->setSchema("librarySys");
    stmt = con->createStatement();
}

bool sqlConnection::ifConnected() {

bool isConnected = false;
if(!con->isClosed()){
    std::cout << "Succeed to connect mysql";
    isConnected = true;
}else{
    std::cout << "fail to connect mysql";
}
return isConnected;
}

sqlConnection::~sqlConnection() {
delete stmt;
delete con;
}

main.cpp中的测试main.cpp

The test in the main.cpp main.cpp

#include <iostream>
#include "sqlConnection.h"
using namespace std;

int main() {
sqlConnection *sqlC = new sqlConnection();
sqlC->ifConnected();
return 0;
}

cmakeList:

cmake_minimum_required(VERSION 3.3)
project(librarySystem)
INCLUDE_DIRECTORIES(sqlFiles/include)
INCLUDE_DIRECTORIES(sqlFiles/lib)
INCLUDE_DIRECTORIES(sqlFiles/include/cppconn)
INCLUDE_DIRECTORIES(/usr/local/lib/libmysqlcppconn.so)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++0x")
set(SOURCE_FILES main.cpp sqlConnection.cpp sqlConnection.h)
add_executable(librarySystem ${SOURCE_FILES})

我用mysql connector-cpp连接mysql,但是问题来了,网上的解决方法试过了,没用.

I used mysql connector-cpp to connect mysql.But the problem came.Have tried the solution on web,but they did't work.

推荐答案

遇到了同样的错误,我得到了一个小例子来处理这个 CMakeLists.txt 内容.即使版本不同,也可能对您有所帮助.

Struggled with the same error and I got a small example to work with this CMakeLists.txt content. Maybe it's helpful for you even if its not same versions.

cmake_minimum_required(VERSION 3.5)
project(TestCPP)

#For mysql connector include..
INCLUDE_DIRECTORIES(/mypath/mysql-connector-c++-1.1.7-osx10.10-x86-64bit/include/)

#For Boost..
INCLUDE_DIRECTORIES(/opt/local/include/)

#For imported linking..
add_library(libmysqlcppconn STATIC IMPORTED)

set_property(TARGET libmysqlcppconn PROPERTY IMPORTED_LOCATION /mypath/mysql-connector-c++-1.1.7-osx10.10-x86-64bit/lib/libmysqlcppconn-static.a)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp)

add_executable(TestCPP ${SOURCE_FILES})

target_link_libraries (TestCPP libmysqlcppconn)

这篇关于CLion:未定义的“_get_driver_instance";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆