Mex compilation error when linking with gmp on Linux

2 views (last 30 days)
I am using a mex command which works fine in Windows but when I try to mex on Linux, I get an error regarding gmp library.
I have linked to the same gmp library using GCC outside of Matlab successfully. Below is the command
gcc -x c++ -I. -L. -lstdc++ -lm -lIp_cordic_v6_0_bitacc_cmodel -Wl,-rpath,. -o run_bitacc_cmodel run_bitacc_cmodel.c
However within Matlab (tried 2019 and 2020), I get the below error:
gmp.h:37:61: error: ‘GMP_NAIL_BITS’ was not declared in this scope
#define GMP_NUMB_MASK ((~ __GMP_CAST (mp_limb_t, 0)) >> GMP_NAIL_BITS)
Below is the mex command I am using to compile the code in Matlab on Linux:
mex -lstdc++ -lm -lgmp -lIp_cordic_v6_0_bitacc_cmodel cordic_sin_cos.cpp -v
Below is the mex command I am using to compile the code in Matlab on Windows which works fine:
mex cordic_sin_cos.cpp libIp_cordic_v6_0_bitacc_cmodel.lib

Answers (1)

Prateekshya
Prateekshya on 25 Aug 2023
As per my understanding, you are encountering an error related to the GMP library when attempting to use a mex command on Linux. The error message specifically mentions that "GMP_NAIL_BITS" was not declared in the scope of the "gmp.h" header file.
I assume that you have verified the installation and linking of GMP library. You can consider adding the "-D__GMP_CAST" flag to the mex command. This flag is used to define the "__GMP_CAST" macro, which might be required by the code you are compiling. The modified mex command would look like thie following:
>> mex --lstdc++ -lm -lgmp -D__GMP_CAST -lIp_cordic_v6_0_bitacc_cmodel cordic_sin_cos.cpp -v

Categories

Find more on Write C Functions Callable from MATLAB (MEX Files) in Help Center and File Exchange

Tags

Products


Release

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!