-1

I am a newbie to C & C++ and I am in desperate need of help. I want to re-use the functionality already coded by a vendor. For this, Vendor gave me the .H files & .lib files. Vendor code was developed in Visual C langage and I am trying to access those .lib files in Visual C++ 6. Compilation is successful. I get errors while linking. Steps taken:

  1. I have linked all the .lib files under the project settings.

I still get the following error message:

pricing_w32.obj : error LNK2001: unresolved external symbol _open_item_info_files Debug/pricing_w32.exe : fatal error LNK1120: 1 unresolved externals Error executing link.exe.

Below is the code which i had written:

    #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 contains the following function prototype:

    int open_item_info_files( int *err );

Below is snippet of the command: dumpbin /symbols cma_telx.lib

076 00000000 SECT1D notype () External | ?open_item_info_files@@YAHPAH@Z (int __cdecl open_item_info_files(int *)) tag index 00000083 size 00000121 lines 00007129 next function 0000008E 078 00000000 SECT1E notype Static | .data Section length 9, #relocs 0, #linenums 0, checksum 145249B4, selection 2 (pick any) 07A 00000000 SECT1E notype External | ??_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 | ??_C@_06CPCO@TSITEM?$AA@ (string') 07E 00000000 SECT20 notype Static | .data Section length 7, #relocs 0, #linenums 0, checksum F397CDFF, selection 2 (pick any) 080 00000000 SECT20 notype External | ??_C@_06OHCH@KPXREF?$AA@ (`string') 081 00000000 UNDEF notype () External | _imp_FileManager 082 00000000 UNDEF notype () External | __chkstk

Deanie
  • 2,316
  • 2
  • 19
  • 35
Ravi
  • 163
  • 1
  • 2
  • 12
  • the error shows you didn't like to those libs when compiling – gongzhitaao Nov 27 '13 at 22:32
  • @gongzhitaao, *link*, you mean? – wjmolina Nov 27 '13 at 22:34
  • 1
    Are you sure there is a function called `open_item_info_files` in the library? Did you get the spelling / capitalization / punctuation exactly right? You could look at the question http://stackoverflow.com/questions/305287/how-to-see-the-contents-of-windows-library-lib which helps you "peek inside" the library. Either you are not linking right, or the thing you ask for is not there. This will help you narrow down the search. – Floris Nov 27 '13 at 22:43
  • Is the library 32 bit code or 64 bit? – Kaz Nov 28 '13 at 00:44

2 Answers2

0

Are the *.lib files for static-linking or for dll-linking? Here on my VC++ 2010 Express I have to check under project properties/C++/codegeneration/runtime-bib whether linking against DLL or not DLL (= static).

Go to definition/declaration of your unresolved external symbol and post its defintion!

mb84
  • 683
  • 1
  • 4
  • 13
0

First thing to check is make sure you have added the .lib file project properties >> Linker. I am on my mac right now but you add the .lib on 2nd page under linker settings and you have to add the path on first page under linker.

After this, check the c++ >> 'code generation' and see if it linked via MT or MD settings. This has to match to what the actual .lib file was build against so you may want to toggle it and that may do the trick.

zar
  • 11,361
  • 14
  • 96
  • 178
  • I have tried for two days in adding the .lib files to linker and the /mt & /MD options. nothing worked until now. I have provided more information in my original question. PLease have a look at it. – Ravi Nov 28 '13 at 04:29