简体   繁体   English

flatcc 未定义符号aligned_free/aligned_malloc

[英]flatcc undefined symbol aligned_free/aligned_malloc

Resolved解决

I'm currently working on LabWindows/CVI, this is a C.我目前正在研究 LabWindows/CVI,这是一个 C。 The only version of C supported is c99.唯一支持的 C 版本是 c99。 I'm trying to integrate Google Flatbuffers (the c version flatcc ) to my current project.我正在尝试将 Google Flatbuffers(c 版本flatcc )集成到我当前的项目中。 When I'm trying to link my solution, I'm facing a linking error:当我尝试链接我的解决方案时,我遇到了链接错误: 链接错误

First question: how could I fix this error?第一个问题:我该如何解决这个错误?

According to the vendor, LabWindows/CVI use CLANG as compiler .根据供应商的说法,LabWindows/CVI 使用CLANG 作为编译器 if I take a look at the file where the symbol aligned_free /algined_malloc apear, I can read this:如果我看一下符号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.
 */

Second question: According to the text above, I should have definition of aligned_free/aligned_malloc, but for some reason, I don't have it.第二个问题:根据上面的文字,我应该有aligned_free/aligned_malloc的定义,但由于某种原因,我没有它。 Why?为什么? What I'm missing?我错过了什么?

Additionnal information: LabWindows/CVI only accepte.lib as lib (no.a) so I had to compile flatcc using Cmake and MSVS19.附加信息: LabWindows/CVI 只接受.lib 作为 lib (no.a),所以我必须使用 Cmake 和 MSVS19 编译 flatcc。 I have try several configuration but nothing to do I always get the same error.我尝试了几种配置,但无事可做,我总是遇到同样的错误。

Best regard最良好的问候

EDIT : I fixed one undefined symbol '__allmul' by doing this cmake command:编辑:我通过执行此 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.

Then editing flatcc\src\compiler\CMakeFiles\flatcc.dir\flags.make and flatcc\src\runtime\CMakeFiles\flatcc.dir\flags.make然后编辑flatcc\src\compiler\CMakeFiles\flatcc.dir\flags.makeflatcc\src\runtime\CMakeFiles\flatcc.dir\flags.make

to looks like that: C_FLAGS = -m32 -DFLATCC_REFLECTION=0 -Wstrict-prototypes -Wsign-conversion -Wconversion -std=c99 -pedantic -Wall -Wextra -DFLATCC_PORTABLE -m32 is for 32 bit binary and -std=c99 instead of -std=c11 (can't put c89 because flatcc contain some inline keyword)看起来像这样: 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 包含一些内联关键字)

Then editing flatcc\src\compiler\CMakeFiles\flatcc.dir\link.txt and flatcc\src\runtime\CMakeFiles\flatcc.dir\link.txt to look like this:然后编辑flatcc\src\compiler\CMakeFiles\flatcc.dir\link.txtflatcc\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

Then running Mingw32-make.exe然后运行Mingw32-make.exe

2 errors remain:仍然存在 2 个错误: 剩余误差

Could you try to compile flatcc as a static library and force the output as.lib instead of the (by default).a (with the "-o flatcc.lib" flag)?您能否尝试将 flatcc 编译为 static 库并强制 output as.lib 而不是(默认情况下).a(带有“-o flatcc.lib”标志)? The problem I guess is that you're using two different compilers here (msvc and clang), on the same plateform (win32), and clang by default could have a "unix way of doing things".我猜的问题是你在这里使用两个不同的编译器(msvc和clang),在同一个平台(win32)上,默认情况下clang可能有一个“unix做事方式”。 ;) ;)

But actually the important point here I guess is from this comment quote:但实际上我猜这里的重点是来自这个评论引用:

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.请注意,带有 -std=c11 或 -std=c99 的 clang 和 gcc 不会定义 * _POSIX_C_SOURCE ,因此无法检测到 posix_memalign 但 *aligned_alloc 也不一定可用。 We assume * that clang always has posix_memalign although it is not strictly * correct.我们假设 * clang 总是有 posix_memalign 虽然它不是严格 * 正确的。

Maybe simply try to compile flatcc with clang and with the "-std=c89" flag to avoid any problem.也许只是尝试使用 clang 和“-std=c89”标志编译 flatcc 以避免任何问题。 Do:做:

cmake -G "MinGW Makefiles" -DCMAKE_C_COMPILER=clang .

Then in the flatcc\src\compiler\CMakeFiles\flatcc.dir\flags.make file generated, you can change -std=c11 to -std=c89.然后在生成的flatcc\src\compiler\CMakeFiles\flatcc.dir\flags.make文件中,可以将-std=c11改为-std=c89。 Then compile the project again with:然后再次编译项目:

make

By default when I compile flatcc with mingw-32 on windows, I have the -std=c11 flag set (gcc version 7.3)默认情况下,当我在 windows 上使用 mingw-32 编译 flatcc 时,我设置了 -std=c11 标志(gcc 版本 7.3)

Well, to fix this issue, I had to compile flatcc Using clang in 32bit.好吧,为了解决这个问题,我必须在 32 位中使用 clang 编译 flatcc。 To do this, I moved into flatcc directory and did:为此,我进入了 flatcc 目录并做了:

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 -DFLATCC_USE_GENERIC_ALIGNED_ALLOC -B .

Then edited flatcc\src\compiler\CMakeFiles\flatcc.dir\flags.make and flatcc\src\runtime\CMakeFiles\flatcc.dir\flags.make to add -m32 to C_FLAGS:然后编辑flatcc\src\compiler\CMakeFiles\flatcc.dir\flags.makeflatcc\src\runtime\CMakeFiles\flatcc.dir\flags.make将 -m32 添加到 C_FLAGS:

C_FLAGS = -m32 -DFLATCC_REFLECTION=0 -Wstrict-prototypes -Wsign-conversion -Wconversion -std=c11 -pedantic -Wall -Wextra -DFLATCC_PORTABLE -DFLATCC_USE_GENERIC_ALIGNED_ALLOC

Then changed flatcc\src\compiler\CMakeFiles\flatcc.dir\link.txt and flatcc\src\runtime\CMakeFiles\flatcc.dir\link.txt to look like this:然后将flatcc\src\compiler\CMakeFiles\flatcc.dir\link.txtflatcc\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

Note: I just changed name of.a generated to.lib注意:我只是将生成的.a的名称更改为.lib

Then finally I run mingw32-make.exe (or make.exe )然后最后我运行mingw32-make.exe (或make.exe

Thanks to Victor Gallet感谢维克多·加勒

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM