0

The compiler error I'm getting from g++ is

./Debug_gcc_lin64_5610_ST/tom.o: In function `process_P2T_CUST(IPC*)':
/mxhome/charrison/git/libs/tom.cpp:512: undefined reference to `memorize_block(boost::unordered_map< ... >&, Block const&)'

(Ellipsis mine).

The source code snippet containing the undefined reference is:

void
process_P2T_CUST(IPC *client_ipc) {

    // Get list of record types in block                                                                                                 
    Block& block = client_ipc->get_block();
    block.get_record_types(input_record_set);

    // Reset associative memory                                                                                                          
    memory.clear();

    // Add all field=value pairs from P2T_CUST into memory                                                                           
    memorize_block(memory, block);

And the header definition of memorize_block is:

void memorize_block(MemoryBank&, Block&);

Now: here's how I interpret the error message - the linker (or actually the compiler) has somehow inferred that the required signature of memorize_block() must have parm1 = unordered_map&, and parm2 = Block const&.

But why does it think that the Block should be const?

If I haven't provided enough source code, please comment and I'll amend this question accordingly.

UPDATE 1 Here is the code for memorize_block, which is in the same compilation unit as the reference. There is no other definition anywhere.

void
memorize_block(MemoryBank& memory, Block &block) {
    D_RecordType_Vector record_types;
    block.get_record_types(record_types);    
    BOOST_FOREACH(const D_RecordType_Set::value_type& rec_type, record_types) {
            block.traverse_record(rec_type, add_to_memory(memory));
    }
}
Chap
  • 3,649
  • 2
  • 46
  • 84
  • Have you provided definition for the `memorize_block` ? If yes, are you compiling and linking the source file that has the definition ? – Mahesh Sep 05 '13 at 00:38
  • Feels like ODR violation. Look for another declaration of `memorize_block`, one where the second parameter is in fact a const reference. – Igor Tandetnik Sep 05 '13 at 00:38
  • @Igor: ODR? There is no other declaration of `memorize_block`. verified by grepping recursively through source tree. @Mahesh: source for memorize_block() lives in same source file as the undefined ref. I have also included it in the question, UPDATE 1. – Chap Sep 05 '13 at 04:03
  • Well, the compiler clearly believes otherwise. Try running that source file through a preprocessor (for gcc, `-E` option), inspect the output to find out what declaration of `memorize_block` the compiler sees. – Igor Tandetnik Sep 05 '13 at 04:21
  • What's the proto for client_ipc->get_block()? – kfsone Sep 05 '13 at 06:12
  • I boiled it down to an sscce and it works fine: http://ideone.com/n3ttgN – kfsone Sep 05 '13 at 06:15
  • I have to apologize: I should have tried this first - I ran `make clean`, and then the make ran fine. Still not sure why it got confused about a reference whose resolution lived in the same .cpp file, but all is now well. – Chap Sep 05 '13 at 15:50

1 Answers1

0

The problem is not whit the compiler, if you reach that line of error, the compilation is done. Don't worry about the constness of the signature. The problem here is that your linker is not able to find the "definition" of the function, he only knows the "declaration", it's means, you only have the ignature of the function, but not the implementation. If the implementation is in a cpp that is not provided to the compiler, then you need to add it

hidrargyro
  • 257
  • 1
  • 7
  • As mentioned above, the definition is in the same source file as the reference. The only explanation I could think of for why it couldn't find it was the mismatch on const. – Chap Sep 05 '13 at 04:04