c-包括PJSIP库和编写makefile



我是编写makefile的新手。现在我正在尝试使用pjsipc-library,它安装在我的主目录中。我截取了一些片段,试图编译它。有一些错误,所以我搜索了一个解决方案,所以我发现我必须将这个库的包含在搜索路径中。此外,还有可能在makefile中声明它们,所以我尝试了第二种解决方案。

这里是我的makefile:

pjpath=home/pi/pjproject-2.4.5
LIB=-L/$(pjpath)/pjlib/lib -L/$(pjpath)/pjlib-util/lib -L/$(pjpath)/pjnath/lib -L/$(pjpath)/pjmedia/lib -L/$(pjpath)/pjsip/lib
INC=-I/$(pjpath)/pjlib/include -I/$(pjpath)/pjlib-util/include -I/$(pjpath)/pjnath/include -I/$(pjpath)/pjmedia/include -I/$(pjpath)/pjsip/include
all:
        gcc -o test $(INC) simple_pjsua.c $(LIB) -lpj -lpjlib -lpjnath -lpjmedia -lpjmedia-audiodev -lpjmedia-codec -lpjmedia-videodev -lpjsdp -lpjsip -lpjsip-simple -lpjsip-ua -lpjsua -lpjsua2
clean: 
        rm simple_pjsua.o test

这里是我的c文件simple_pjsua.c:

#define PJ_IS_LITTLE_ENDIAN 1
#define PJ_IS_BIG_ENDIAN 0 
#include <pjsua-lib/pjsua.h>
#define THIS_FILE "App"
#define SIP_USER "demo-user2"
#define SIP_DOMAIN "sip:192.168.2.59"
#define SIP_PASSWD "123456"
    static void on_incoming_call(pjsua_acc_id acc_id, pjsua_call_id call_id, pjsip_rx_data *rdata);
    static void on_call_state(pjsua_call_id call_id, pjsip_event *e);
    static void on_call_media_state(pjsua_call_id call_id);
    static void error_exit(const char *title, pj_status_t status);
    int main(int argc, char *argv[]){
            printf("Hello World");
            return 0;
    }
    static void on_incoming_call(pjsua_acc_id acc_id, pjsua_call_id call_id, pjsip_rx_data *rdata){
            pjsua_call_info ci; 
            PJ_UNUSED_ARG(acc_id);
            PJ_UNUSED_ARG(rdata);
            pjsua_call_get_info(call_id, &ci);
            PJ_LOG(3,(THIS_FILE, "Incoming call from %.*s!!", (int) ci.remote_info.slen, ci.remote_info.ptr));
            /* Automatically answer incoming calls with 200/OK */
            pjsua_call_answer(call_id, 200, NULL, NULL);
    }
    static void on_call_state(pjsua_call_id call_id, pjsip_event *e){
            pjsua_call_info ci; 
            PJ_UNUSED_ARG(e);
            pjsua_call_get_info(call_id, &ci);
            PJ_LOG(3,(THIS_FILE, "Call %d state=%.*s", call_id, (int) ci.state_text.slen, ci.state_text.ptr));
    }
    static void on_call_media_state(pjsua_call_id call_id){
            pjsua_call_info ci; 
            pjsua_call_get_info(call_id, &ci);
            if (ci.media_status == PJSUA_CALL_MEDIA_ACTIVE) {
                    pjsua_conf_connect(ci.conf_slot, 0); 
                    pjsua_conf_connect(0, ci.conf_slot);
            }   
    }
    static void error_exit(const char *title, pj_status_t status){
            pjsua_perror(THIS_FILE, title, status);
            pjsua_destroy();
            exit(1);
    }

这是我的makefile输出:

    gcc -o test -I/home/pi/pjproject-2.4.5/pjlib/include -I/home/pi/pjproject-2.4.5/pjlib-util/include -I/home/pi/pjproject-2.4.5/pjnath/include -I/home/pi/pjproject-2.4.5/pjmedia/include -I/home/pi/pjproject-2.4.5/pjsip/include simple_pjsua.c -L/home/pi/pjproject-2.4.5/pjlib/lib -L/home/pi/pjproject-2.4.5/pjlib-util/lib -L/home/pi/pjproject-2.4.5/pjnath/lib -L/home/pi/pjproject-2.4.5/pjmedia/lib -L/home/pi/pjproject-2.4.5/pjsip/lib -lpj -lpjlib -lpjnath -lpjmedia -lpjmedia-audiodev -lpjmedia-codec -lpjmedia-videodev -lpjsdp -lpjsip -lpjsip-simple -lpjsip-ua -lpjsua -lpjsua2 
In file included from /home/pi/pjproject-2.4.5/pjlib/include/pj/config.h:288:0,
                 from /home/pi/pjproject-2.4.5/pjlib/include/pj/types.h:33,
                 from /home/pi/pjproject-2.4.5/pjsip/include/pjsip/sip_config.h:27,
                 from /home/pi/pjproject-2.4.5/pjsip/include/pjsip/sip_types.h:34,
                 from /home/pi/pjproject-2.4.5/pjsip/include/pjsip.h:24,
                 from /home/pi/pjproject-2.4.5/pjsip/include/pjsua-lib/pjsua.h:30,
                 from simple_pjsua.c:3:
/home/pi/pjproject-2.4.5/pjlib/include/pj/config_site.h:3:35: warning: extra tokens at end of #include directive [enabled by default]
/usr/bin/ld: cannot find -lpj
/usr/bin/ld: cannot find -lpjlib
/usr/bin/ld: cannot find -lpjnath
/usr/bin/ld: cannot find -lpjmedia
/usr/bin/ld: cannot find -lpjmedia-audiodev
/usr/bin/ld: cannot find -lpjmedia-codec
/usr/bin/ld: cannot find -lpjmedia-videodev
/usr/bin/ld: cannot find -lpjsdp
/usr/bin/ld: cannot find -lpjsip
/usr/bin/ld: cannot find -lpjsip-simple
/usr/bin/ld: cannot find -lpjsip-ua
/usr/bin/ld: cannot find -lpjsua
/usr/bin/ld: cannot find -lpjsua2
collect2: ld returned 1 exit status
makefile:6: recipe for target 'all' failed
make: *** [all] Error 1

我还找到了一个有用的网站来解释它是如何做到的,尽管我还不知道。

首先,第一个警告来自库代码,您的代码是清白的。

然后,始终在所有源文件或对象文件之后指定链接库。默认情况下,GNU链接器不会记住尚未被引用的库中的符号,因此,如果以前的对象或库没有引用somelib,它只会删除所有的-lsomelib

所以,我敢打赌,

 gcc -o test $(INC) simple_pjsua.c $(LIB)

会对您有所帮助(或者至少这个特定的错误会得到解决)。

所以我在这个网站上找到了最简单的解决方案,在1.6或更高版本的makefile部分。

# If your application is in a file named myapp.cpp or myapp.c
# this is the line you will need to build the binary.
all: myapp
myapp: myapp.cpp
        $(CC) -o $@ $< `pkg-config --cflags --libs libpjproject`
clean:
        rm -f myapp.o myop

为我工作,但有一条线索我偶然发现了。这一点很重要,在我链接的页面底部也有描述。如果您注意到文件底部有空格(在$(CC)和rm之前),这些是一个单独的选项卡,而不是空格。这很重要,否则make命令将失败;缺少分隔符";错误

相关内容

  • 没有找到相关文章

最新更新