Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ld: cannot find -lstdc++

Tags:

c++

g++

linker

I was trying to break down compilation to these four steps, but the last one seems problematic for me.

cpp hello.cpp > hello.i
g++ -S hello.i
as -o hello.o hello.s
ld -o hello hello.o -lstdc++

I searched the problem on here and here, but that didn't help.

Running in verbose mode gave me

attempt to open hello.o succeeded
hello.o
attempt to open /usr/i686-linux-gnu/lib32/libstdc++.so failed
attempt to open /usr/i686-linux-gnu/lib32/libstdc++.a failed
attempt to open //usr/local/lib32/libstdc++.so failed
attempt to open //usr/local/lib32/libstdc++.a failed
attempt to open //lib32/libstdc++.so failed
attempt to open //lib32/libstdc++.a failed
attempt to open //usr/lib32/libstdc++.so failed
attempt to open //usr/lib32/libstdc++.a failed
attempt to open //usr/local/lib/i386-linux-gnu/libstdc++.so failed
attempt to open //usr/local/lib/i386-linux-gnu/libstdc++.a failed
attempt to open //usr/local/lib/libstdc++.so failed
attempt to open //usr/local/lib/libstdc++.a failed
attempt to open //lib/i386-linux-gnu/libstdc++.so failed
attempt to open //lib/i386-linux-gnu/libstdc++.a failed
attempt to open //lib/libstdc++.so failed
attempt to open //lib/libstdc++.a failed
attempt to open //usr/lib/i386-linux-gnu/libstdc++.so failed
attempt to open //usr/lib/i386-linux-gnu/libstdc++.a failed
attempt to open //usr/lib/libstdc++.so failed
attempt to open //usr/lib/libstdc++.a failed
ld: cannot find -lstdc++

Any suggestions? Thanks in advance.

like image 465
Piyush Deshmukh Avatar asked Oct 21 '25 02:10

Piyush Deshmukh


2 Answers

Instead of invoking the linker directly, try calling it indirectly through gcc or g++:

cpp hello.cpp > hello.i
g++ -S hello.i
as -o hello.o hello.s
g++ -o hello hello.o
like image 178
greatwolf Avatar answered Oct 22 '25 15:10

greatwolf


In my case I had updated gcc to gcc-10 but left g++ at an older version (g++-9).

The fix was to install g++-10.

like image 39
Lincoln Avatar answered Oct 22 '25 16:10

Lincoln