Subj : passing an 'int' to a thread To : comp.programming.threads From : Huub Date : Tue Jun 07 2005 10:13 pm Hi, With an example I took from the web I've tried to modify it so it passes an int (0, 4 or -4) to a thread. However, I get undefined references. This is my code so far: #ifdef HAVE_CONFIG_H #include #endif #include #include #include #include #include #include "ftapi/ftapi.h" using namespace std; using namespace ftapi; // default interface connection string device(""); ft_if_conn connection = FT_IC_LIB_USB; IfOutputs out; IfInputs inp; void *MotorDraad(void *threadid) { int *id_ptr, task_id; id_ptr = (int *)threadid; task_id = *id_ptr; cout << "Start MotorDraad" << endl; time_t start; time_t current; time(&start); try { auto_ptr fti (ftGetIfFromFactory(device, connection)); // Initialspeed = 4 FtMotorSpeed mSpeed1(task_id); // Initialspeed = 4 FtMotorSpeed mSpeed2(task_id); // enable all motor outputs out.data[FT_MASTER]= 0xFF; // M1: not moving out.setMotorSpeed(FT_MASTER, FT_M1, mSpeed1); // M2: forward with velocity 4 out.setMotorSpeed(FT_MASTER, FT_M2, mSpeed2); while (difftime(current,start) < 5.0) { time(¤t); fti->writeAndReadAllData(out, inp); } } // anything went wrong catch (exception &x) { cout << x.what() << endl; } } int main(int argc, char *argv[]) { cout << "Start fase 1" << endl; pthread_t threads[1]; int *task_ids[1]; int rc, t; t = 0; int snelheid = 0; cout << "1 Thread gedeclareerd" << endl; cout << "fttestextension v0.4" << endl; if (1 == argc) { /* leave device name as defined above, since no parameters given */ } else if (((2 == argc) || (3 == argc)) && (string("-l")==(argv[1]))) { if (3 == argc) device = argv[2]; connection = FT_IC_LIB_USB; } else if (((2 == argc) || (3 == argc)) && (string("-u")==(argv[1]))) { if (3 == argc) { device = argv[2]; } else { device = "/dev/usb/robointerface0"; } connection = FT_IC_USB; } else { return EXIT_FAILURE; } // now let's go! cout << "opening fischertechnik interface \"" << device << "\"" << endl; task_ids[t] = (int *) malloc(sizeof(int)); *task_ids[t] = t; while (snelheid != 8) { cin >> snelheid; cout << "Aanmaken thread" << endl; rc = pthread_create(&threads[t], NULL, MotorDraad, (void *)task_ids[t]); } pthread_exit(NULL); return EXIT_SUCCESS; } // EOF I compile it with: g++ -lftapi -lusb ffTestInterface_thread_args.cpp -o ffTestInterFace_thread_args -pthread Errors: /tmp/ccbRjnRM.o(.text+0x6d): In function `MotorDraad(void*)': : undefined reference to `ftapi::ftGetIfFromFactory(std::basic_string, std::allocator >, ftapi::ft_if_conn)' /tmp/ccbRjnRM.o(.text+0xc3): In function `MotorDraad(void*)': : undefined reference to `ftapi::FtMotorSpeed::FtMotorSpeed[in-charge](int)' /tmp/ccbRjnRM.o(.text+0xd5): In function `MotorDraad(void*)': : undefined reference to `ftapi::FtMotorSpeed::FtMotorSpeed[in-charge](int)' /tmp/ccbRjnRM.o(.text+0xf1): In function `MotorDraad(void*)': : undefined reference to `ftapi::IfOutputs::setMotorSpeed(ftapi::ft_module_type, ftapi::ft_motor, ftapi::FtMotorSpeed const&)' /tmp/ccbRjnRM.o(.text+0x106): In function `MotorDraad(void*)': : undefined reference to `ftapi::IfOutputs::setMotorSpeed(ftapi::ft_module_type, ftapi::ft_motor, ftapi::FtMotorSpeed const&)' /tmp/ccbRjnRM.o(.text+0x663): In function `__static_initialization_and_destruction_0(int, int)': : undefined reference to `ftapi::IfOutputs::IfOutputs[in-charge]()' /tmp/ccbRjnRM.o(.text+0x682): In function `__static_initialization_and_destruction_0(int, int)': : undefined reference to `ftapi::IfInputs::IfInputs[in-charge]()' collect2: ld returned 1 exit status If I'm using the wrong way for passing an int to a thread, please tell me or direct me to a link where I can find out how to do it. Thank you for helping me out. Huub .