我目前正在学习 c++ 并想尝试使用数据库并遇到 SQLAPI++。因为我喜欢 JetBrains 的 IDE,所以我使用 CLion。作为编译器,我开始使用 Cygwin 编译器,并在本周下载了 Visual Studio 编译器以使 SQLAPI++ 正常工作。所以终于感觉准备好了,就像现在编译可以工作一样,我得到了链接错误。
NMAKE : fatal error U1077: ""C:\Program Files\JetBrains\CLion 2021.1.3\bin\cmake\win\bin\cmake.exe"": Exit-Code "0xffffffff"
Stop.
NMAKE : fatal error U1077: ""E:\Programs\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\bin\HostX86\x86\nmake.exe"": Exit-Code "0x2"
Stop.
NMAKE : fatal error U1077: ""E:\Programs\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\bin\HostX86\x86\nmake.exe"": Exit-Code "0x2"
Stop.
NMAKE : fatal error U1077: ""E:\Programs\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\bin\HostX86\x86\nmake.exe"": Exit-Code "0x2"
Stop.
sqlapis.lib(samisc.obj) : error LNK2019: Reference to non listed extern Symbol "_GetFileVersionInfoSizeA@8" in function ""void * __cdecl SAGetVersionInfo(char const *)" (?SAGetVersionInfo@@YAPAXPBD@Z)".
sqlapis.lib(samisc.obj) : error LNK2019: Reference to non listed extern Symbol "_GetFileVersionInfoA@16" in function ""void * __cdecl SAGetVersionInfo(char const *)" (?SAGetVersionInfo@@YAPAXPBD@Z)".
sqlapis.lib(samisc.obj) : error LNK2019: Reference to non listed extern Symbol "_VerQueryValueA@16" in function ""long __cdecl SAGetFileVersionFromString(char const *)" (?SAGetFileVersionFromString@@YAJPBD@Z)".
这是我的 CMakeLists:
cmake_minimum_required(VERSION 3.19)
project(Project)
set(CMAKE_CXX_STANDARD 20)
set(Boost_USE_STATIC_LIBS OFF)
set(LIBS "C:/Users/Maximilian/Documents/C C++/librarys")
include_directories(Project ${LIBS}/SQLAPI/include/)
add_executable(Project main.cpp src/Project.cpp src/Project.h)
target_link_libraries(Project ${LIBS}/SQLAPI/vs2019/lib/sqlapis.lib)
target_link_libraries(Project ${LIBS}/SQLAPI/vs2019/lib/sqlapisd.lib)
这是我复制的示例代码:
#include <iostream>
#include <SQLAPI.h>
int main(int argc, char* argv[])
{
SAConnection saConnection;
try {
saConnection.Connect(_TSA("localhost:3306"), _TSA("MaxBas"), _TSA("maxi2004"));
printf("We are connected!\n");
saConnection.Disconnect();
printf("We are disconnected!\n");
}
catch(SAException &x) {
saConnection.Rollback();
printf("%s\n", x.ErrText().GetMultiByteChars());
}
return 0;
}