意外的文件错误结束

我希望你能帮助我,因为我不知道发生了什么。 在尝试将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 

对不起,这么多的代码。

转到SolutionExplorer(应该已经可见,如果不使用菜单:View-> SolutionExplorer)。

在解决scheme树中find.cxx文件,右键单击它,然后从popup菜单中select“属性”。 你会得到你的文件的属性窗口。

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

你忘了在你的源代码中包含stdafx.h (因为我看不到你的代码)。 如果你没有,那么确保#include "stdafx.h"是你的.cpp文件的第一行,否则即使你在源文件中包含"stdafx.h" ,也会看到同样的错误不在文件的开头 )。

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

如果你已经显示的是整个.cxx文件,那么你忘了在该文件中包含stdafx.h

我也有这个错误,但是.h文件。 修复是进入文件Properties (通过解决scheme资源pipe理器的文件popup菜单),并正确设置文件types。 它被设置为C/C++ Compiler而不是正确的C/C++ header

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

  • 在项目的解决scheme资源pipe理器窗格中,右键单击项目名称,然后单击Properties
  • 在左侧窗格中,单击C/C++文件夹。
  • 单击Precompiled Headers节点。
  • 在右窗格中单击Create/Use Precompiled Header ,然后单击Not Using Precompiled Headers

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

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

将您的C ++项目的平台更改为“x64”(或您select的平台)而不是“Win32”。 这可以在Visual Studio中find生成 – >configurationpipe理器。 在列表中find您的项目并更改平台列。 不要忘记为所有的解决schemeconfiguration。