【问题标题】:Reading from std::cin produces Linker error从 std::cin 读取会产生链接器错误
【发布时间】:2013-06-28 22:48:25
【问题描述】:

我有一个相当不寻常的问题。我正在尝试这样做:

char *content = new char[10000];
std::cin.read(content, 10000);

我收到以下链接器错误(很奇怪,因为代码在几周前编译良好,并且尚未修改):

Error LNK2001: unresolved external symbol "__declspec(dllimport) public: class std::basic_istream<char,struct std::char_traits<char> > & __thiscall std::basic_istream<char,struct std::char_traits<char> >::read(char *,__int64)" (__imp_?read@?$basic_istream@DU?$char_traits@D@std@@@std@@QAEAAV12@PAD_J@Z) main.obj

我验证了我在项目属性中链接了所有必需的依赖项,验证了我设置了 /MT 等等。该项目在几周前编译得很好——从那时到现在我唯一做的就是更新 VS2012。这是我的包含。

#include <stdlib.h>

#ifdef _WIN32
    #include <process.h>
#else
    #include <unistd.h>
    extern char ** environ;
#endif

#include "fcgio.h"
#include "fcgi_config.h"

#include <boost/filesystem.hpp>
#include <boost/filesystem/fstream.hpp>
#include <boost/algorithm/string.hpp>

【问题讨论】:

  • 检查项目设置,看看它是否配置为忽略默认库。
  • 据我所知,您的包含不包括 iostream。要么,要么你使用gcc 而不是g++ 来编译你的代码。
  • 您的文件是否以“.c”结尾。似乎已调用 C 编译器来编译您的程序。
  • 您的read 函数调用有错误。应该是std::cin.read(content, 10000);content 参数前面没有星号。
  • 感谢各位的帮助。它没有忽略默认库,包括 iostream 不起作用,并且文件以 .h 结尾。我很茫然。

标签: c++ linker std fastcgi


【解决方案1】:

似乎在更新 Visual Studio 2012 后,该项目(不知何故)变得无法运行。将完全相同的代码复制到新项目已经解决了这个问题。

【讨论】:

    猜你喜欢
    • 2010-11-27
    • 2013-07-31
    • 2021-02-28
    • 1970-01-01
    • 1970-01-01
    • 2011-11-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多