4

today i encountered a problem with linking my compiled cuda stuff.

i have a uptodate debian testing w/ 2.6.32-3-amd64.

i worked all day on my code. compiling from time to time. had no problem. but then after a minor code change i got following error:

gcc -o pa  CUDA.o  histogram256.o  histogram64.o  main.o  -lrt -lm -lcudart  -I. -I/data/cuda/include -I/data/cuda/C/common/inc -L/data/cuda/lib64
/usr/bin/ld: main.o: undefined reference to symbol 'std::basic_ifstream<char, std::char_traits<char> >::close()@@GLIBCXX_3.4'
/usr/bin/ld: note: 'std::basic_ifstream<char, std::char_traits<char> >::close()@@GLIBCXX_3.4' is defined in DSO /usr/lib64/libstdc++.so.6 so try adding it to the linker command line
/usr/lib64/libstdc++.so.6: could not read symbols: Invalid operation
collect2: ld returned 1 exit status

i changed the code back but the error stayed.

the lib is where it should be. (/usr/lib64 is linked to /usr/lib)

ldd /usr/lib/libstdc++.so.6
    linux-vdso.so.1 =>  (0x00007fff31fff000)
    libm.so.6 => /lib/libm.so.6 (0x00007f15f625a000)
    libc.so.6 => /lib/libc.so.6 (0x00007f15f5ef9000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f15f680d000)
    libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00007f15f5ce2000)

hopefully someone has a good advice.

snippl
  • 235
  • 1
  • 2
  • 13
  • Are you sure you didn't change anything with your environment? It's unlikely that your code caused this if you still see the issue after reverting to older code. – JaredC Feb 22 '11 at 20:37
  • unfortunately i'm pretty sure. the only thing i changed was the code. – snippl Feb 22 '11 at 22:12
  • At this point it is a good time to ask, does anyone else (with admin access) use the machine in question ? Anyway a fix would be to use -L/usr/lib64 -lstdc++ . Looks like an update from debian might have done this. – Pavan Yalamanchili Feb 23 '11 at 00:20
  • i'm the only one. and thank you, that fixed my problem. – snippl Feb 23 '11 at 08:32

2 Answers2

15

adding

-L/usr/lib64 -lstdc++

to my makefile/commandlineparameters fixed it.

snippl
  • 235
  • 1
  • 2
  • 13
9

You could also use g++ instead of gcc. This will automatically link against stdc++ without you having to specify it explicitly.

What is the difference between g++ and gcc?

Community
  • 1
  • 1
bckohan
  • 203
  • 1
  • 6