SQLiteStudio在msvc 2015下的编译
1.下载源码
下载master分支的压缩包
Qt版本需要大于5.12.0,我用的5.13.2
2.将工程导入到vs2015中
1.解压master源码包,定位到\sqlitestudio-master\SQLiteStudio3下,找到\SQLiteStudio3.pro 工程文件
2.打开vs2015使用“Qt VS Tools"插件–>”Open Qt Project File (.pro)“打开上述工程文件完成源码导入
3.肉测只有core…,gui…,SqliteStudio 是客户端主要构成,第一个是核心库,第二个是界面库,第三个是app框架
4.将三个工程都转换为”Convert Project To Qt VS Tools Project"(工程文件点击右键由此菜单”)
3.编译coreSQLiteStudio
编译核心库,估计源码是采用mingw编译器编译,其中有些编译器属性vs没有:
1.configimpl.cpp
coreSQLiteStudio\services\impl\configimpl.cpp
文件中的
__attribute__((__fallthrough__));
改为
#ifndef _MSC_VER
__attribute__((__fallthrough__));
#endif
2.windowscrashhandler
coreSQLiteStudio\chillout\windows\windowscrashhandler.h WindowsCrashHandler类中缺少 m_crtReportHook成员 添加
private:
_CRT_REPORT_HOOK m_crtReportHook = nullptr;
windowscrashhandler.cpp中未找到GetExceptionPointers,目测跟捕捉crash异常有关系屏蔽代码块好像影响不大:
// EXCEPTION_POINTERS* pExceptionPtrs = NULL;
// GetExceptionPointers(CR_CPP_INVALID_PARAMETER, &pExceptionPtrs);
//
// DoHandleCrash(pExceptionPtrs);
3.头文件中的全局变量修改为全局函数
coreSQLiteStudio\qio.h中的extern变量改为全局类函数,同理completionhelper.h中的静态成员变量也要改为函数
gcc编译后好像成员都能被外部链接到,但是vs好像不行会报链接错误。
qio.h:
API_EXPORT extern QTextStream qOut;
API_EXPORT extern QTextStream qIn;
API_EXPORT extern QTextStream qErr;
改为
class API_EXPORT Qio
{
public:
static QTextStream& getOut();
static QTextStream& getIn();
static QTextStream& getErr();
};
#define qOut Qio::getOut()
#define qIn Qio::getIn()
#define qErr Qio::getErr()
qio.cpp:
QTextStream qOut(stdout);
QTextStream qIn(stdin);
QTextStream qErr(stderr);
改为
static QTextStream qStdOut(stdout), qStdIn(stdin), qStdErr(stderr);
QTextStream& Qio::getOut()
{
return qStdOut;
}
QTextStream& Qio::getIn()
{
return qStdIn;
}
QTextStream& Qio::getErr()
{
return qStdErr;
}
completionhelper.h:
CompletionHelper类中静态成员
static bool enableLemonDebug;
改为
static bool isEnableLemonDebug();
static void setEnableLemonDebug(bool e);
completionhelper.cpp:
bool CompletionHelper::enableLemonDebug = false;
改为
static bool enableLemonDebug = false;
bool CompletionHelper::isEnableLemonDebug()
{
return enableLemonDebug;
}
void CompletionHelper::setEnableLemonDebug(bool e)
{
enableLemonDebug = e;
}
调用的地方(gui)不直接调用成员,改为调用静态函数
4.添加sqlite3源码
工程中是链接sqlite库,但是我手里没有要求的版本3.34.1,于是拿上手里有的版本进行静态编译 替换掉工程里的sqlite3.h头文件且将sqlite3.c添加到工程这样才能链接到sqlite3的函数
还有个坑的地方 由于之前工程采用链接sqlite库的方式在工程的C/C+±预处理器里面添加了(SQLITE_API="__declspec(dllexport)")这样的宏,这样的宏到了vs直接报xxxx字符串错误,,就算用库在vs下要改为(SQLITE_API=__declspec(dllexport))才行,但是现在是静态编译,删掉这个预处理宏就行,或者一开始在pro文件中删除"DEFINES += “SQLITE_API=”__declspec(dllexport)""".
4.编译guiSQLiteStudio
gui依赖于core
1.添加链接信息
gcc编译的原理就算是moc_xxx.cpp信息都是编译到了lib里面,但是vs编译方式没有declspec(dllexport)的方法都没在lib中,导致链接的时候找不到moc_cfgentry moc_db moc_BuiltInPlugin的一些方法.
最笨的方法:在mainwindow.cpp中include cpp:
#include "../../output/build/coreSQLiteStudio/moc_cfgentry.cpp"
#include "../../output/build/coreSQLiteStudio/moc_db.cpp"
#include "../../output/build/coreSQLiteStudio/moc_BuiltInPlugin.cpp"
…/…/output/build/coreSQLiteStudio是core生成中间文件的目录
2.编译器兼容
guiSQLiteStudio\dbtree\dbtreemodel.cpp:
stream << reinterpret_cast<qint32>(indexes.size());
改为
stream << static_cast<qint32>(indexes.size());
XByteArray.cpp中的and改为&& ,or改为||
guiSQLiteStudio\windows\editorwindow.cpp:
QPair boundries = getQueryBoundriesForPosition(contents, pos, fallBackToPreviousIfNecessary);
->
auto boundries = getQueryBoundriesForPosition(contents, pos, fallBackToPreviousIfNecessary);
5.编译sqlitestudio
删除windows.rc文件中的RT_MANIFEST资源
main.cpp:
# include <windef.h>
# include <windows.h>
->
# include <qt_windows.h>
CompletionHelper::enableLemonDebug = parser.isSet(lemonDebugOption);
->
CompletionHelper::setEnableLemonDebug(parser.isSet(lemonDebugOption));