2016-11-10 24 views
0

私は sudo brew install libusb と私のプログラム日食ビルドエラー

#include <stdio.h> 
#include <stdlib.h> 
#include <libusb-1.0/libusb.h> 
int main(void) { 
    libusb_context **libcontext; 
    int status = libusb_init(libcontext); 
    if (status == 0) { 
     printf("success"); 
    } 
} 

のlibusbをusblibインストールMacコンピュータ のCプロジェクトのためのEclipse IDEを使用するには、 enter image description here

であります

10:17:53 **** Build of configuration Debug for project testusb **** make all Building file: ../src/testusb.c Invoking: Cross GCC Compiler gcc -O0 -g3 -Wall -c -fmessage-length=0 -stdlib=libstdc++ -MMD -MP -MF"src/testusb.d" -MT"src/testusb.o" -o "src/testusb.o" "../src/testusb.c" ../src/testusb.c:16:6: warning: unused variable 'status' [-Wunused-variable] int status = libusb_init(libcontext); ^../src/testusb.c:16:27: warning: variable 'libcontext' is uninitialized when used here [-Wuninitialized] int status = libusb_init(libcontext); ^~~~~~~~~~ ../src/testusb.c:15:29: note: initialize the variable 'libcontext' to silence this warning libusb_context libcontext; ^ = NULL 2 warnings generated. Finished building: ../src/testusb.c Building target: testusb Invoking: Cross GCC Linker gcc -L/opt/local/lib -o "testusb" ./src/testusb.o Undefined symbols for architecture x86_64:
"_libusb_init", referenced from: _main in testusb.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) make: *
[testusb] Error 1

どのように修正するのですか?

enter image description here

+0

これはライブラリがリンクされていないようです。プロジェクトの設定を確認してください。 – MikeCAT

+0

私は設定写真を追加しますが、設定方法はわかりません。これは初めてのCプログラムです –

+0

参照:http://stackoverflow.com/questions/7050482/libusb-undefined-reference-to – Fang

答えて

0

おかげ@Fang提案がLibusb undefined reference to 私は問題を解決します。 最初のタイプ

pkg-config --list-all 

クエリインストールされているすべてのライブラリ、インストール、 は、出力

があるはず私は

を使用したいのlibusbに対する

pkg-config --libs libusb 

リンクを入力するかどうかのlibusbをチェック

-lusb 

プロジェクトプロップを右クリックerties-> c/C++ビルド - >設定 - >クロスGCCリンカーその他、タイプ-lusb-1.0