有一个win32控制台工程,有以下几个文件:
main.cpp    /* 只包含main函数 */
include.h   /* 一些变量的定义 */
function.h  /* 一些函数的定义 */main.cpp有如下代码:
#include <windows.h>
#include <stdio.h>
#include "include.h"
void function1();  //有分号
//后续省略function.h有如下代码:
#include <windows.h>
#include <stdio.h>
#include "include.h"void  function1( )
{
  //函数内容
}
怎么样在main.cpp中引用function.h的function1()?
我看别人写的代码都是几个文件有函数主体内容,然后在cpp文件中如main.cpp样声明这些函数,即可调用。
但是我写的时候在LINK时出现如下错误:
我的实际情况:
--------------------Configuration: 某工程 - Win32 Debug--------------------
Linking...
某工程.obj : error LNK2001: unresolved external symbol "int __cdecl _WriteINI(char const * const,char const * const,char const * const,char const * const)" (?_WriteINI@@YAHQBD000@Z)
某工程.obj : error LNK2001: unresolved external symbol "int __cdecl _ReadINI(char const * const,char const * const,char const * const,char *,unsigned long)" (?_ReadINI@@YAHQBD00PADK@Z)
Debug/某工程.exe : fatal error LNK1120: 2 unresolved externals
执行 link.exe 时出错.某工程.exe - 1 error(s), 0 warning(s)第一次写大一点的工程,以前都是main.cpp include function.h,function.h include stdio.h及windows.h等,但是感觉这样不太正规,。
语言表达能力不好,望见谅。
高手新手都欢迎帮忙解决一下问题,看来我是世界上最菜的。VC控制台工程工程结构

解决方案 »

  1.   

    简单地说,#include预编译命令的作用是,将指定文件的所有内容复制到该命令处
    所以下面的代码
    #include <windows.h>
    #include <stdio.h>
    #include "include.h"
    void function1();  //有分号
    在编译时,首先就被展开成
    #include <windows.h>
    #include <stdio.h>
    #include <windows.h>
    #include <stdio.h>
    #include "include.h"
    void  function1( )
    {
      //函数内容
    }
    void function1();  //有分号
    很明显,声明放在了定义的后面,没有任何用处然后,虽然代码放在哪里是你的自由,但帮你省略了太多操作的VC,默认“只有CPP文件是需要编译的代码文件”。这符合最常用的编程习惯:头文件放声明,源文件放定义
      

  2.   

    对,main.cpp确实没有包含function.h,我想知道作为一个工程VC为什么不管
    现在应该怎么办呢?像提问最后所说的“main.cpp include function.h,function.h include stdio.h及windows.h等”吗?
      

  3.   

    function.h,会重复包含吗?
    加一个类似
    #ifndef _MEMDC_H_
    #define _MEMDC_H_
    .......
    #endif