Results 1 to 3 of 3

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

  1. #1
    Join Date
    Oct 2018
    Location
    Atlantis
    Posts
    117

    Default 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/s...eat/tinyspline

    I encounter error:

    Code:
    [    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/...-pow-and-floor

    But I think I was adding it the wrong way, which still cause the same error.
    Code:
    %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

  2. #2
    Join Date
    Jun 2008
    Location
    Podunk
    Posts
    28,528
    Blog Entries
    15

    Default Re: How to add -lm flag in cmake in spec file?

    Quote Originally Posted by andythe_great View Post
    Hello,

    I have been trying to build tinyspline with cmake on Tumbleweed.
    https://build.opensuse.org/package/s...eat/tinyspline

    I encounter error:

    Code:
    [    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/...-pow-and-floor

    But I think I was adding it the wrong way, which still cause the same error.
    Code:
    %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...
    Cheers Malcolm °¿° SUSE Knowledge Partner (Linux Counter #276890)
    SUSE SLE, openSUSE Leap/Tumbleweed (x86_64) | GNOME DE
    If you find this post helpful and are logged into the web interface,
    please show your appreciation and click on the star below... Thanks!

  3. #3
    Join Date
    Oct 2018
    Location
    Atlantis
    Posts
    117

    Default Re: How to add -lm flag in cmake in spec file?

    Quote Originally Posted by malcolmlewis View Post
    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
    Code:
    #include <math.h>   /* fabs, sqrt */
    Which it contain the use of "pow" like this.
    Code:
            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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •