From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

undefined symbol aligned_free / aligned_malloc

Solved!
Go to solution

I have added an external lib to my project and when compiling it, I get some linking error (I'm compiling with C99 extension and I need to keep it) :mDdbg5N

To be honest, even if the error seems basic, I'm totally lost. The header where aligned_free/ aligned_malloc are referenced say this : 

 

/*
 * 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.
 */

 

If I dont miss, LabWindows/CVI is based on clang. So why I got this error ? Help !

0 Kudos
Message 1 of 2
(1,760 Views)
Solution
Accepted by topic author JohnKafe

Well, to fix this issue, I had to compile flatcc Using clang (a true Clang installation, not the NI one) in 32bit. To do this, I moved into flatcc directory and did :

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 :

Then changed flatcc\src\compiler\CMakeFiles\flatcc.dir\link.txt and flatcc\src\runtime\CMakeFiles\flatcc.dir\link.txt to look like this :

Note: I just changed name of .a generated to .lib

Then finally I run mingw32-make.exe (or make.exe)

 

The two .lib generated work with labWindows/Cvi (c99)

0 Kudos
Message 2 of 2
(1,712 Views)