Can't figure out how to build C application after adding Mongoose Embedded

别等时光非礼了梦想. 提交于 2021-02-11 15:04:33

问题


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.

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 

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.

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?

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 );
}

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)

Thanks for the help!


回答1:


A simple solution is to add to your Makefile :

LDFLAGS+=../mongoose.c

This will build mongoose and link it with your application



来源:https://stackoverflow.com/questions/27264668/cant-figure-out-how-to-build-c-application-after-adding-mongoose-embedded

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!