我用VC++6编译C程序,各模块都没出现问题,但在创建exe文件的连接时出现问题,本人C++不好,不知道问题出在什么地方,请教各位老师指点

解决方案 »

  1.   

    看不到图片!
    链接时出现的错误你可以COPY出来给我们看看撒!
      

  2.   

    如果在C++中调用C函数,需要在函数声明前面加extern "C",如果是包含C程序的头文件,可以用如下形式:
    extern "C" {
    #include "xxx.h"
    }
      

  3.   

    图片不知为什么看不到了,现在从新用文本方式提问:我用VC++6编译C程序,各模块都没出现问题,但在创建exe文件的连接时出现问题,本人C++不好,不知道问题出在什么地方,请教各位老师指点getopt.h头文件里申明的其中的变量和函数:
    …………….
    extern char *optarg;
    extern  int optind;
    extern  int getopt_long (int argc, char *const *argv, const char *shortopts,
             const struct option *longopts, int *longind);
    …………….
    gzip.c主函数对几个参数和函数的应用:
    ……………..
    #include "getopt.h"
    …………….
    file_count = argc - optind;
        while ((optc = getopt_long (argc, argv, "ab:cdfhH?lLmMnNqrS:tvVZ123456789",
    longopts, (int *)0)) != EOF) {
    switch (optc) {
            case 'a':
                ascii = 1; break;
    case 'b':
        maxbits = atoi(optarg);
        break;
    ……………..调试产生的连接错误:
    --------------------Configuration: gzip - Win32 Debug--------------------
    Linking...
    gzip.obj : error LNK2001: unresolved external symbol _optind
    gzip.obj : error LNK2001: unresolved external symbol _optarg
    gzip.obj : error LNK2001: unresolved external symbol _getopt_long
    Debug/gzip.exe : fatal error LNK1120: 3 unresolved externals
    执行 link.exe 时出错.gzip.exe - 1 error(s), 0 warning(s)但从来都没申明和应用_optind、_optarg、_getopt_long(注意前面加了下横线)
      

  4.   

    前面的下划线是编译后的加上去的,C语言中的名字编译后都会加上下划线。你看一下你的getopt.c中有没有定义这些变量和函数(前面不用加_)。
      

  5.   

    请确认  getopt.c 文件中 存在 getopt_long()函数