How to add -lm flag in cmake in spec file?

Hello,

I have been trying to build tinyspline with cmake on Tumbleweed.
https://build.opensuse.org/package/show/home:andythe_great/tinyspline

I encounter error:

    5s] /usr/lib64/gcc/x86_64-suse-linux/9/../../../../x86_64-suse-linux/bin/ld: /tmp/libtinyspline.so.FCXWuN.ltrans0.ltrans.o: in function `ts_distance':
    5s] /home/abuild/rpmbuild/BUILD/tinyspline-snapshot/src/tinyspline.c:2069: undefined reference to `sqrt'
    5s] /usr/lib64/gcc/x86_64-suse-linux/9/../../../../x86_64-suse-linux/bin/ld: /tmp/libtinyspline.so.FCXWuN.ltrans0.ltrans.o: in function `ts_bspline_interpolate_catmull_rom':
    5s] /home/abuild/rpmbuild/BUILD/tinyspline-snapshot/src/tinyspline.c:987: undefined reference to `pow'
    5s] /usr/lib64/gcc/x86_64-suse-linux/9/../../../../x86_64-suse-linux/bin/ld: /home/abuild/rpmbuild/BUILD/tinyspline-snapshot/src/tinyspline.c:988: undefined reference to `pow'
    5s] /usr/lib64/gcc/x86_64-suse-linux/9/../../../../x86_64-suse-linux/bin/ld: /home/abuild/rpmbuild/BUILD/tinyspline-snapshot/src/tinyspline.c:989: undefined reference to `pow'
    5s] collect2: error: ld returned 1 exit status

It is complaining about undefined reference to sqrt' and pow’
I found that I have to add link flag -lm, which told gcc to use math library.
https://stackoverflow.com/questions/8671366/undefined-reference-to-pow-and-floor

But I think I was adding it the wrong way, which still cause the same error.


%prep
%autosetup -n %{name}-%{version}

%build
%cmake -DCMAKE_INSTALL_PREFIX=%{_prefix} \
       -DCMAKE_LD_FLAGS:STRING="%optflags -lm" \
       -DCMAKE_CXX_FLAGS:STRING="%optflags -lm" \

%cmake_build

%install
%cmake_install

Thanks,
Andy

Hi
You need to inspect the CmakeLists.txt file (may be deeper in the directories) to see where it’s using calling it… it maybe called something different…

Hello,

I found a file /src/tinyspline.c which have

#include <math.h>   /* fabs, sqrt */ 

Which it contain the use of “pow” like this.


        t1 = t0 + (tsReal) pow(ts_distance(p0, p1, dimension), alpha);
        t2 = t1 + (tsReal) pow(ts_distance(p1, p2, dimension), alpha);
        t3 = t2 + (tsReal) pow(ts_distance(p2, p3, dimension), alpha);

Anyway, I think it is better to ask the dev how to compile this on cmake.