当我使用g ++编译一个简单的c ++文件时,它会返回这样的错误
$ g++ test.cpp
/tmp/cc5HEhoY.o: In function `main':
test.cpp:(.text+0x3a): undefined reference to `std::istream::seekg(long long, std::_Ios_Seekdir)'
collect2: error: ld returned 1 exit status
代码如下:
#include <fstream>
#include <iostream>
int
main(void) {
std::ifstream in("/tmp/a", std::ios::in);
in.seekg(0, std::ifstream::beg);
in.close();
return 0;
}
g ++版本是
$ g++ --version
g++ (GCC) 4.9.2 20150212 (Red Hat 4.9.2-6)
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE
我的linux版本是
$ lsb_release -a
LSB Version: :core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch
Distributor ID: Fedora
Description: Fedora release 21 (Twenty One)
Release: 21
Codename: TwentyOne
我的libstdc ++版本是
$ /sbin/ldconfig -p | grep stdc++
libstdc++.so.6 (libc6,x86-64) => /lib64/libstdc++.so.6
libstdc++.so.6 (libc6) => /lib/libstdc++.so.6
libstdc++.so (libc6,x86-64) => /lib64/libstdc++.so
libstdc++.so (libc6) => /lib/libstdc++.so
细节是:
$ strings /usr/lib/libstdc++.so.6 | grep LIBCXX
GLIBCXX_3.4
GLIBCXX_3.4.1
GLIBCXX_3.4.2
GLIBCXX_3.4.3
GLIBCXX_3.4.4
GLIBCXX_3.4.5
GLIBCXX_3.4.6
GLIBCXX_3.4.7
GLIBCXX_3.4.8
GLIBCXX_3.4.9
GLIBCXX_3.4.10
GLIBCXX_3.4.11
GLIBCXX_3.4.12
GLIBCXX_3.4.13
GLIBCXX_3.4.14
GLIBCXX_3.4.15
GLIBCXX_3.4.16
GLIBCXX_3.4.17
GLIBCXX_3.4.18
GLIBCXX_3.4.19
GLIBCXX_3.4.20
GLIBCXX_DEBUG_MESSAGE_LENGTH
有没有人遇到这样的错误?