2013-04-21 128 views
2

首先,我安裝在Ubuntu 12.04 SCTP
命令和apt-get安裝libsctp-dev的lksctp工具
然後在我的.c文件,我包括:爲什麼我無法在Linux中編譯sctp程序?

#include <netinet/in.h> 
#include <netinet/sctp.h> 
#include <sys/socket.h> 
#include <stdlib.h> 
#include <unistd.h> 

howerver,當我用gcc編譯,結果是:

undefined reference to `sctp_recvmsg' 
undefined reference to `sctp_get_no_strms' 
undefined reference to `sctp_sendmsg' 

出了什麼問題?

+0

顯示您的編譯命令,並回答您的部分源代碼。 – 2013-04-21 12:34:46

+0

顯示您正在用來編譯程序的'gcc'命令。請記住,'gcc'的參數順序很重要。 – 2013-04-21 12:55:06

+0

Gcc temp.c -o temp – huaxz1986 2013-04-21 22:49:19

回答

4

如果你真的用gcc temp.c -o temp進行編譯,那麼你沒有鏈接任何庫(除了默認的libc.6.so),你需要一些額外的參數gcc;也許嘗試

gcc -Wall -g temp.c -lsctp -o temp 

編譯一旦你的程序與gdb調試器的幫助下調試,你認爲它是沒有bug,你可能會問,編譯器使用優化它

gcc -Wall -O2 temp.c -lsctp -o temp 

程序參數的順序爲gcc非常重要。

+0

它是-lsctp,而不是-lscpt.Thank你,它的工作原理! – huaxz1986 2013-04-22 13:13:20

相關問題