我如何链接到libusb,它已经从源代码而不是系统库构建

How do I link to libusb which has been built from source instead of the system library?

本文关键字:源代码 构建 系统库 何链接 链接 libusb      更新时间:2023-10-16

我知道我的问题是相当基本的,我有点不好意思问。因此,我在使用VRUI与我的Oculus Rift时遇到了一些麻烦,并且我有USB问题,因此为了进行理智检查,我下载了libusub-1.0.19-rc2的源代码,并试图链接到此编译版本而不是系统库版本。我用的是ubuntu 12.04 LTS。

感谢

编辑:因此,我的程序makefile的相关部分(整个东西相当长)看起来像这样:

########################################################################
# Makefile for Vrui toolkit and required basic libraries.
# Copyright (c) 1998-2014 Oliver Kreylos
#
# This file is part of the WhyTools Build Environment.
# 
# The WhyTools Build Environment is free software; you can redistribute
# it and/or modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
# 
# The WhyTools Build Environment is distributed in the hope that it will
# be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with the WhyTools Build Environment; if not, write to the Free
# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
# 02111-1307 USA
########################################################################
########################################################################
# The root directory where Vrui will be installed when running
# "make install". This must be a different directory than the one that
# contains this makefile, i.e., Vrui cannot be built in-tree. If the
# installation directory is changed from the default, the makefiles of
# Vrui applications typically need to be changed to use the same
# installation directory.
########################################################################
INSTALLDIR := $(HOME)/Vrui-3.1
########################################################################
# Please do not change the following lines
########################################################################
# Define the root of the toolkit source tree and the build system
# directory
VRUI_PACKAGEROOT := $(shell pwd)
VRUI_MAKEDIR := $(VRUI_PACKAGEROOT)/BuildRoot
# Include definitions for the system environment and provided software
# packages
include $(VRUI_MAKEDIR)/SystemDefinitions
include $(VRUI_MAKEDIR)/Packages.System
########################################################################
# Some settings that might need adjustment. In general, do not bother
# with these unless something goes wrong during the build process, or
# you have very specific requirements. Proceed with caution!
# The settings below are conservative; see the README file for what they
# mean, and how they depend on capabilities of the host system.
########################################################################
# The build system attempts to auto-detect the presence of system
# libraries that provide optional features. If autodetection fails and
# the build process generates error messages related to missing include
# files during compiling or missing libraries during linking, the use
# of these optional libraries can be disabled manually by uncommenting
# any of the following lines.
# SYSTEM_HAVE_LIBUSB1 = 0
# SYSTEM_HAVE_LIBPNG = 0
# SYSTEM_HAVE_LIBJPEG = 0
# SYSTEM_HAVE_LIBTIFF = 0
# SYSTEM_HAVE_ALSA = 0
# SYSTEM_HAVE_SPEEX = 0
# SYSTEM_HAVE_OPENAL = 0
# SYSTEM_HAVE_V4L2 = 0
# SYSTEM_HAVE_DC1394 = 0
# SYSTEM_HAVE_THEORA = 0
# SYSTEM_HAVE_BLUETOOTH = 0
# The build system attempts to auto-detect optional features in system
# libraries. If autodetection fails and the build process generates
# error messages related to undeclared functions, the use of these
# optional features can be disabled manually by uncommenting any of the
# following lines:
# Presense of libusb_get_parent in libusb.h:
# LIBUSB1_HAS_TOPOLOGY_CALLS 0
########################################################################
# Please do not change the following line
########################################################################
# Include definitions for Vrui-provided software packages
include $(VRUI_MAKEDIR)/Packages.Vrui
########################################################################
# More settings that might need adjustment. In general, do not bother
# with these unless something goes wrong during the build process, or
# you have very specific requirements. Proceed with caution!
# The settings below are conservative; see the README file for what they
# mean, and how they depend on capabilities of the host system.
########################################################################
# Set this to 1 if Vrui executables and shared libraries shall contain
# links to any shared libraries they link to. This will relieve a user
# from having to set up a dynamic library search path.
USE_RPATH = 1
# Set the following flag to 1 if the GL support library shall contain
# support for multithreaded rendering to several windows. This is
# required for shared-memory multi-pipe rendering systems such as SGI
# Onyx or Prism, but somewhat reduces performance when accessing per-
# window data elements or OpenGL extensions. If the compiler and run-
# time environment do not support a direct mechanism for thread-local
# storage (such as gcc's __thread extension), this uses the even slower
# POSIX thread-local storage mechanism. If setting this to 1 causes
# compilation errors, the SYSTEM_HAVE_TLS variable in
# BuildRoot/SystemDefinitions needs to be set to 0.
GLSUPPORT_USE_TLS = 0
# Set this to 1 if the VRWindow class shall be compiled with support for
# swap locks and swap groups (NVidia extension). This is only necessary
# in very rare cases; if you don't already know you need it, leave this
# setting at 0.
# If this is set to 1 and the NVidia extension is not there,
# VRWindow.cpp will generate compiler errors.
VRUI_VRWINDOW_USE_SWAPGROUPS = 0
# Set this to 1 if the operating system supports the input abstraction
# layer. If this is set to 1 and the input abstraction is not supported,
# Joystick.cpp will generate compiler errors.
VRDEVICES_USE_INPUT_ABSTRACTION = 0
# Set this to 1 if the Linux input.h header file has the required
# structure definitions (usually on newer Linux versions). If this is
# set wrongly, HIDDevice.cpp will generate compiler errors.
# This setting is ignored on MacOS X.
VRDEVICES_INPUT_H_HAS_STRUCTS = 1
# Set this to 1 if the Vrui VR device driver shall support Nintendo Wii
# controllers using the bluez user-level Bluetooth library. This
# requires that bluez is installed on the host computer, and that the
# path to the bluez header files / libraries is set properly in
# $(VRUI_MAKEDIR)/Packages.
# For now, the following code tries to automatically determine whether
# bluez is supported. This might or might not work.
VRDEVICES_USE_BLUETOOTH = $(SYSTEM_HAVE_BLUETOOTH)
########################################################################
# Please do not change anything below this line
########################################################################
# Specify version of created dynamic shared libraries
VRUI_VERSION = 3001002
MAJORLIBVERSION = 3
MINORLIBVERSION = 1
VRUI_NAME := Vrui-$(MAJORLIBVERSION).$(MINORLIBVERSION)
# Set additional debug options
ifdef DEBUG
  CFLAGS += -DDEBUG
endif
# Set destination directory for libraries and executables
LIBDESTDIR := $(VRUI_PACKAGEROOT)/$(MYLIBEXT)
# Override the include file and library search directories:
VRUI_INCLUDEDIR = $(VRUI_PACKAGEROOT)
VRUI_LIBDIR = $(VRUI_PACKAGEROOT)/$(MYLIBEXT)
# Directories for installation components
ifdef SYSTEMINSTALL
  HEADERINSTALLDIR = $(INSTALLDIR)/usr/$(INCLUDEEXT)/$(VRUI_NAME)
  ifdef DEBUG
    LIBINSTALLDIR = $(INSTALLDIR)/usr/$(LIBEXT)/$(VRUI_NAME)/debug
    EXECUTABLEINSTALLDIR = $(INSTALLDIR)/usr/$(BINEXT)/debug
  else
    LIBINSTALLDIR = $(INSTALLDIR)/usr/$(LIBEXT)/$(VRUI_NAME)
    EXECUTABLEINSTALLDIR = $(INSTALLDIR)/usr/$(BINEXT)
  endif
  ETCINSTALLDIR = $(INSTALLDIR)/etc/$(VRUI_NAME)
  SHAREINSTALLDIR = $(INSTALLDIR)/usr/share/$(VRUI_NAME)
  PKGCONFIGINSTALLDIR = $(INSTALLDIR)/usr/$(LIBEXT)/pkgconfig
  DOCINSTALLDIR = $(INSTALLDIR)/usr/share/doc/$(VRUI_NAME)
  INSTALLROOT = /usr
else
  ifeq ($(findstring $(VRUI_NAME),$(INSTALLDIR)),$(VRUI_NAME))
    INSTALLSHIM = 
  else
    INSTALLSHIM = /$(VRUI_NAME)
  endif
  HEADERINSTALLDIR = $(INSTALLDIR)/$(INCLUDEEXT)
  ifdef DEBUG
    LIBINSTALLDIR = $(INSTALLDIR)/$(LIBEXT)/debug
    EXECUTABLEINSTALLDIR = $(INSTALLDIR)/$(BINEXT)/debug
  else
    LIBINSTALLDIR = $(INSTALLDIR)/$(LIBEXT)
    EXECUTABLEINSTALLDIR = $(INSTALLDIR)/$(BINEXT)
  endif
  ETCINSTALLDIR = $(INSTALLDIR)/etc$(INSTALLSHIM)
  SHAREINSTALLDIR = $(INSTALLDIR)/share$(INSTALLSHIM)
  PKGCONFIGINSTALLDIR = $(INSTALLDIR)/$(LIBEXT)/pkgconfig
  DOCINSTALLDIR = $(INSTALLDIR)/share/doc$(INSTALLSHIM)
  INSTALLROOT = $(INSTALLDIR)
endif
PLUGININSTALLDIR = $(LIBINSTALLDIR)
ifdef DEBUG
  MAKEINSTALLDIR = $(SHAREINSTALLDIR)/make/debug
else
  MAKEINSTALLDIR = $(SHAREINSTALLDIR)/make
endif
########################################################################
# Specify additional compiler and linker flags
########################################################################
# Set flags to distinguish between static and shared libraries
ifdef STATIC_LINK
  LIBRARYNAME = $(LIBDESTDIR)/$(1).$(LDEXT).a
  OBJDIREXT = Static
else
  CFLAGS += $(CDSOFLAGS)
  LIBRARYNAME = $(LIBDESTDIR)/$(call FULLDSONAME,$(1))
endif
########################################################################
# List packages used by this project
# (Supported packages can be found in ./BuildRoot/Packages)
########################################################################
PACKAGES = 
########################################################################
# Specify all final targets
########################################################################
LIBRARIES = 
PLUGINS = 
EXECUTABLES = 
#
# The basic libraries:
#
LIBRARY_NAMES    = libMisc 
                   libThreads
ifneq ($(SYSTEM_HAVE_LIBUSB1),0)
  LIBRARY_NAMES += libUSB
endif
LIBRARY_NAMES   += libIO 
                   libPlugins 
                   libRealtime 
                   libComm 
                   libCluster 
                   libMath 
                   libGeometry 
                   libGLWrappers 
                   libGLSupport 
                   libGLXSupport 
                   libGLGeometry 
                   libImages 
                   libGLMotif 
                   libSound 
                   libVideo 
                   libALSupport 
                   libSceneGraph 
                   libVrui
LIBRARIES += $(LIBRARY_NAMES:%=$(call LIBRARYNAME,%))
#
# The Vrui VR tool plug-in hierarchy:
#
VRTOOLS_SOURCES = $(wildcard Vrui/Tools/*.cpp)
VRTOOLSDIREXT = VRTools
VRTOOLSDIR= $(LIBDESTDIR)/$(VRTOOLSDIREXT)
VRTOOLS = $(VRTOOLS_SOURCES:Vrui/Tools/%.cpp=$(VRTOOLSDIR)/lib%.$(PLUGINFILEEXT))
PLUGINS += $(VRTOOLS)
#
# The Vrui vislet plug-in hierarchy:
#
VRVISLETS_SOURCES = $(wildcard Vrui/Vislets/*.cpp)
VRVISLETSDIREXT = VRVislets
VRVISLETSDIR = $(LIBDESTDIR)/$(VRVISLETSDIREXT)
VRVISLETS = $(VRVISLETS_SOURCES:Vrui/Vislets/%.cpp=$(VRVISLETSDIR)/lib%.$(PLUGINFILEEXT))
PLUGINS += $(VRVISLETS)
#
# The VR device driver daemon:
#
EXECUTABLES += $(EXEDIR)/VRDeviceDaemon
#
# The VR device driver plug-ins:
#
# Don't build the following device modules unless explicitly asked later:
VRDEVICES_IGNORE_SOURCES = VRDeviceDaemon/VRDevices/Joystick.cpp 
                           VRDeviceDaemon/VRDevices/VRPNConnection.cpp 
                           VRDeviceDaemon/VRDevices/Wiimote.cpp 
                           VRDeviceDaemon/VRDevices/WiimoteTracker.cpp 
                           VRDeviceDaemon/VRDevices/RazerHydra.cpp 
                           VRDeviceDaemon/VRDevices/RazerHydraDevice.cpp 
                           VRDeviceDaemon/VRDevices/OculusRift.cpp
VRDEVICES_SOURCES = $(filter-out $(VRDEVICES_IGNORE_SOURCES),$(wildcard VRDeviceDaemon/VRDevices/*.cpp))
ifneq ($(VRDEVICES_USE_INPUT_ABSTRACTION),0)
  VRDEVICES_SOURCES += VRDeviceDaemon/VRDevices/Joystick.cpp
endif
ifneq ($(VRDEVICES_USE_BLUETOOTH),0)
  VRDEVICES_SOURCES += VRDeviceDaemon/VRDevices/WiimoteTracker.cpp
endif
ifneq ($(SYSTEM_HAVE_LIBUSB1),0)
  VRDEVICES_SOURCES += VRDeviceDaemon/VRDevices/RazerHydraDevice.cpp 
                       VRDeviceDaemon/VRDevices/OculusRift.cpp
endif
VRDEVICESDIREXT = VRDevices
VRDEVICESDIR = $(LIBDESTDIR)/$(VRDEVICESDIREXT)
VRDEVICES = $(VRDEVICES_SOURCES:VRDeviceDaemon/VRDevices/%.cpp=$(VRDEVICESDIR)/lib%.$(PLUGINFILEEXT))
PLUGINS += $(VRDEVICES)
#
# The VR tracker calibrator plug-ins:
#
VRCALIBRATORS_SOURCES = $(wildcard VRDeviceDaemon/VRCalibrators/*.cpp)
VRCALIBRATORSDIREXT = VRCalibrators
VRCALIBRATORSDIR = $(LIBDESTDIR)/$(VRCALIBRATORSDIREXT)
VRCALIBRATORS = $(VRCALIBRATORS_SOURCES:VRDeviceDaemon/VRCalibrators/%.cpp=$(VRCALIBRATORSDIR)/lib%.$(PLUGINFILEEXT))
PLUGINS += $(VRCALIBRATORS)
#
# The Vrui device driver test program:
#
EXECUTABLES += $(EXEDIR)/DeviceTest
#
# The Vrui eye calibration program:
#
EXECUTABLES += $(EXEDIR)/EyeCalibrator
#
# The input device data file dumping program:
#
EXECUTABLES += $(EXEDIR)/PrintInputDeviceDataFile
#
# The Vrui calibration utilities:
#
EXECUTABLES += $(EXEDIR)/XBackground 
               $(EXEDIR)/MeasureEnvironment 
               $(EXEDIR)/ScreenCalibrator 
               $(EXEDIR)/AlignTrackingMarkers
ifneq ($(SYSTEM_HAVE_LIBUSB1),0)
  EXECUTABLES += $(EXEDIR)/OculusCalibrator
endif
# Set the name of the makefile fragment:
ifdef DEBUG
  MAKEFILEFRAGMENT = Share/Vrui.debug.makeinclude
else
  MAKEFILEFRAGMENT = Share/Vrui.makeinclude
endif
# Set the name of the make configuration file:
MAKECONFIGFILE = BuildRoot/Configuration.Vrui
# Set the name of the pkg-config meta data file:
PKGCONFIGFILE = Share/Vrui.pc
# Remember the names of all generated files for "make clean":
ALL = $(LIBRARIES) $(EXECUTABLES) $(PLUGINS) $(MAKEFILEFRAGMENT) $(MAKECONFIGFILE) $(PKGCONFIGFILE)
.PHONY: all
all: config $(ALL)
# Build all libraries before any plug-ins or executables:
$(PLUGINS): | $(LIBRARIES)
$(EXECUTABLES): | $(LIBRARIES)
########################################################################
# Pseudo-target to print configuration options and configure libraries
########################################################################
.PHONY: config
config: Configure-End
.PHONY: Configure-Begin
Configure-Begin:
    @echo "---- Vrui configuration options: ----"
ifneq ($(USE_RPATH),0)
    @echo "Run-time library search paths enabled"
else
    @echo "Run-time library search paths disabled"
endif
.PHONY: Configure-Install
Configure-Install: Configure-Threads 
                   Configure-USB 
                   Configure-Realtime 
                   Configure-GLSupport 
                   Configure-Images 
                   Configure-Sound 
                   Configure-ALSupport 
                   Configure-Video 
                   Configure-Vrui 
                   Configure-VRDeviceDaemon
    @echo "---- Vrui installation configuration ----"
ifdef SYSTEMINSTALL
    @echo "System-level installation requested"
endif
    @echo "Root installation directory               : $(INSTALLDIR)"
    @echo "Header installation root directory        : $(HEADERINSTALLDIR)"
    @echo "Library installation root directory       : $(LIBINSTALLDIR)"
    @echo "Executable installation directory         : $(EXECUTABLEINSTALLDIR)"
    @echo "Plug-in installation root directory       : $(PLUGININSTALLDIR)"
    @echo "Configuration file installation directory : $(ETCINSTALLDIR)"
    @echo "Shared file installation root directory   : $(SHAREINSTALLDIR)"
    @echo "Makefile fragment installation directory  : $(SHAREINSTALLDIR)"
    @echo "Build system installation directory       : $(MAKEINSTALLDIR)"
    @echo "pkg-config metafile installation directory: $(PKGCONFIGINSTALLDIR)"
    @echo "Documentation installation directory      : $(DOCINSTALLDIR)"
.PHONY: Configure-End
Configure-End: Configure-Install
    @echo "---- End of Vrui configuration options ----"

除了通常的-lusb-1.0外,还必须指定-L directory/where/libusb/binary/is/located

使用-L指定的路径在链接时将在默认路径之前搜索,因此链接器将从源编译的libusb-1.0版本而不是系统版本。