Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when trying to compile with cmake #152

Closed
kevinsmia1939 opened this issue Mar 21, 2020 · 13 comments
Closed

Error when trying to compile with cmake #152

kevinsmia1939 opened this issue Mar 21, 2020 · 13 comments

Comments

@kevinsmia1939
Copy link

kevinsmia1939 commented Mar 21, 2020

When I switch to compiling with make to cmake I encounter an 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 it to use math library.
https://stackoverflow.com/questions/8671366/undefined-reference-to-pow-and-floor

This is what the flags currently look like.

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

%build
%cmake -Wno-dev \
       -DCMAKE_INSTALL_PREFIX=%{_prefix} \
       -DTINYSPLINE_ENABLE_PYTHON:BOOL=ON \
       -DCMAKE_LD_FLAGS:STRING="%optflags -lm" \
       -DCMAKE_CXX_FLAGS:STRING="%optflags -lm" 

%cmake_build

%install
%cmake_install

But I don't think

-DCMAKE_LD_FLAGS:STRING="%optflags -lm" \
-DCMAKE_CXX_FLAGS:STRING="%optflags -lm" 

is the correct way to do it. How do I properly do this?

But I still could not get it to compile.
Full spec file here: https://build.opensuse.org/package/view_file/home:andythe_great/tinyspline/tinyspline.spec?expand=1
Full error log here: https://build.opensuse.org/package/live_build_log/home:andythe_great/tinyspline/openSUSE_Tumbleweed/x86_64
PS: About the unversioned library, lets see if cmake will report such problem when I can get tinyspline to compile.
Thanks.

@msteinbeck
Copy link
Owner

Thank you for reporting this issue. I'll fix it later this day.

@msteinbeck
Copy link
Owner

This should now be fixed (see 9c49cea).

Background information: The CMake script located in the src directory exported the CMake variable TINYSPLINE_LIBRARIES which contains all libraries one needs to link against when linking tinyspline and tinysplinecpp. This makes sense for the static libraries, but is unnecessary for the shared libraries because we can easily link m while creating the shared libraries.

With 9c49cea, the shared libraries are now linked against all dependent libs. Only for the static libraries one needs to now which other libraries must be linked into the executable. I introduced the CMake variables TINYSPLINE_STATIC_LIBRARIES (for the static library of the C interface) and TINYSPLINE_CXX_STATIC_LIBRARIES (for the static library of the C++ interface). When linking TinySpline statically, you have to use them accordingly. When linking TinySpline dynamically, no additional linkage is necessary.

Note: This replaces the CMake variable TINYSPLINE_LIBRARIES.

Please let me know if this fixes your issue.

@kevinsmia1939
Copy link
Author

I'm a bit confuse how to apply the flag. Like this?

%cmake -Wno-dev \
       -DCMAKE_INSTALL_PREFIX=%{_prefix} \
       -DTINYSPLINE_CXX_STATIC_LIBRARIES:BOOL=ON 

%cmake_build

@msteinbeck
Copy link
Owner

You don't need to use TINYSPLINE_CXX_STATIC_LIBRARIES when compiling and linking the shared libraries. If, on the other hand, you link the libraries statically, pass the the values to your compiler. Here you'll find an example where TINYSPLINE_CXX_STATIC_LIBRARIES is used in CMake to properly link libtinysplinecpp statically.

@kevinsmia1939
Copy link
Author

So I actually don't have to add anything?
I download the latest snapshot but still have the same error.
This is what I have in my sepc file.

%build
%cmake -Wno-dev \
       -DCMAKE_INSTALL_PREFIX=%{_prefix} 

%cmake_build

%install
%cmake_install

@msteinbeck
Copy link
Owner

So I actually don't have to add anything?

Yes, it shouldn't be necessary to add further options because in 9c49cea I added the -lm flag to all shared library targets (9c49cea#diff-95e351a3805a1dafa85bf20b81d086e6R488).

I download the latest snapshot but still have the same error.

This is unexpected. You still get the error that sqrt and pow are undefined?

@kevinsmia1939
Copy link
Author

kevinsmia1939 commented Mar 25, 2020

I got this error:

[    7s] /usr/lib64/gcc/x86_64-suse-linux/9/../../../../x86_64-suse-linux/bin/ld: /tmp/libtinyspline.so.IxHbVg.ltrans0.ltrans.o: in function `ts_distance':
[    7s] /home/abuild/rpmbuild/BUILD/tinyspline-0.2.0+git.1584996308.33462b8/src/tinyspline.c:2069: undefined reference to `sqrt'
[    7s] /usr/lib64/gcc/x86_64-suse-linux/9/../../../../x86_64-suse-linux/bin/ld: /tmp/libtinyspline.so.IxHbVg.ltrans0.ltrans.o: in function `ts_bspline_interpolate_catmull_rom':
[    7s] /home/abuild/rpmbuild/BUILD/tinyspline-0.2.0+git.1584996308.33462b8/src/tinyspline.c:987: undefined reference to `pow'
[    7s] /usr/lib64/gcc/x86_64-suse-linux/9/../../../../x86_64-suse-linux/bin/ld: /home/abuild/rpmbuild/BUILD/tinyspline-0.2.0+git.1584996308.33462b8/src/tinyspline.c:988: undefined reference to `pow'
[    7s] /usr/lib64/gcc/x86_64-suse-linux/9/../../../../x86_64-suse-linux/bin/ld: /home/abuild/rpmbuild/BUILD/tinyspline-0.2.0+git.1584996308.33462b8/src/tinyspline.c:989: undefined reference to `pow'

This is the spec file for cmake for builiding tinypline: https://build.opensuse.org/package/view_file/home:andythe_great/tinyspline/tinyspline.spec?expand=1

This is the full error log: https://build.opensuse.org/package/live_build_log/home:andythe_great/tinyspline/openSUSE_Tumbleweed/x86_64

I recently trigger the building service, so it is trying to build a package at the moment.

@msteinbeck
Copy link
Owner

Did you try to compile the libraries without additional tools, i.e. running the following commands:

wget https://github.com/msteinbeck/tinyspline/archive/snapshot.tar.gz
tar xf snapshot.tar.gz
cd tinyspline-snapshot
mkdir build
cd build
cmake ..
cmake --build .

You should get the following output:

> ls lib
libtinyspline.a  libtinyspline.so*  libtinysplinecpp.a  libtinysplinecpp.so*

ldd shows that the .so files are linked against libm:

> ldd lib/libtinyspline.so
        linux-vdso.so.1 (0x00007fff3afc9000)
        libm.so.6 => /lib64/libm.so.6 (0x00007fe18f751000)
        libc.so.6 => /lib64/libc.so.6 (0x00007fe18f388000)
        /lib64/ld-linux-x86-64.so.2 (0x00007fe18fc70000)
> ldd lib/libtinysplinecpp.so
        linux-vdso.so.1 (0x00007ffec13a5000)
        libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x00007f37ea79b000)
        libm.so.6 => /lib64/libm.so.6 (0x00007f37ea492000)
        libgcc_s.so.1 => /usr/lib64/libgcc_s.so.1 (0x00007f37ea27b000)
        libc.so.6 => /lib64/libc.so.6 (0x00007f37e9eb2000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f37ead36000)

@kevinsmia1939
Copy link
Author

I tried building on my machine and it indeed work, I will try asking the OBS dev.

@kevinsmia1939
Copy link
Author

I posted the question here.
https://forums.opensuse.org/showthread.php/539613-Can-build-package-with-native-cmake-but-failed-when-using-OBS

By the way, how can I uninstalled the compiled tinyspline with normal cmake that I follow in your instruction?

@kevinsmia1939
Copy link
Author

kevinsmia1939 commented Mar 26, 2020

I suspect OBS might change some cmake flags that cause it to failed.
Bad news that I have zero clue how these flags work.

Some of the flags I have found when OBS was compiling are.


cd /home/abuild/rpmbuild/BUILD/tinyspline-0.2.0+git.1584996308.33462b8/build/src && /usr/bin/cmake -E cmake_link_script CMakeFiles/tinyspline_shared.dir/link.txt --verbose=1
[    6s] /usr/bin/cc -fPIC -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection -Werror=return-type -flto=auto -DNDEBUG -std=c89 -O2 -g -DNDEBUG -flto=auto -Wl,--as-needed -Wl,--no-undefined -Wl,-z,now -lm -shared -Wl,-soname,libtinyspline.so -o ../lib/libtinyspline.so CMakeFiles/tinyspline_shared.dir/tinyspline.c.o CMakeFiles/tinyspline_shared.dir/parson.c.o 

@msteinbeck
Copy link
Owner

By the way, how can I uninstalled the compiled tinyspline with normal cmake that I follow in your instruction?

CMake has no built-in uninstall target. However, you'll find the installed files in install_manifest.txt.

@msteinbeck
Copy link
Owner

I'll close this issue because the actual error has been fixed. Don't hesitate to reopen it if necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants