You mentioned libstdc++
in a comment, which makes me suspect that the problem is that you're linking with g++
rather than with gcc
.
The gcc
command invokes the compiler and/or the linker. If you use it to compile a source file, it normally determines the language (and therefore which compiler front-end to use).
The g++
command is similar, but it's specialized for C++; if it invokes the linker, it passes arguments as needed to link libraries like libstdc++
that are required for C++.
For example, these two commands, which just compile without linking:
gcc -c foo.cpp
g++ -c foo.cpp
are (as far as I know) equivalent, but these commands:
gcc foo.cpp -o foo
g++ foo.cpp -o foo
are not; the former will probably fail (depending on what features foo.cpp
uses).
And it turns out that the g++
command, unlike the gcc
command, implicitly links the math library, at least in the version on my system. So if your C++ code uses both C++-specific features (like, say, <iostream>
) and math functions, then linking it with the gcc
command is likely to produce complaints about functions defined in both libstdc++
and libm
-- which is just what you're seeing.
If you link with the g++
command, that should solve the problem. You'll probably have to modify your Makefile
or equivalent, or whatever generates it.
(If this is the solution, you should probably add "c++" to the list of tags on your question.)
As for why you didn't run into this problem before, I can't tell. Some C (and/or C++) compilers will link the math library implicitly; the need to specify -lm
for other compilers is arguably a bug.