2012-04-18 76 views
0

我正在嘗試開發一個包含CUDA支持模式匹配的數據包分析器。我正在使用GTK +創建GUI,但我無法將GUI文件與cuda文件一起編譯。如何爲這種情況編寫makefile?Makefile for Gtk +和cuda

該項目分爲兩部分:1.分析儀2. GUI
分析儀由許多.c,.h文件和一個.cu文件組成。
GUI部分只有一個文件gui.c 我在gui.c中包含了packet_analyzer.h

我嘗試下面的Makefile

all: guitest 

guitest: gui.o list.o queue.o Word.o dictionary.o packet_capturer.o rule.o aho-corasick.o aho-corasick_cuda.o packet_analyzer.o 
    gcc -lpcap -lpthread `pkg-config --cflags --libs gtk+-2.0` gui.o list.o queue.o Word.o dictionary.o packet_capturer.o rule.o aho-corasick.o aho-corasick_cuda.o packet_analyzer.o 

gui.o: gui.c 
    gcc -lpcap -lpthread -c `pkg-config --cflags --libs gtk+-2.0` gui.c 

list.o : list.c 
    gcc -c list.c 

queue.o : queue.c 
    gcc -c queue.c 

Word.o : Word.c Word.h 
    gcc -c Word.c 

dictionary.o : dictionary.c 
    gcc -c dictionary.c 

rule.o : rule.c rule.h 
    gcc -c rule.c rule.h 

packet_capturer.o : packet_capturer.c 
    gcc -lpcap -lpthread -c packet_capturer.c 

aho-corasick.o : aho-corasick.c 
    gcc -lpcap -lpthread -c aho-corasick.c 

aho-corasick_cuda.o : aho-corasick_cuda.cu 
    nvcc -lpcap -lpthread -c aho-corasick_cuda.cu 

packet_analyzer.o : packet_analyzer.c 
    gcc -lpcap -lpthread -c packet_analyzer.c 

clean: 
    rm -rf *o guitest 

我結束了以下錯誤:

aho-corasick_cuda.o: In function `transfer_tries_from_hosttodevice(int, int, int)': 
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x37): undefined reference to `cudaMalloc' 
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x5d): undefined reference to `cudaMalloc' 
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x86): undefined reference to `cudaMalloc' 
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0xac): undefined reference to `cudaMalloc' 
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0xd5): undefined reference to `cudaMalloc' 
aho-corasick_cuda.o:tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0xfb): more undefined references to `cudaMalloc' follow 
aho-corasick_cuda.o: In function `transfer_tries_from_hosttodevice(int, int, int)': 
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x132): undefined reference to `cudaMemcpy' 
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x166): undefined reference to `cudaMemcpy' 
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x19d): undefined reference to `cudaMemcpy' 
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x1d1): undefined reference to `cudaMemcpy' 
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x208): undefined reference to `cudaMemcpy' 
aho-corasick_cuda.o:tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x23c): more undefined references to `cudaMemcpy' follow 
aho-corasick_cuda.o: In function `transfer_packets_from_hosttodevice(void*)': 
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x3b1): undefined reference to `Queue_dequeue(Queue*)' 
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x519): undefined reference to `cudaMalloc' 
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x52b): undefined reference to `cudaMalloc' 
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x53d): undefined reference to `cudaMalloc' 
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x56b): undefined reference to `cudaMemcpy' 
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x58b): undefined reference to `cudaMemcpy' 
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x5ab): undefined reference to `cudaMemcpy' 
aho-corasick_cuda.o: In function `analyze_packets(void*)': 
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x663): undefined reference to `cudaMalloc' 
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x683): undefined reference to `cudaMemcpy' 
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x6dd): undefined reference to `cudaConfigureCall' 
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x777): undefined reference to `cudaMemcpy' 
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x78a): undefined reference to `Queue_dequeue(Queue*)' 
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x7d5): undefined reference to `Queue_enqueue(Queue*, void*)' 
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x7f3): undefined reference to `cudaFree' 
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x802): undefined reference to `cudaFree' 
aho-corasick_cuda.o: In function `__cudaUnregisterBinaryUtil()': 
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x824): undefined reference to `__cudaUnregisterFatBinary' 
aho-corasick_cuda.o: In function `__device_stub__Z14AC_search_CudaPiS_S_S_S_S_S_S_PhiS_(int*, int*, int*, int*, int*, int*, int*, int*, unsigned char*, int, int*)': 
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x85c): undefined reference to `cudaSetupArgument' 
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x87f): undefined reference to `cudaSetupArgument' 
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x8a2): undefined reference to `cudaSetupArgument' 
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x8c5): undefined reference to `cudaSetupArgument' 
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x8e8): undefined reference to `cudaSetupArgument' 
aho-corasick_cuda.o:tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0x90b): more undefined references to `cudaSetupArgument' follow 
aho-corasick_cuda.o: In function `__sti____cudaRegisterAll_52_tmpxft_00001608_00000000_4_aho_corasick_cuda_cpp1_ii_9958a654()': 
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0xa82): undefined reference to `__cudaRegisterFatBinary' 
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text+0xae3): undefined reference to `__cudaRegisterFunction' 
aho-corasick_cuda.o: In function `cudaError cudaLaunch<char>(char*)': 
tmpxft_00001608_00000000-1_aho-corasick_cuda.cudafe1.cpp:(.text._Z10cudaLaunchIcE9cudaErrorPT_[cudaError cudaLaunch<char>(char*)]+0x14): undefined reference to `cudaLaunch' 
aho-corasick_cuda.o:(.eh_frame+0x12): undefined reference to `__gxx_personality_v0' 
collect2: ld returned 1 exit status 
make: *** [guitest] Error 1 
+0

你能發佈你看到的實際問題嗎? – Tom 2012-04-18 07:07:08

+0

編輯該問題請看看... – Arif 2012-04-19 09:05:46

回答

2

您需要鏈接CUDA運行時庫。將-lcudart添加到您的鏈接命令(如有必要,請添加CUDA lib路徑)。

+0

謝謝you.it工作。 – Arif 2012-04-20 03:58:08

1

這是nvcc -lpcap -lpthread $(ANALYZER) -o packet_analyzer.o行未能真實,對不對?通過-o選項,您可以告訴它構建完整的可執行文件,而不僅僅是目標文件。它需要一個main函數來做到這一點,我認爲你沒有任何$(ANALYZER)文件。相反,嘗試使用-c標誌編譯所有源(例如,您已使用的gcc),然後將它們全部包裝在一起並將其與其他gcc命令鏈接起來。

+0

非常感謝...我改變了上面的makefile,但得到錯誤,說cuda函數是undefined ... – Arif 2012-04-19 10:06:46

+0

你有'#包括'在你的頂部調用CUDA函數的源文件? – 2012-04-19 12:53:09

+0

no.without頭文件(cuda.h)分析器部分使用nvcc編譯時給出輸出..我嘗試添加頭文件但得到錯誤:cuda.h:沒有這樣的文件或目錄。 – Arif 2012-04-19 13:17:39