添加Mongoose Embedded后无法弄清楚如何构建C应用程序 [英] Can't figure out how to build C application after adding Mongoose Embedded

查看:67
本文介绍了添加Mongoose Embedded后无法弄清楚如何构建C应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对C开发特别是makefile文件还很陌生,所以请多多包涵.我有一个功能良好的C应用程序,可以很好地构建(基于此项目)带有Makefile,但我希望它能够响应http请求.因此,猫鼬.

I'm fairly new to C development, and especially to makefiles, so please bear with me. I have a functional C application that builds nicely (based on this project) with it's Makefile, but I want to be able to have it respond to http requests. Thus, Mongoose.

在功能上,Makefile调用:

Functionally, the Makefile calls:

g++ -pthread -I./ -I../../dmx/include -I/usr/include/glib-2.0 -I/usr/include/gtk-3.0 -I/usr/lib/arm-linux-gnueabihf/glib-2.0/include -I/usr/include/pango-1.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/atk-1.0  -g -c DMXController.c -o DMXController.o -Wno-deprecated-declarations
g++ -o DMXController.bin DMXController.o -lgtk-3 -lgdk-3 -latk-1.0 -lgio-2.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lcairo-gobject -lpango-1.0 -lcairo -lgobject-2.0 -lglib-2.0 -lusb -lm -L../../dmx/lib -ldmx -L. -ldl -lpthread  -Wl,--no-whole-archive -rdynamic
rm DMXController.o 

在没有任何Mongoose函数调用的情况下 都可以正常工作,但是一旦添加一个就中断了.我将mongoose.c和mongoose.h文件复制到了直接的父目录中,并添加了 #include"mongoose.h" ,但是我不确定如何将依赖项添加到Makefile中.

This works fine without any of the Mongoose function calls, but breaks as soon as I add one in. I copied the mongoose.c and mongoose.h files into the immediate parent directory and added #include "mongoose.h", but I'm not really sure how to add the dependencies to the Makefile.

Mongoose文档说要使用 cc app.c mongoose.c -pthread -o app 形式进行构建,但是如何将其与已有的东西结合起来?

The Mongoose documentation says to build using the form cc app.c mongoose.c -pthread -o app, but how do I combine that with what I already have?

如果我使用mongoose函数调用在应用程序代码上运行现有的Makefile,则编译错误为:对'mg_create_server'的未定义引用(或任何其他的mongoose函数,我可以使用).

If I run my existing Makefile on my application code with mongoose function calls, the compile error is: undefined reference to 'mg_create_server' (or any other mongoose function that I may use).

与应用程序代码相关的部分如下.

The relevant-seeming parts of the application code follow.

#include <gtk/gtk.h>                        // GTK+3.0 graphics library
#include <dmx.h>                            // DMX interface library
#include "mongoose.h"                       // Mongoose Web server

// ...

int main( int argc, char *argv[] )
{
    // initialize mg
    struct mg_server *server = mg_create_server(NULL, NULL); // undefined reference
    mg_set_option(server, "document_root", ".");      // undefined reference
    mg_set_option(server, "listening_port", "8080");  // undefined reference

    // initialize DMX
    int error;
    error = initDMX(); // local function that works fine
    if ( error < 0 ) return ( error );

    // do stuff 
    for (;;) {
            mg_poll_server(server, 1000);   // undefined reference
    }

    // kill mg
    mg_destroy_server(&server); // undefined reference

    // kill DMX
    exitDMX(); // local function that works fine

    // die quietly
    return ( 0 );
}

Makefile的内容:(当前...我一直在尝试各种方法)

Contents of the Makefile: (currently... I've been trying various things)

CC=g++
CFLAGS+=  -pthread

LDFLAGS+= -lgtk-3 -lgdk-3 -latk-1.0 -lgio-2.0 -lpangocairo-1.0 \
      -lgdk_pixbuf-2.0 -lcairo-gobject -lpango-1.0 -lcairo \
      -lgobject-2.0 -lglib-2.0 -lusb -lm \
      -L../../dmx/lib -ldmx -L.# -lmongoose -ldl -lpthread

INCLUDES+= -I. -I../../dmx/include \
       -I/usr/include/glib-2.0 -I/usr/include/gtk-3.0 \
       -I/usr/lib/arm-linux-gnueabihf/glib-2.0/include \
       -I/usr/include/pango-1.0 -I/usr/include/cairo \
       -I/usr/include/pixman-1 -I/usr/include/gdk-pixbuf-2.0 \
       -I/usr/include/atk-1.0

OBJS=DMXController.o
BIN=DMXController.bin

all: $(BIN)

%.o: %.c
    @rm -f $@
    $(CC) $(CFLAGS) $(INCLUDES) -g -c $< -o $@ -Wno-deprecated-declarations

%.bin: $(OBJS)
    $(CC) -o $@ $(OBJS) $(LDFLAGS) -Wl,--no-whole-archive -rdynamic
    @cp $@ ../bin

clean:
    for i in $(OBJS); do (if test -e "$$i"; then ( rm $$i ); fi ); done
    @rm -f $(BIN)

感谢您的帮助!

推荐答案

一个简单的解决方案是将其添加到Makefile中:

A simple solution is to add to your Makefile :

LDFLAGS+=../mongoose.c

这将构建猫鼬并将其与您的应用程序链接

This will build mongoose and link it with your application

这篇关于添加Mongoose Embedded后无法弄清楚如何构建C应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆