4

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.

Community
  • 1
  • 1
Piyush Deshmukh
  • 519
  • 1
  • 7
  • 14
  • `g++ hello.cpp -Wl,--verbose` will get GCC to tell you where it's finding `libstdc++`. That should give you a start to figuring out how to get `ld` to find it. – Michael Burr Dec 02 '14 at 07:02

1 Answers1

4

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
greatwolf
  • 20,287
  • 13
  • 71
  • 105
  • I think that might not even be indirect… `ld` is now a different tool, deprecated for such purposes, if I recall correctly. – Potatoswatter Dec 02 '14 at 04:53
  • Actually my primary target was to study/learn/deal with linker ,and not to create an executable and `ld` command made me cry over that. – Piyush Deshmukh Dec 02 '14 at 05:04