意外的文件结束错误

时间:2012-01-14 14:33:53

标签: c++ visual-studio-2008 visual-c++ compiler-errors precompiled-headers

我希望你能帮助我,因为我不知道发生了什么。尝试将Beecrypt库添加到我的项目时,我遇到以下错误:

  

致命错误C1010:查找预编译标头时意外结束文件。您是否忘记在源代码中添加“#include”stdafx.h“'?

实际上我没有忘记将#include“stdafx”添加到我的源代码中。编译器将错误指向此.cxx文件的末尾:

#define BEECRYPT_CXX_DLL_EXPORT

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include "beecrypt/c++/security/SecureRandom.h"
#include "beecrypt/c++/security/SecureRandomSpi.h"
#include "beecrypt/c++/security/Security.h"

using namespace beecrypt::security;

SecureRandom* SecureRandom::getInstance(const String& algorithm) throw       (NoSuchAlgorithmException)
 {
Security::spi* tmp = Security::getSpi(algorithm, "SecureRandom");

assert(dynamic_cast<SecureRandomSpi*>(tmp->cspi));

SecureRandom* result = new SecureRandom(reinterpret_cast<SecureRandomSpi*>(tmp->cspi), tmp->prov, tmp->name);

delete tmp;

return result;
}

 SecureRandom* SecureRandom::getInstance(const String& type, const String& provider) throw (NoSuchAlgorithmException, NoSuchProviderException)
  {
Security::spi* tmp = Security::getSpi(type, "SecureRandom", provider);

assert(dynamic_cast<SecureRandomSpi*>(tmp->cspi));

SecureRandom* result = new SecureRandom(reinterpret_cast<SecureRandomSpi*>(tmp->cspi), tmp->prov, tmp->name);

delete tmp;

return result;
    }

   SecureRandom* SecureRandom::getInstance(const String& type, const Provider& provider) throw (NoSuchAlgorithmException)
   {
Security::spi* tmp = Security::getSpi(type, "SecureRandom", provider);

assert(dynamic_cast<SecureRandomSpi*>(tmp->cspi));

SecureRandom* result = new SecureRandom(reinterpret_cast<SecureRandomSpi*>(tmp->cspi), tmp->prov, tmp->name);

delete tmp;

return result;
     }

  void SecureRandom::getSeed(byte* data, int size)
 {
entropyGatherNext(data, size);
 }

 SecureRandom::SecureRandom()
 {
Security::spi* tmp = Security::getFirstSpi("SecureRandom");

assert(dynamic_cast<SecureRandomSpi*>((SecureRandomSpi*) tmp->cspi));

_rspi = (SecureRandomSpi*) tmp->cspi;
_type = tmp->name;
_prov = tmp->prov;

delete tmp;
   }

  SecureRandom::SecureRandom(SecureRandomSpi* rspi, const Provider* provider, const String& type)
  {
_rspi = rspi;
_prov = provider;
_type = type;
  }

 SecureRandom::~SecureRandom()
 {
delete _rspi;
 }

void SecureRandom::generateSeed(byte* data, int size)
 {
_rspi->engineGenerateSeed(data, size);
 }

 void SecureRandom::setSeed(const byte* data, int size)
 {
_rspi->engineSetSeed(data, size);
 }

  void SecureRandom::nextBytes(byte* data, int size)
 {
_rspi->engineNextBytes(data, size);
 }

 const String& SecureRandom::getType() const throw ()
 {
return _type;
 }

  const Provider& SecureRandom::getProvider() const throw ()
 {
return *_prov;
  }

这是h文件:

#ifndef _CLASS_BEE_SECURITY_SECURERANDOM_H
#define _CLASS_BEE_SECURITY_SECURERANDOM_H

#include "beecrypt/beecrypt.h"

#ifdef __cplusplus

#include "beecrypt/c++/security/SecureRandomSpi.h"
using beecrypt::security::SecureRandomSpi;
#include "beecrypt/c++/security/Provider.h"
using beecrypt::security::Provider;
#include "beecrypt/c++/security/NoSuchAlgorithmException.h"
using beecrypt::security::NoSuchAlgorithmException;
#include "beecrypt/c++/security/NoSuchProviderException.h"
using beecrypt::security::NoSuchProviderException;

 namespace beecrypt {
namespace security {
    /*!\ingroup CXX_SECURITY_m
     */
    class BEECRYPTCXXAPI SecureRandom : public Object
    {
    public:
        static SecureRandom* getInstance(const String& type)    throw (NoSuchAlgorithmException);
        static SecureRandom* getInstance(const String& type,    const String& provider) throw (NoSuchAlgorithmException, NoSuchProviderException);
        static SecureRandom* getInstance(const String& type,   const Provider& provider) throw (NoSuchAlgorithmException);

        static void getSeed(byte*, int);

    private:
        SecureRandomSpi* _rspi;
        const Provider*  _prov;
        String           _type;

    protected:
        SecureRandom(SecureRandomSpi* spi, const Provider*   provider, const String& type);

    public:
        SecureRandom();
        virtual ~SecureRandom();

        void generateSeed(byte*, int);
        void nextBytes(byte*, int);
        void setSeed(const byte*, int);

        const String& getType() const throw ();
        const Provider& getProvider() const throw ();
    };
}
   }

   #endif

   #endif

很抱歉这么多代码。

7 个答案:

答案 0 :(得分:120)

转到SolutionExplorer(应该已经可见,如果没有使用菜单:View-&gt; SolutionExplorer)。

在解决方案树中找到您的.cxx文件,右键单击它并从弹出菜单中选择“属性”。您将获得包含文件属性的窗口。

使用左侧的树转到“C ++ /预编译标题”部分。在窗口的右侧,您将获得三个属性。将名为“Create / Use Precompiled Header”的属性设置为“Not Using precompiled Headers”的值。

答案 1 :(得分:11)

如果未在项目中使用预编译头,请将源文件的“创建/使用预编译头”属性设置为“不使用预编译头”。要设置此编译器选项,请按照下列步骤操作:

  • 在项目的Solution Explorer窗格中,右键单击项目名称,然后单击Properties
  • 在左侧窗格中,单击C/C++文件夹。
  • 单击Precompiled Headers节点。
  • 在右侧窗格中,点击Create/Use Precompiled Header,然后点击Not Using Precompiled Headers

答案 2 :(得分:10)

您确实忘记在源代码中包含stdafx.h(因为我无法看到您的代码)。如果您没有,请确保#include "stdafx.h".cpp文件中的第一个行,否则即使您已包含{{1},也会看到相同的错误在您的源文件中(但不在文件的开头中)。

答案 3 :(得分:5)

在包含任何其他标头文件之前,行#include "stdafx.h" 必须是每个源文件顶部的第一行。

如果您展示的是整个.cxx文件,那么您 忘记在该文件中加入stdafx.h

答案 4 :(得分:5)

我也遇到了这个错误,但对于.h文件。修复是进入文件Properties(通过解决方案资源管理器的文件弹出菜单)并正确设置文件类型。它设置为C/C++ Compiler而不是正确的C/C++ header

答案 5 :(得分:4)

当我在命名新的Win32控制台应用程序后忘记从向导中的其他选项中取消选中预编译头时,我遇到了该错误。

因为我不需要stdafx.h库,所以我通过转到项目菜单删除它,然后点击属性 [我们项目的名称]属性或只需按 Alt + F7 。在配置旁边的下拉列表中,选择所有配置。在下面是树节点,单击配置属性,然后单击 C / C ++ 。在右侧窗格中,选择创建/使用预编译标题,然后选择不使用预编译标题

答案 6 :(得分:1)

将C ++项目的平台更改为“x64”(或您要定位的任何平台)而不是“Win32”。这可以在Build - &gt;下的Visual Studio中找到。配置管理器。在列表中找到您的项目并更改Platform列。不要忘记为所有解决方案配置执行此操作。

相关问题