2013-11-27 80 views
-1

我是一个新手C & C++,我迫切需要帮助。我想重新使用已由供应商编码的功能。为此,供应商给我提供了.H文件& .lib文件。供应商代码是使用Visual C语言开发的,我尝试在Visual C++ 6中访问这些.lib文件。编译成功。链接时出错。采取的步骤:链接问题C/C++

  1. 我已链接项目设置下的所有.lib文件。

我仍然得到以下错误消息:

pricing_w32.obj:错误LNK2001:解析外部符号_open_item_info_files 调试/ pricing_w32.exe:致命错误LNK1120:1周无法解析的外部 错误执行链接。可执行程序。

下面是代码,我曾写入:

#include<stdio.h> 
    #include<string.h> 
    #include<fstream> 
    #include<conio.h> 
    #include<stdlib.h> 
    #include<iostream> 
    #include <windows.h> 
    extern "C" 
    { 
    #include<cma_telx.h> 
    } 
    using namespace std; 
    int process_file(char **in_file); 
    extern "C" 
    { 
    void lkup_item_info(void *item); 
    int open_item_info_files(int *err); 
    int close_item_info_files(int *err); 
    int open_item_promo_files(int *err); 
    int close_item_promo_files(int *err); 
    void lkup_rtn_csp_db(void *itemCspWDB); 
    void lkup_rtn_promos_csp_db(void *itemPrmCspWDB); 
    int do_empdisc_lookup(struct EMPDISC_RECORD *edisc, int *err); 
    int do_empauth_lookup(struct EMPLOYEE_AUTH_REC *eauth, int *err); 
    void return_all_promos(struct ALL_PRMINFO_BASE &all_promos); 
    } 
    int APIENTRY WinMain(HINSTANCE hInstance, 
       HINSTANCE hPrevInstance, 
       LPSTR  lpCmdLine, 
       int  nCmdShow) 
    { 
     char UPC[7]; 
     void *SKU; 
    cout<<"Normal end"<<endl; 
int return_code, *err; 
return_code = open_item_info_files(err); 
    cout<<return_code<<"open item return code"<<endl; 
    cout<<return_code<<"Close item return code"<<endl; 
    return 0; 
    } 

cma_telx.h包含以下函数原型:

int open_item_info_files(int *err); 

下面是命令的片段:DUMPBIN /符号cma_telx。 lib

076 00000000 SECT1D notype()External | ?open_item_info_files @@ YAHPAH @ Z(int __cdecl open_item_info_files(int *)) 标记索引00000083大小00000121行00007129下一个函数0000008E 078 00000000 SECT1E notype静态| .data 段长度9,#relocs 0,#linenums 0,校验和145249B4,选择2(挑选任何) 07A 00000000 SECT1E notype外部| ?_ C @ _08OOCA @ PMSDPTCL?$ AA @(string') 07B 00000000 SECT1F notype Static | .data Section length 7, #relocs 0, #linenums 0, checksum 7F8A6B53, selection 2 (pick any) 07D 00000000 SECT1F notype External | [email protected][email protected][email protected] ( string') 07E 00000000 SECT20 notype静态| .data 段长度7,#relocs 0,#linenums 0,校验和F397CDFF,选择2(挑选任何) 080 00000000 SECT20 notype外部| _ _ @ @ 06OHCH @ KPXREF $ AA @(`string') 081 00000000 UNDEF notype()External | _ imp _FileManager 082 00000000 UNDEF notype()External | __chkstk

+0

错误显示你编译时不喜欢那些库文件 – gongzhitaao

+0

@gongzhitaao,* link *,你的意思是? – Raptor

+1

你确定库中有一个叫做'open_item_info_files'的函数吗?你的拼写/大小写/标点完全正确吗?你可以看看这个问题http://stackoverflow.com/questions/305287/how-to-see-the-contents-of-windows-library-lib它可以帮助你“窥视”图书馆。要么你没有连接正确,要么你要求的东西不在那里。这将帮助您缩小搜索范围。 – Floris

回答

0

静态链接或dll链接的* .lib文件?在我的VC++ 2010 Express中,我必须检查项目属性/ C++/codegeneration/runtime-bib是否链接到DLL或不DLL(静态)。

进入定义/声明您的未解析的外部符号并发布其定义!

+0

我正在使用visual C++ 6 – Ravi

0

首先要检查的是确保已添加.lib文件项目属性>>链接器。我现在在我的Mac上,但是在链接器设置下的第二页上添加.lib,并且必须在链接器下的第一页上添加路径。

之后,检查C++ >>'代码生成',看看它是通过MT或MD设置链接。这必须与实际的.lib文件构建的内容相匹配,因此您可能需要切换它,这可能会有所裨益。

+0

我已经尝试了两天将.lib文件添加到链接器和/ mt&/ MD选项。直到现在没有任何工作我在原始问题中提供了更多信息。请看看它。 – Ravi