简体   繁体   English

未解决的外部符号错误,即使已定义功能并被IDE看到也是如此

[英]Unresolved external symbol error, even if function is defined and seen by IDE

using Visual C++ 2008, I am having an "Unresolved external symbol" even if with the IDE I can correctly see both declaration and definition of the function: 使用Visual C ++ 2008,即使使用IDE我可以正确看到函数的声明和定义,我也有一个“无法解析的外部符号”:

The error: 错误:

hook_file.obj : error LNK2001: unresolved external symbol "int __cdecl is_directory_objattr(struct _OBJECT_ATTRIBUTES const *)" (?is_directory_objattr@@YAHPBU_OBJECT_ATTRIBUTES@@@Z)

Relevant code in hook_file.cpp: hook_file.cpp中的相关代码:

    #include "misc.h"

    void handle_new_file(HANDLE file_handle, const OBJECT_ATTRIBUTES *obj)
        {
            if(is_directory_objattr(obj) == 0 ) { 
            // etc.

Declaration in misc.h file: 在misc.h文件中的声明:

BOOL is_directory_objattr(const OBJECT_ATTRIBUTES *obj);

Definition in misc.cpp file: 在misc.cpp文件中的定义:

#include "misc.h"

BOOL is_directory_objattr(const OBJECT_ATTRIBUTES *obj)
    { //function body here }

I really don't get what the linker has to complain here. 我真的没有得到链接器在这里抱怨的内容。

  • The header with function declaration is included by the file which calls the function. 带有函数声明的标头包含在调用函数的文件中。
  • The cpp file with the function definition included header file with declaration. 具有功能定义的cpp文件包括带有声明的头文件。
  • Declaration and definitions are identical. 声明和定义相同。
  • All files are listed among project files. 所有文件都列在项目文件中。

Any idea whats wrong? 知道怎么了吗?

Thanks! 谢谢!

Have you only include one time your header file? 您只包含一次头文件吗?

in misc.h 在misc.h中

#ifndef MISC
#define MISC

...

#endif MISC ?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM