Undefined reference error with sincosf@@GLIBC_2.2.5 and sqrtf@@GLIBC_2.2.5

Problem

I was compiling some C++ and CUDA code using CMake on Ubuntu 14.04. The linking stage threw up this error:

/usr/bin/ld: foobar.cpp.o: undefined reference to symbol 'sincosf@@GLIBC_2.2.5'
//lib/x86_64-linux-gnu/libm.so.6: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status

Another error of the same form:

/usr/bin/ld: foobar.cpp.o: undefined reference to symbol 'sqrtf@@GLIBC_2.2.5'
//lib/x86_64-linux-gnu/libm.so.6: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status

I had used these same source and CMake files without any compile error on a Ubuntu 12.04 system.

Solution

Ubuntu 14.04 uses newer versions of the GCC compilers and libraries. The hint here is that its complaining about a mathematical symbol: sincosf. Suggesting the linker to link with the math library fixed this error. You can do this by adding -lm to the linker invocation.

For my CMake, I did this by adding -lm to the linking options to the target as:

target_link_libraries(
    foobar
    -lsomelibrary
    -lm
    )

Tried with: GCC 4.8.2, CMake 2.8.12.2 and Ubuntu 14.04

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.