解决
我目前正在研究 LabWindows/CVI,这是一个 C。唯一支持的 C 版本是 c99。我正在尝试将 Google Flatbuffers(c 版本flatcc)集成到我当前的项目中。当我尝试链接我的解决方案时,我遇到了链接错误:
第一个问题:我该如何解决这个错误?
根据供应商的说法,LabWindows/CVI 使用CLANG 作为编译器。如果我看一下符号aligned_free /algined_malloc 出现的文件,我可以读到:
/*
* NOTE: MSVC in general has no aligned alloc function that is
* compatible with free and it is not trivial to implement a version
* which is. Therefore, to remain portable, end user code needs to
* use `aligned_free` which is not part of C11 but defined in this header.
*
* glibc only provides aligned_alloc when _ISOC11_SOURCE is defined, but
* MingW does not support aligned_alloc despite of this, it uses the
* the _aligned_malloc as MSVC.
*
* The same issue is present on some Unix systems not providing
* posix_memalign.
*
* Note that clang and gcc with -std=c11 or -std=c99 will not define
* _POSIX_C_SOURCE and thus posix_memalign cannot be detected but
* aligned_alloc is not necessarily available either. We assume
* that clang always has posix_memalign although it is not strictly
* correct. For gcc, use -std=gnu99 or -std=gnu11 or don't use -std in
* order to enable posix_memalign, or live with the fallback until using
* a system where glibc has a version that supports aligned_alloc.
*
* For C11 compliant compilers and compilers with posix_memalign,
* it is valid to use free instead of aligned_free with the above
* caveats.
*/
第二个问题:根据上面的文字,我应该有aligned_free/aligned_malloc的定义,但由于某种原因,我没有它。为什么 ?我错过了什么?
附加信息: LabWindows/CVI 只接受 .lib 作为 lib(没有 .a),所以我必须使用 Cmake 和 MSVS19 编译 flatcc。我尝试了几种配置,但无事可做,我总是遇到同样的错误。
最良好的问候
编辑:我通过执行以下 cmake 命令修复了一个未定义的符号“__allmul”:
cmake -G "MinGW Makefiles" -DCMAKE_C_COMPILER=x86_64-w64-mingw32-c99 -DFLATCC_PORTABLE=true -DFLATCC_ALLOW_WERROR=false -DBUILD_TESTING=false -DFLATCC_CXX_TEST=false -DFLATCC_REFLECTION=false -B .
然后编辑flatcc\src\compiler\CMakeFiles\flatcc.dir\flags.make
和flatcc\src\runtime\CMakeFiles\flatcc.dir\flags.make
看起来像这样:C_FLAGS = -m32 -DFLATCC_REFLECTION=0 -Wstrict-prototypes -Wsign-conversion -Wconversion -std=c99 -pedantic -Wall -Wextra -DFLATCC_PORTABLE
-m32 是 32 位二进制和 -std=c99 而不是 -std=c11 (不能放 c89 因为 flatcc 包含一些内联关键字)
然后编辑flatcc\src\compiler\CMakeFiles\flatcc.dir\link.txt
并flatcc\src\runtime\CMakeFiles\flatcc.dir\link.txt
看起来像这样:
...\bin\clang\bin\ar.exe rc ..\..\..\lib\flatcc.lib CMakeFiles/flatcc.dir/__/__/external/hash/cmetrohash64.c.obj ...
...bin\clang\bin\ranlib.exe ..\..\..\lib\flatcc.lib
然后运行Mingw32-make.exe