FreeCAD采用了基于约束/特征的全参数化三维建模方法,作为一款开源CAD代码,近几年在国内s受到了越来越多的从业人员(特别是国产CAx软件开发人员)的欢迎。三年前,笔者写了一篇博文讲述在Windows下编译FreeCAD 0.18:FreeCAD编译、安装、开发环境。
在这期间,不少朋友也向笔者反应了一些新版本编译的问题。因此,本文记录在Windows下编译安装FreeCAD 0.21的流程,希望对大家有帮助。
操作系统 | Windows 11 |
Visual Studio | Visual Studio Community 2022 |
CMake | CMake 3.24.2 |
Doxygen | Doxygen-1.9.8 |
git clone https://github.com/FreeCAD/FreeCAD.git
cd ./FreeCAD/
git checkout -b FreeCAD-0-21 origin/releases/FreeCAD-0-21
从GitHub下载FreeCAD LibPack-0.21 Version 2.10。
从GitHub下载fmt-9.1.0.zip。
按照下表配置CMake,并完成构建与生成,
Where is the source code | D:\YouQuan\CaeFrameworks\FreeCAD | |
Where to build the binaries | D:\YouQuan\CaeFrameworks\FreeCAD\BUILD\FreeCAD-0.21 | |
CMAKE_INSTALL_PREFIX | D:/YouQuan/CaeFrameworks/FreeCAD/INSTALL/FreeCAD-0.21 | |
FREECAD_LIBPACK_DIR | D:/YouQuan/CaeFrameworks/FreeCAD/LibPack-0.21-V2.10 | |
FREECAD_USE_EXTERNAL_FMT | FALSE | |
FETCHCONTENT_SOURCE_DIR_FMT | D:/YouQuan/CaeFrameworks/FreeCAD/fmt-9.1.0 | LibPack仅提供了Release版本的fmtlib |
FREECAD_USE_MP_COMPILE_FLAG | FALSE | 若开启,编译需要较大内存 |
BUILD_TEST | FALSE | |
打开FreeCAD.sln,构建"ALL_BUILD"完成FreeCAD编译;构建"INSTALL"完成FreeCAD安装。
问题:Error C1060 compiler is out of heap space
Error C1060 compiler is out of heap space (compiling source file D:\YouQuan\CaeFrameworks\FreeCAD\FreeCAD\src\Mod\PartDesign\App\ShapeBinder.cpp) PartDesign D:\YouQuan\CaeFrameworks\FreeCAD\fmt-9.1.0\include\fmt\printf.h 402
解决:在cMake/FreeCAD_Helpers/SetGlobalCompilerAndLinkerSettings.cmake中,"FREECAD_USE_MP_COMPILE_FLAG"默认情况下开启,以加速FreeCAD编译,但需要较多的内存。可以在CMake中,将"FREECAD_USE_MP_COMPILE_FLAG"设为"FALSE"。
问题:在编译TechDrawGui时,字符串报错
Error C2001 newline in constant TechDrawGui D:\YouQuan\CaeFrameworks\FreeCAD\FreeCAD\src\Mod\TechDraw\Gui\TaskSurfaceFinishSymbols.cpp 89
Error C2143 syntax error: missing ')' before '}' TechDrawGui D:\YouQuan\CaeFrameworks\FreeCAD\FreeCAD\src\Mod\TechDraw\Gui\CommandExtensionDims.cpp 175
Error C2146 syntax error: missing ')' before identifier 'roughGrades' TechDrawGui D:\YouQuan\CaeFrameworks\FreeCAD\FreeCAD\src\Mod\TechDraw\Gui\TaskSurfaceFinishSymbols.cpp 90
Error C3680 cannot concatenate user-defined string literals with mismatched literal suffix identifiers TechDrawGui D:\YouQuan\CaeFrameworks\FreeCAD\FreeCAD\src\Mod\TechDraw\Gui\TaskSurfaceFinishSymbols.cpp 89
Error C3688 invalid literal suffix 'X'; literal operator or literal operator template 'operator ""X' not found TechDrawGui D:\YouQuan\CaeFrameworks\FreeCAD\FreeCAD\src\Mod\TechDraw\Gui\TaskSurfaceFinishSymbols.cpp 89
解决:TaskSurfaceFinishSymbols.cpp、CommandExtensionDims.cpp文件中使用了UTF-8无法解析的符号。将其使用Notepad++以UTF-16进行编码保存。
问题:TechDrawGui编译时,提示有重复的函数定义
Error LNK2005 "public: virtual struct QMetaObject const * __cdecl TechDrawGui::TaskSurfaceFinishSymbols::metaObject(void)const " (?metaObject@TaskSurfaceFinishSymbols@TechDrawGui@@UEBAPEBUQMetaObject@@XZ) already defined in mocs_compilation_Debug.obj TechDrawGui D:\YouQuan\CaeFrameworks\FreeCAD\BUILD\FreeCAD-0.21\src\Mod\TechDraw\Gui\TaskSurfaceFinishSymbols.obj 1
解决:在TaskSurfaceFinishSymbols中,注释掉下行代码
#include
问题:Release下,编译TechDrawGui,提示找不到 'ui_TaskSurfaceFinishSymbols.h'
Error C1083 Cannot open include file: 'ui_TaskSurfaceFinishSymbols.h': No such file or directory TechDrawGui D:\YouQuan\CaeFrameworks\FreeCAD\FreeCAD\src\Mod\TechDraw\Gui\TaskSurfaceFinishSymbols.cpp 37
解决:将"TechDrawGui_autogen/include_Debug/ui_TaskSurfaceFinishSymbols.h"拷贝到"TechDrawGui_autogen/include_Release/ui_TaskSurfaceFinishSymbols.h"。
问题:VS中,设置FreeCADMain为启动项目,调试时缺少python38_d.dll、Qt5Cored.dll、Qt5Widgetsd.dll、Qt5Guid.dll等库。
解决:设置FreeCADMain属性,指定PATH、FC_PYTHONHOME等环境变量
For Debug:
PATH=../../../../LibPack-0.21-V2.10/bind;../../../../LibPack-0.21-V2.10/bin;$(Path)
FC_PYTHONHOME=../../../../LibPack-0.21-V2.10/bin
For Release:
PATH=../../../../LibPack-0.21-V2.10/bin;$(Path)
FC_PYTHONHOME=../../../../LibPack-0.21-V2.10/bin
FreeCADhttps://github.com/FreeCAD/FreeCAD
FreeCAD-LibPackhttps://github.com/FreeCAD/FreeCAD-LibPack
FreeCAD Documention: Compile on Windowshttps://wiki.freecad.org/Compile_on_Windows
FreeCAD编译、安装、开发环境https://blog.csdn.net/qq_26221775/article/details/106172142?spm=1001.2014.3001.5502