在 Windows 上出现“对 `check' 的未定义引用”错误

问题描述 投票:0回答:0

我尝试使用连接器 C++ 8.0 将数据库连接到 C++。 当我编译一个非常简单的代码时:

#include <iostream>
#include <jdbc.h>

int main(){
    sql::Driver *driver;
    driver = get_driver_instance();
    
    return 0;
}

我得到这个错误:

c:/program files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\newva\AppData\Local\Temp\cc7Hgjeq.o:Main.cpp:(.text+0x1f): undefined reference to `check(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
c:/program files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\newva\AppData\Local\Temp\cc7Hgjeq.o:Main.cpp:(.text+0x53): undefined reference to `check(std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > > 
const&)'
c:/program files (x86)/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\newva\AppData\Local\Temp\cc7Hgjeq.o:Main.cpp:(.text+0xba): undefined reference to `_get_driver_instance_by_name'
collect2.exe: error: ld returned 1 exit status

当我评论“driver = get_driver_instance();”行,代码编译。

我用 Makefile 编译:

MYSQL_CONCPP_DIR = "C:\Program Files\MySQL\Connector C++ 8.0"
CPPFLAGS=-I $(MYSQL_CONCPP_DIR)\include\mysql -L $(MYSQL_CONCPP_DIR)\lib64
LDLIBS=-lmysqlcppconn8
CXXFLAGS=-std=c++20

result.exe:Main.cpp
    g++ Main.cpp ${CXXFLAGS} ${CPPFLAGS} ${LDLIBS} -o result.exe

我在 Windows 10 上。

c++ windows mysql-connector
© www.soinside.com 2019 - 2024. All rights reserved.