Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > C/C++: Программирование под Unix/Linux > Библиотека Libusb и GCC


Автор: avroman 5.5.2009, 00:44
Здравствуйте,
Я пишу open source проект под названием USB pic Microcontroller programmer for LINUX OS.
Я разработал USB прибор, который связывается с компьютером по средствам HID протокола.

Я хочу воспользоваться библиотекой LIBUSB но что то не получается скомпилировать следующий код в GCC.


#include <libusb-1.0/libusb.h>
#include <stdio.h>
#include <string.h>

int main()
{
     libusb_device **list;
     libusb_init(NULL);       

      return 0;
  
}

я компилирую следующей командой: gcc -g -Wall  main2.c -o my -L/usr/local/lib
и получаю следующею ошибку: undefined reference to `libusb_init'

Может, кто знает, в чем проблема?
Зарание спасибо за ответ.

Автор: InvalidProperty 5.5.2009, 08:13
линковщик не находит ссылку на libusb_init, т.е. тебе нужно передать ссылку на библиотеку. Попробуй вот это
Цитата

-llibrary
     -l library
         Search the library named library when linking.  (The
         second alternative with the library as a separate
         argument is only for POSIX compliance and is not
         recommended.)

         It makes a difference where in the command you write
         this option; the linker searches and processes libraries
         and object files in the order they are specified.  Thus,
         foo.o -lz bar.o searches library z after file foo.o but
         before bar.o.  If bar.o refers to functions in z, those
         functions may not be loaded.

         The linker searches a standard list of directories for
         the library, which is actually a file named
         liblibrary.a.  The linker then uses this file as if it
         had been specified precisely by name.


ты уверен, что твоя библиотека именно в /usr/local/lib?

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)