0

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!

4

1 回答 1

0

一个简单的解决方案是添加到您的 Makefile :

LDFLAGS+=../mongoose.c

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

于 2014-12-06T13:19:47.360 回答