当前位置: 首页 > 工具软件 > Qjson > 使用案例 >

qjson编译方法

齐承运
2023-12-01

网上有人总结过编译方法,本人参考其方法,无论如何也不能编译成功,只能自己解决问题。

经过查看相关资料,已经解决QJson编译问题,现总结如下,给后来者以指导。

 

qjson是qt下第三方开源库,由于没有pro文件只能用cmake方式编译,如果没有特殊说明,按照readme说明进行编译,在windows下会有问题。

我机器上面安装了vs2010和qt mingw两个编译环境;cmake缺省检测到vs2010对qjson进行编译导致qt没有相应库文件而失败,所以在configuration时必须指定编译信息。

下面说一下编译步奏。

1.下载安装cmake,假设安装路径为D:\Qt\cmake-2.8.10.2-win32-x86\

2.从QT菜单【Qt 4.8.3 Command Prompt】中进入命令行窗口,执行下面命令

set path=%path%;D:\Qt\cmake-2.8.10.2-win32-x86\bin

该命令行是设置cmake路径

3.在qjson目录下执行下面命令:

a).cmake -G "MinGW Makefiles" -DCMAKE_INSTALL_PREFIX=./
 

执行结果如下:

-- The C compiler identification is GNU 4.4.0
-- The CXX compiler identification is GNU 4.4.0
-- Check for working C compiler: D:/Qt/qtcreator-2.2.0/mingw/bin/gcc.exe
-- Check for working C compiler: D:/Qt/qtcreator-2.2.0/mingw/bin/gcc.exe -- wo
s
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: D:/Qt/qtcreator-2.2.0/mingw/bin/g++.exe
-- Check for working CXX compiler: D:/Qt/qtcreator-2.2.0/mingw/bin/g++.exe --
rks
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Looking for Q_WS_X11
-- Looking for Q_WS_X11 - not found
-- Looking for Q_WS_WIN
-- Looking for Q_WS_WIN - found
-- Looking for Q_WS_QWS
-- Looking for Q_WS_QWS - not found
-- Looking for Q_WS_MAC
-- Looking for Q_WS_MAC - not found
-- Found Qt4: d:/Qt/4.8.3/bin/qmake.exe (found version "4.8.3")
-- Configuring done
-- Generating done
-- Build files have been written to: D:/Qt/qjson/qjson-0.8.11

 

注意,cmake时,-G参数必须指定,否则会出现类似如下错误。网上大部分文章和readme文件也没说明,本人由于此参数折腾了需求,不得已查文档才解决问题。

CMake Error at D:/Qt/cmake-2.8.10.2-win32-x86/share/cmake-2.8/Modules/FindQt4.cm
ake:599 (message):
  It appears you're trying to use Visual Studio with Qt built by mingw.
  Those compilers do not produce code compatible with each other.
Call Stack (most recent call first):
  CMakeLists.txt:35 (FIND_PACKAGE)

 

b).执行make,结果如下:

[  9%] Generating moc_serializerrunnable.cxx
[ 18%] Generating moc_parserrunnable.cxx
Scanning dependencies of target qjson
[ 27%] Building CXX object src/CMakeFiles/qjson.dir/parser.cpp.obj
[ 36%] Building CXX object src/CMakeFiles/qjson.dir/qobjecthelper.cpp.obj
[ 45%] Building CXX object src/CMakeFiles/qjson.dir/json_scanner.cpp.obj
[ 54%] Building CXX object src/CMakeFiles/qjson.dir/json_parser.cc.obj
[ 63%] Building CXX object src/CMakeFiles/qjson.dir/parserrunnable.cpp.obj
[ 72%] Building CXX object src/CMakeFiles/qjson.dir/serializer.cpp.obj
[ 81%] Building CXX object src/CMakeFiles/qjson.dir/serializerrunnable.cpp.obj
[ 90%] Building CXX object src/CMakeFiles/qjson.dir/moc_parserrunnable.cxx.obj
[100%] Building CXX object src/CMakeFiles/qjson.dir/moc_serializerrunnable.cxx.o
bj
Linking CXX shared library ..\lib\libqjson.dll
Creating library file: ..\lib\libqjson.dll.a
Copying OS X content lib/Headers/parser.h
Copying OS X content lib/Headers/parserrunnable.h
Copying OS X content lib/Headers/qjson_export.h
Copying OS X content lib/Headers/qobjecthelper.h
Copying OS X content lib/Headers/serializer.h
Copying OS X content lib/Headers/serializerrunnable.h
[100%] Built target qjson

至此qjson已经编译完成,头文件和库文件在lib目录下,copy到自己工程下可以使用了。

 

 类似资料: