Search code examples
c++ubuntug++gpib

Trying to use ibdev with g++ in Ubuntu and getting linker error


I am trying to develop code to control some instruments using the NI GPIB-USB-B adapter in Xubuntu 14.04.1 LTS and the 3.13.0-35-generic kernel.
At this point I am simply going for proof of concept with the function ibdev() in the ib.h library. When I enter the following command:

g++ gpibtest.cpp -o gt

I receive the following for my trouble: "undefined reference to `ibdev'".
I am assuming that the ib.h library is in the correct location as the compiler does not complain about not being able to find it.
I think it is likely that I am not entering the correct switch in my g++ command to include this library as I have had similar problems before with the time.h library, when I needed to include -lrt. I have been looking for hours and cannot find a solution to this despite its simplicity. I have looked in the ib.h file and it does contain these function prototypes (although using 'extern'), but I do not know where to look for their source code. This seems like a very basic issue with a very simple solution and I would appreciate any help that can be given.

Here is my simple program:

#include "visa.h"
#include <gpib/ib.h>
#include <iostream>

int main() {
    int dev;
    dev = ibdev(0, 5, 0, 13, 1, 0);

    std::cout << "Press any key\n";
    std::cin.ignore();

    return 0;
}

Solution

  • Did you try including -lgpib ? If its not in a standard path, use -L to specify the path to libgpib

    Also, make sure you are including the correct gpib/ib.h using -I