对 libusb 函数的未定义引用

Undefined reference to libusb functions

我从一个依赖 libusb 的供应商那里得到了一些示例代码。当我尝试使用 make:

进行编译时,我得到了这个
mkdir -p .obj
gcc -I./ -I../libsoccptp/include -std=gnu++11 -pthread -g -o .obj/authentication.o -c authentication.cpp -lusb-1.0 -lusb
gcc -std=gnu++11 -pthread -g -o ../out/bin/authentication .obj/authentication.o -L../out/lib -lsoccptp -L/usr/lib -lusb-1.0 -lstdc++ -lusb-1.0 -lusb
../out/lib/libsoccptp.so: undefined reference to `libusb_has_capability'
../out/lib/libsoccptp.so: undefined reference to `libusb_hotplug_register_callback'
../out/lib/libsoccptp.so: undefined reference to `libusb_handle_events_timeout_completed'
../out/lib/libsoccptp.so: undefined reference to `libusb_hotplug_deregister_callback'
collect2: error: ld returned 1 exit status
Makefile:28: recipe for target '../out/bin/authentication' failed
make: *** [../out/bin/authentication] Error 1

我发现很多其他人的帖子都有类似的问题让 libusb 正确地 link。但似乎其他人的解决方案只是确保将 -lusb-1.0-lusb 作为参数添加到编译器。显然,我的供应商已经设置了 Makefile 来执行此操作。我还验证了我在 Ubuntu 上拥有最新版本的 libusb-1.0,据推测这与我的供应商使用的环境相同。

为什么 link 不正确?

作为参考,这里是 Makefile:

ROOT_DIR ?= ..
OUT ?= ../out
OUT_DIR := $(OUT)/bin
CC := gcc

LIBS := -L${OUT}/lib -lsoccptp -L/usr/lib -lusb-1.0 -lstdc++

override INCLUDES += -I./ -I${ROOT_DIR}/libsoccptp/include

.PHONY: clean

OBJ_DIR := .obj
SOURCES := authentication.cpp shoot_an_image_and_get_it.cpp check_LiveView_status_and_get_images.cpp parser_handling.cpp list_objects.cpp change_camera_setting.cpp
OBJECTS := $(addprefix $(OBJ_DIR)/, $(notdir $(SOURCES:.cpp=.o)))
TARGETS := $(addprefix ${OUT_DIR}/, $(notdir $(basename ${SOURCES})))

all: ${OUT_DIR} $(OBJ_DIR) ${TARGETS}

objs: $(OBJ_DIR) $(OBJECTS)

$(OBJ_DIR)/%.o : %.cpp
    $(CC) $(INCLUDES) -std=gnu++11 -pthread -g -o $@ -c $< -lusb-1.0 -lusb

$(OUT_DIR)/%: $(OBJ_DIR)/%.o
    ${CC} -std=gnu++11 -pthread -g -o $@ $< ${LIBS} -lusb-1.0 -lusb

${OUT_DIR}:
    mkdir -p ${OUT_DIR}

$(OBJ_DIR):
    mkdir -p $(OBJ_DIR)

clean:
    rm -rf ${TARGETS} $(OBJ_DIR)

在与提供软件的供应商的工程师讨论后,确定我使用的是较新版本的 Ubuntu (v16),然后他们开发了该软件。当我在旧版本 (v14) 上编译时,它编译得很好。

工程师无法解释 Ubuntu 16 中的更改破坏了他们的代码,但这暂时解决了我的问题。