0

I've defined two extern unsigned char's in a header file for transfering two char's between two classes. In the first .cpp I use them like normal varibles to store the inputs i get from the function without any further declaration, like this:

test.h

extern unsigned char tempName;
extern unsigned char tempValue;

test.cpp

void NanoKontrol2::midi_in_proc(UINT wMsg, DWORD_PTR dwParam1, DWORD_PTR dwParam2) {
    unsigned char ch_msg, data1, data2, data3;

    switch (wMsg) {
    case MIM_DATA:
        ch_msg = (unsigned char)(0xFF & dwParam1);
        data1 = (unsigned char)(0xFF & (dwParam1 >> 8));
        data2 = (unsigned char)(0xFF & (dwParam1 >> 16));
        data3 = (unsigned char)(0xFF & (dwParam1 >> 24));
        /*on_message(ch_msg, data1, data2, data3);*/
        tempName = data1;
        tempValue = data2;
        /*on_change_value(tempName, tempValue);*/
        break;
    default:
        break;
    }
}

Now I need the stored values in the tempVariables from the midi_in_proc in the second class needhere.cpp.

I tried to use them in the class needhere.cpp like this:

if (NK2_FADER_0 <= tempName && tempName <= NK2_FADER_7) {
                fader1 = tempValue;
            }
            //Knobs
            else if (NK2_ROTARY_KNOB_0 <= tempName && tempName <= NK2_ROTARY_KNOB_7) {
                knob1 = tempValue;
            }

Visual Studio doesn't show any Error. But when I try to compile I get this 6 Errors:

Severity    Code    Description Project File    Line    Suppression State
Error   LNK1120 3 unresolved externals  MayaNK2Node C:\Users    1   
Error   LNK2001 unresolved external symbol "public: static class NanoKontrol2 MayaNK2Node::nanoKONTROL2" (?nanoKONTROL2@MayaNK2Node@@2VNanoKontrol2@@A  1   
Error   LNK2001 unresolved external symbol "unsigned char tempName" (?tempName@@3EA)    
Error   LNK2001 unresolved external symbol "unsigned char tempName" (?tempName@@3EA)    
Error   LNK2001 unresolved external symbol "unsigned char tempValue" (?tempValue@@3EA)  
Error   LNK2001 unresolved external symbol "unsigned char tempValue" (?tempValue@@3EA)  
melpomene
  • 84,125
  • 8
  • 85
  • 148
SurfinBird
  • 21
  • 1
  • 7

1 Answers1

1

you have to define tempName somewhere. extern unsigned char tempName; just says 'tempName exists somewhere in my program', you have to make it exist too.

Add

unsigned char tempName;

to test.cpp

pm100
  • 48,078
  • 23
  • 82
  • 145
  • worked thanks! But I am still getting the same Error for the whole class: `Error LNK2001 unresolved external symbol "public: static class NanoKontrol2 MayaNK2Node::nanoKONTROL2" (?nanoKONTROL2@MayaNK2Node@@2VNanoKontrol2@@A) MayaNK2Node` – SurfinBird May 04 '18 at 15:25
  • ask a new question. Include the command(s) used to compile and link – pm100 May 07 '18 at 17:46
  • already solved it! thanks! – SurfinBird May 09 '18 at 08:59