0

I have 2 projects, RoofExp and testapp, the RoofExp is a DLL project which is written by C, the testapp is a win32 console project to test the RoofExp.dll. My code is listed below:

roofexp.h

#ifndef ROOF_EXP_PARSER_H
#define ROOF_EXP_PARSER_H

#ifdef ROOF_EXP_API
#else
#define ROOF_EXP_API __declspec(dllimport)
#endif

#ifndef MAX_PATH
#define MAX_PATH    260         
#endif

#define MAX_PARAS   16          
enum ParaType
{
    PARA_NUMBER = 1,
    PARA_STRING
};

typedef struct _VARIABLE_INFO
{
    char    VarName[MAX_PATH];
    struct _VARIABLE_INFO   *next;
}VARIABLE_INFO, *PVARIABLE_INFO;

typedef struct _FUNCTION_INFO
{
    char    FuncName[MAX_PATH];
    int     FuncParas;
    enum ParaType FuncParaType;
    int     FuncParaList[MAX_PARAS];
    struct _FUNCTION_INFO   *next;
}FUNCTION_INFO, *PFUNCTION_INFO;


ROOF_EXP_API void __cdecl ParserUninitialize();

ROOF_EXP_API int __cdecl ParserInitialize(PVARIABLE_INFO pVarList, PFUNCTION_INFO pFuncList);

ROOF_EXP_API int __cdecl ParserExecute(char *filename, int *errcnt, char *errmsg, int bufflen, void *fptr);

#define ERROR_PARSER_BASE           1024
#define ERROR_PARSER_SUCCESS        0x00
#define ERROR_PARSER_BAD_PARAMETERS ERROR_PARSER_BASE-1
#define ERROR_PARSER_FILE_NOT_FOUND ERROR_PARSER_BASE-2
#define ERROR_PARSER_FAILED_INIT    ERROR_PARSER_BASE-3
#endif

testapp.cpp

int _tmain(int argc, _TCHAR* argv[])
{
    char szFileName[MAX_PATH];
    int nRetCode = 0;

    ParserExecute(szFileName, &nRetCode, szFilePath, 1024, NULL);


    return 0;
}

The RoofExp project can build successfully, When I build the testapp project, I got the following error message:

error LNK2019: unresolved external symbol "__declspec(dllimport) int __cdecl ParserExecute(char *,int *,char *,int,void *)

I googled for a long time and cannot resolve my problem. Can someone tell me what's wrong with my code and how to resolve it?

CharlesB
  • 86,532
  • 28
  • 194
  • 218
Kecise
  • 61
  • 6
  • Did you pass the lib file to the linker? – David Heffernan Jul 23 '13 at 05:09
  • Yes, I passed the lib file to the linker using `/LIBPATH:"lib-path" roofexp.lib` linker options. – Kecise Jul 23 '13 at 09:24
  • possible duplicate of [error LNK2019: unresolved external symbol](http://stackoverflow.com/questions/13318965/error-lnk2019-unresolved-external-symbol), [Cannot solve unresolved external error LNK2019 error](http://stackoverflow.com/q/7850896/62576), and several others, all of which arrive at basically the same conclusions. – Ken White Jul 23 '13 at 13:34

3 Answers3

1

There is no obvious way you made sure that these functions are actually getting exported from the DLL. Your ROOF_EXP_API macro certainly looks wrong, it is normally written like this:

#ifdef ROOF_EXP_API
#  define ROOF_EXP_API __declspec(dllexport)
#else
#  define ROOF_EXP_API __declspec(dllimport)
#endif
Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
0

There are several things I would check:

  1. The library defining ParserExecute is included in the linked libraries list in your project.
  2. The function is actually defined and exported from that DLL.
Cătălin Pitiș
  • 14,123
  • 2
  • 39
  • 62
0

Assuming you correctly included the .lib file for the DLL, most of the time this is down to differences in the compiler settings. e.g. If your DLL was compiled with UNICODE switched on make sure your APP is also compiled with UNICODE on (otherwise TCHAR will be defined differently).

  1. Check that the .lib is actually being loaded by setting the 'Show Progress' Linker settings to VERBOSE.
  2. Run DUMPBIN on the LIB file to check that the exported functions are the same as the ones the linker is trying to import.
snowdude
  • 3,854
  • 1
  • 18
  • 27