[Stk] Beginners question using RtMidi

Stephen Sinclair sinclair@music.mcgill.ca
Wed, 04 Apr 2007 12:30:41 -0400


Hello,

You have a function prototype here:

void call_back(double timeStamp, std::vector <unsigned char> *message, 
void *userData) ;

But where is the actual function defined?
It is missing, hence the "undefined reference" error.
You have to give a function body:

void call_back(double timeStamp, std::vector <unsigned char> *message, 
void *userData)
{
    // do something
}


Steve


Robert Gründler wrote:
> Hi,
>
> i'm having troubles implementing the RtMidiCallback function to 
> process incoming midi messages.
> I'ts a beginners mistake i assume, i'm getting a linker error:
>
> midi_in.cpp:37: undefined reference to `call_back(double, 
> std::vector<unsigned char, std::allocator<unsigned char> >*, void*)'
>
> Here's the code:
>
> #include <iostream>
> #include "RtMidi.h"
> #include <signal.h>
> #include <vector>
>
> using namespace std;
>
> void call_back(double timeStamp, std::vector <unsigned char> *message, 
> void *userData) ;
>
> int main( int argc, char *argv[] ) {
>
> RtMidiIn *midi_in = 0;
>
> try {
>    midi_in = new RtMidiIn();
> }
>
> catch ( RtError& error ) {
>    error.printMessage();
>    exit(0);
> }
> midi_in->openPort(1);
> midi_in->setCallback(&call_back);
>  
> delete midi_in;
>
> return 0;
> }
>
> Here's how my makefile looks like:
>
> ### STK examples Makefile - for various flavors of unix
>
> PROGRAMS = tester midi_in
> RM = /bin/rm
> SRC_PATH = ../../src
> OBJECT_PATH = /usr/lib/
> vpath %.o $(OBJECT_PATH)
>
> INCLUDE =
> ifeq ($(strip $(INCLUDE)), )
>    INCLUDE = /usr/include/
> endif
> vpath %.h $(INCLUDE)
>
> CC       = g++
> DEFS     = -D__LITTLE_ENDIAN__
> DEFS    +=
> CFLAGS   = -O3
> CFLAGS  += -Wall -g -D__GXX__ -I$(INCLUDE)
> LIBRARY =  -ljack   -lasound -lpthread -lm  -lasound
> LIBRARY +=
>
> REALTIME = yes
> ifeq ($(REALTIME),yes)
>    DEFS    += -D__LINUX_JACK__ -D__LINUX_ALSASEQ__
> endif
>
> RAWWAVES =
> ifeq ($(strip $(RAWWAVES)), )
>    RAWWAVES = ../../rawwaves/
> endif
> DEFS    += -DRAWWAVE_PATH=\"$(RAWWAVES)\"
>
> %.o : $(SRC_PATH)/%.cpp
>    $(CC) $(CFLAGS) $(DEFS) -c $(<) -o $(OBJECT_PATH)/$@
>
> all : $(PROGRAMS)
>
> $(OBJECTS) : Stk.h
>
> clean :
>    -rm $(PROGRAMS)
>
> strip :
>    strip $(PROGRAMS)
>
> tester:   test.cpp
>    $(CC) $(CFLAGS) test.cpp  -o tester -lstk -ljack -lasound
>   midi_in:   midi_in.cpp
>    $(CC) $(CFLAGS) midi_in.cpp -o midi_in -lstk -ljack -lasound  
> -lpthread -lm -lasound
>
>
> Any help would be greatly appreciated!
>
> -robert
>
>
>
>
>
>
> _______________________________________________
> Stk mailing list
> Stk@ccrma.stanford.edu
> http://ccrma-mail.stanford.edu/mailman/listinfo/stk