0

Kindly Help Me With The following piece of code

//jmp_common.h

typedef void (*jmp_Handler_t)(void);

#define JMP_CMD_HANDLER(com)    extern void Jmp_Handler_##com(void)

#define JMP_DEF_COM(com) extern void Jmp_Handler_##com(void);

#include "jmp_cmd_list.h"

#undef JMP_DEF_COM

typedef struct JmpStruct
{
    char * name;
    jmp_Handler_t handler;
}JmpStruct_t;

/*********************************/
/*********************************/

//jmp_cmd_list.h

JMP_DEF_COM(HELLO)
JMP_DEF_COM(WORLD)

/*********************************/
/*********************************/

//jmp_cmd_handlers.c

#include "jmp_common.h"

JMP_CMD_HANDLER(HELLO)
{
    int a = 100;
}

JMP_CMD_HANDLER(WORLD)
{
    int a = 100;
}

/*********************************/
/*********************************/

//main.c
#include "jmp_common.h"

#define JMP_DEF_COM(com) { #com , Jmp_Handler_##com },

const JmpStruct_t JumpTable[/*JMP_CMD_MAX*/2] = {
#include "jmp_cmd_list.h"
};

int main(void)
{
    JumpTable[0].handler();
    return 0;
}

The Problem Is it that the code fails to compile with a link error unresolved symbol void __cdecl Jmp_Handler_HELLO(void) However when the First Line of code in the main function is removed the code compiles succesfully. Kindly Help

theadnangondal
  • 1,546
  • 3
  • 14
  • 28
  • The name woudl be `Jmp_Handler_HELLO`, since you specified `HELLO` in all caps. – Colonel Thirty Two Jul 28 '14 at 16:12
  • tankyou you but unfortunately it was only a typo error. This is not related to the actual situation. Thanks anyways – theadnangondal Jul 28 '14 at 16:36
  • 2
    Did you forget to link in `jmp_cmd_handlers.o`? It should be defined there (since that is where you defined it), so check to make sure it is (`nm jmp_cmd_handlers.o`) and is getting linked properly. – Chris Dodd Jul 28 '14 at 16:57
  • Thank you Chris for your answer. the jmp_cmd_handler.c is part of visual studio solution and I am compiling through visual studio gui option (instead of visual studio command prompt) , so I don't think that this could be a problem. Moreover the JumpTable struct is compiled succesfully as mentioned before that if the line in main function is removed the code compiled. However I am not completely sure and you may be right, Kindly elaborate your opinios a bit more so that I can give it a try Thank you anyways @ChrisDodd – theadnangondal Jul 28 '14 at 17:42
  • Moreover all the handler functions are getting extern in the header file jmp_common.h `#define JMP_DEF_COM(com) extern void Jmp_Handler_##com(void); #include "jmp_cmd_list.h" #undef JMP_DEF_COM` – theadnangondal Jul 28 '14 at 20:00

1 Answers1

0

Found the problem. Every file was a c file (.c extension) except main file it was c++ file (.cc extension). after changing the extension of main file it compiled smoothly. However I think that it should have compiled before, may be anyone can answer why it was not compiling.

thankyou @chris and @colonel for your replies.

theadnangondal
  • 1,546
  • 3
  • 14
  • 28