0

I have no idea what the problem is. I am trying to build my project for release but the linker complains about not finding external symbols.

The thing that's odd is that I copy & pasted all include paths and dependencies from the Debug into the Release build configuration and double checked it.

get_PC_definition() is e.g. declared in cpudefs.h:

/* Return register definition of instruction pointer */
extern RegisterDefinition * get_PC_definition(Context * ctx);

There are a few implementations of this function - which one I chose is controled by macros so yes, I defined all necessary macros too:

RegisterDefinition * get_PC_definition(Context * ctx) {
    static RegisterDefinition * reg_def = NULL;

    if (!context_has_state(ctx)) 
        return NULL;

    // and so on ..

    return reg_def;
}

cpudefs.obj gets build so far but the Linker just mocks around .. maybe I am already blind to the error but like I said, I copied the configurations from the Debug into the Release build configuration.

Any ideas what I could try?

Error output:

Error   43  error LNK1120: 9 unresolved externals   C:\svn\AgentSib\Release\agentsib.exe    agentsib
Error   31  error LNK2001: unresolved external symbol _get_PC_definition    C:\svn\AgentSib\AgentSib\registers.obj  agentsib
Error   32  error LNK2001: unresolved external symbol _get_PC_definition    C:\svn\AgentSib\AgentSib\runctrl.obj    agentsib
Error   34  error LNK2001: unresolved external symbol _get_PC_definition    C:\svn\AgentSib\AgentSib\symbols_cdb.obj    agentsib
Error   35  error LNK2001: unresolved external symbol _get_PC_definition    C:\svn\AgentSib\AgentSib\cpudefs.obj    agentsib
Error   36  error LNK2001: unresolved external symbol _get_PC_definition    C:\svn\AgentSib\AgentSib\expressions.obj    agentsib
Error   37  error LNK2001: unresolved external symbol _get_PC_definition    C:\svn\AgentSib\AgentSib\funccall.obj   agentsib
Error   38  error LNK2001: unresolved external symbol _get_PC_definition    C:\svn\AgentSib\AgentSib\profiler_sst.obj   agentsib
Error   41  error LNK2019: unresolved external symbol _BREAK_INST referenced in function _get_break_instruction C:\svn\AgentSib\AgentSib\cpudefs.obj    agentsib
Error   27  error LNK2019: unresolved external symbol _cpu_bp_get_capabilities referenced in function _context_get_supported_bp_access_types    C:\svn\AgentSib\AgentSib\context-sib.obj    agentsib
Error   30  error LNK2019: unresolved external symbol _cpu_bp_on_resume referenced in function _sib_resume  C:\svn\AgentSib\AgentSib\context-sib.obj    agentsib
Error   28  error LNK2019: unresolved external symbol _cpu_bp_plant referenced in function _context_plant_breakpoint    C:\svn\AgentSib\AgentSib\context-sib.obj    agentsib
Error   29  error LNK2019: unresolved external symbol _cpu_bp_remove referenced in function _context_unplant_breakpoint C:\svn\AgentSib\AgentSib\context-sib.obj    agentsib
Error   42  error LNK2019: unresolved external symbol _crawl_stack_frame referenced in function _trace_stack    C:\svn\AgentSib\AgentSib\stacktrace.obj agentsib
Error   33  error LNK2019: unresolved external symbol _get_PC_definition referenced in function _command_get_children_cache_client  C:\svn\AgentSib\AgentSib\stacktrace.obj agentsib
Error   39  error LNK2019: unresolved external symbol _ini_cpudefs_mdep referenced in function _ini_cpudefs C:\svn\AgentSib\AgentSib\cpudefs.obj    agentsib
Error   40  error LNK2019: unresolved external symbol _regs_index referenced in function _get_reg_by_dwarf_id   C:\svn\AgentSib\AgentSib\cpudefs.obj    agentsib

Edit:

Calling function get_PC_definition()

static int set_debug_regs(Context * ctx, int check_ip, int * step_over_hw_bp) {
    int i;
    int ret;
    uint32_t dr7      = 0;
    ContextAddress ip = 0;
    ContextExtensioni8051 * dext = EXT(ctx);
    ContextExtensioni8051 * bps  = EXT(context_get_group(ctx, CONTEXT_GROUP_BREAKPOINT));
    RegisterDefinition *reg_def  = NULL;

    ret = 0;

    if (check_ip) {

        *step_over_hw_bp = 0;

        reg_def = get_PC_definition(ctx);
        ret     = context_read_reg(ctx, reg_def, 0, reg_def->size, &ip);

        if ( ret < 0 )
            return -1;
    }

    return 0;
}
Stefan Falk
  • 23,898
  • 50
  • 191
  • 378
  • Show the rest of your code (or at least the relevant part of it, where you call this function). The code given in your question cannot yield this linkage error, because there is "no reason for the linker to try and link this function to anything". – barak manos Aug 29 '14 at 12:46
  • @barakmanos I can do that but since the whole thing compiles without hesitation I don't think that this will give us much information. – Stefan Falk Aug 29 '14 at 12:47
  • BTW, that big gray block (right below "I defined all necessary macros too") doesn't look like a macro to me. – barak manos Aug 29 '14 at 12:48
  • Compilation is not your problem. Linkage is. – barak manos Aug 29 '14 at 12:49
  • @barakmanos this is a very huge project. I'm talking about a lot of files that get macroed in or out. The macro part won't be the problem. Visual Studio gives feedback which code it compiles so these settings are not broken. Besides that all necessary macros have also been copy pasted from Debug to Release build config. – Stefan Falk Aug 29 '14 at 12:50
  • @barakmanos Yes sorry ^^ @compilation/linkage – Stefan Falk Aug 29 '14 at 12:52

1 Answers1

0

This question "Visual Studio 2010's strange "warning LNK4042"" had the solution to my problem.

After all it was a linker problem caused by the compiler..

Under Configuratoin Properties >> C/C++ >> Output Files >> Object File Name I used for both configurations $(IntDir) whereas it worked for Debug but not for Release. Does anybody know why?

Changing it to

$(IntDir)\%(RelativeDir)

was the solution that saved my day.

Community
  • 1
  • 1
Stefan Falk
  • 23,898
  • 50
  • 191
  • 378