scons

##awtk

遇到的问题:
编译1.7.0很顺利,后来项目代码用的1.6.1,在linux上面编译比较顺利,但是在windows上有些问题
1、Cannot find module 'glob'

exe cmd: node tools/idl_gen/tkc.js tools/idl_gen/tkc.json failed.
node tools/idl_gen/index.js tools/idl_gen/idl.json
internal/modules/cjs/loader.js:883
  throw err;
  ^

Error: Cannot find module 'glob'

解决:node安装glob模块
npm install -g glob

$ npm install -g glob

Command 'npm' not found, but can be installed with:

sudo apt install npm

$ node -v
v10.19.0
$ npm -v

Command 'npm' not found, but can be installed with:

sudo apt install npm

$ sudo apt install npm
^Citing for cache lock: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 866352 (unattended-upgr)... 12s
$ sudo rm /var/lib/dpkg/lock-frontend
$ sudo rm /var/lib/dpkg/lock 

$ sudo apt install npm
# sucess

$ npm install -g glob
[..................] / rollbackFailedOptional: verb npm-session 616c6ae6d03da9b9
# or
$ npm install -g glob
npm WARN checkPermissions Missing write access to /usr/local/lib

$ sudo npm config set registry http://registry.npm.taobao.org
$ sudo npm install -g glob
npm WARN notsup Unsupported engine for glob@8.0.3: wanted: {"node":">=12"} (current: {"node":"10.19.0","npm":"6.14.4"})
npm WARN notsup Not compatible with your version of node/npm: glob@8.0.3

+ glob@8.0.3

2、无法解析的外部符号 _DllMainCRTStartup

  正在创建库 bin\awtk.lib 和对象 bin\awtk.exp
LINK : error LNK2001: 无法解析的外部符号 _DllMainCRTStartup
bin\awtk.dll : fatal error LNK1120: 1 个无法解析的外部命令
scons: *** [bin\awtk.dll] Error 1120

解决:修改scons的脚本
awtk.dll不需要入口,因此增加 /NOENTRY选项,找到python或者venv中的scons脚本位置,简单的办法就是直接对py文件按照关键字/dll或者/DEBUG搜索。
mslink.pypdbGenerator函数中增加 /NOENTRY

def pdbGenerator(env, target, source, for_signature):
    try:
        return ['/PDB:%s' % target[0].attributes.pdb, '/DEBUG  /NOENTRY']
    except (AttributeError, IndexError):
        return None

在这里插入图片描述

windows下用vs2019调试awtk项目

vs2019可以打开awtk项目,使用外部程序编译并调试(可能是我的python环境的问题,也可能其他原因,没有设置成功,编译时有找不到头文件的错误提示)

于是仍然使用命令行scons编译demo.exe文件,运行demo.exe程序,

使用vs2019打开awtk项目,配置项目(头文件库文件等),

“调试” -> “附加到进程”-> “找到demo.exe” -> “附加进程”,在源代码设置断点就可以调试exe了。

在 windows 下使用 gcc 编译 AWTK

在 windows 下,如果不想使用 Visual C++编译,也可以使用 gcc 编译。

  • 下载并安装 mingw(opens new window)

64 位系统安装时 architecturex 选择 x86_64。

尽量选择最新的版本来安装,版本如果太旧的话,可能编译不通过,如果编译不过的话,可以考虑升级版本来试一下。

安装之后将 gcc 的路径加入系统环境变量 PATH 中。默认路径如下:

E:\dev\x64-4.8.1-release-posix-seh-rev5\mingw64\bin  
  • 修改 awtk_config_common.py,放开注释掉的 TOOLS_NAME。
TOOLS_NAME = 'mingw'
  • 编译
scons

WSL中不能编译awtk !!!

没有ui支持

编译项目时切换不同版本的awtk SDK

在项目的awtk_locator.py中,

AWTK_ROOT = r'D:\src\gitee\awtk-1.5.4\awtk'

awtk 打包资源时使用指定的awtk root

python .\scripts\update_res.py --awtk_root=D:/src/AWStudioProjects/awtk-1.5.4 all

awtk项目scons后面指定awtk root

最新awtk-c-demos中脚本可以指定awtkroot

'awtk_root=', 'AWTK_ROOT='
scons AWTK_ROOT=D:/src/AWStudioProjects/awtk
scons awtk_root=D:/src/AWStudioProjects/awtk

调试awtk的xml_to_ui.exe

vs2019调试xml_to_ui,由于使用scons编译,awtk源码由awtk代码根目录的SConstruct定义总体环境,所以vcxproj工程的根目录是awtk源码根目录,在源码根目录中添加awtk-1.5.4.vcxprojawtk-1.5.4.vcxproj.user文件。
awtk-1.5.4.vcxproj文件内容(可作为调试awtk 项目的vs2019项目的模板)

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup Label="ProjectConfigurations">
    <ProjectConfiguration Include="Debug|Win32">
      <Configuration>Debug</Configuration>
      <Platform>Win32</Platform>
    </ProjectConfiguration>
  </ItemGroup>
  <ItemGroup>
    <ClCompile Include="src\tkc\str.c" />
    <ClCompile Include="tools\ui_gen\xml_to_ui\xml_to_ui.c" />
  </ItemGroup>
  <PropertyGroup Label="Globals">
    <VCProjectVersion>16.0</VCProjectVersion>
    <ProjectGuid>{9491F8C4-CC42-414E-AF49-45B76C949FDF}</ProjectGuid>
    <Keyword>MakeFileProj</Keyword>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
    <ConfigurationType>Makefile</ConfigurationType>
    <UseDebugLibraries>true</UseDebugLibraries>
    <PlatformToolset>v142</PlatformToolset>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <PropertyGroup Label="UserMacros" />
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <NMakeBuildCommandLine>scons</NMakeBuildCommandLine>
    <NMakeOutput>bin\xml_to_ui.exe</NMakeOutput>
    <NMakeCleanCommandLine>scons -c</NMakeCleanCommandLine>
    <NMakeReBuildCommandLine>scons</NMakeReBuildCommandLine>
    <NMakePreprocessorDefinitions>WIN32;_DEBUG;$(NMakePreprocessorDefinitions)</NMakePreprocessorDefinitions>
    <IncludePath>D:\src\AWStudioProjects\awtk-1.5.4\tools;D:\src\AWStudioProjects\awtk-1.5.4\src\ext_widgets;D:\src\AWStudioProjects\awtk-1.5.4\src;$(VC_IncludePath);$(WindowsSDK_IncludePath)</IncludePath>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
</Project>

其中根据源码和可执行程序不同,配置不同的IncludePath and NMakeOutput;
如果需要设置断点,将.c文件包括到项目的ClCompile中。


因为调试的是工具,所以在awtk-1.5.4.vcxproj.user中指定命令行参数,
awtk-1.5.4.vcxproj.user文件内容:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <ShowAllFiles>true</ShowAllFiles>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <LocalDebuggerCommandArguments>"D:\src\AWStudioProjects\Humidifier\design\default\ui" "D:\src\AWStudioProjects\Humidifier\res\assets\default\raw\ui" bin</LocalDebuggerCommandArguments>
    <DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
  </PropertyGroup>
</Project>

紧在windows中做一般调试,所以只配置了Debug|Win32的环境;
两个文件保存好后,使用vs2019打开vcxproj文件,在源代码中设置断点,F5开始调试。


版权声明:本文为mlz_2原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/mlz_2/article/details/126727346