[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [libmicrohttpd] Trying to get the hellobrowser example to work
From: |
Christian Grothoff |
Subject: |
Re: [libmicrohttpd] Trying to get the hellobrowser example to work |
Date: |
Mon, 25 May 2009 09:04:32 -0600 |
User-agent: |
KMail/1.11.2 (Linux/2.6.27-14-generic; KDE/4.2.2; i686; ; ) |
On Sunday 24 May 2009 09:53:58 pm Lance Lefebure wrote:
> Greetings. I'm relatively new to C/C++ and I'm trying to get the
> hellobrowser example to work. I'm using libmicrohttpd-0.4.2 and my
> environment is Kubuntu 9.04 with Kdevelop 3.5.3. I start a new C++ project
> and insert the contents of /doc/examples/hellobrowser.c. That tells me I
> need to get platform.h and microhttpd.h, so I grab those from
> /src/include/, along with plibc.h and put them in my program's src
> directory. I then find that I need MHD_config.h. I find a file with that
> name and a ".in" extension in the root of the downloaded file, so I rename
> it and copy to my program's src directory.
Uh uh. There's a bunch of problems right here. You're not supposed to
directly use platform.h or MHD_config.h. The idea is that you use your build
system to generate files that produce the right #include's for your target
platform. Now, if you're not worried about broad portability, you can likely
just copy (some) of the #include's from platform.h and have them in your code
before you #include <microhttpd.h>. Using MHD_config.h.in is wrong in any
case since that file needs to be processed by configure.ac (if you take the
resutling MHD_config.h, it should work -- for the specific platform where you
compiled MHD, which is not necessarily what you want).
>
> Next, when I try to build the app, I get these errors:
>
> ts3.o: In function `main':
>
> /home/lance/TS3/src/ts3.cpp:31: undefined reference to `MHD_start_daemon'
>
> /home/lance/TS3/src/ts3.cpp:37: undefined reference to `MHD_stop_daemon'
>
> ts3.o: In function `answer_to_connection(void*, MHD_Connection*, char
> const*, char const*, char const*, char const*, unsigned int*, void**)':
>
> /home/lance/TS3/src/ts3.cpp:18: undefined reference to
> `MHD_create_response_from_data'
>
> /home/lance/TS3/src/ts3.cpp:19: undefined reference to `MHD_queue_response'
>
> /home/lance/TS3/src/ts3.cpp:20: undefined reference to
> `MHD_destroy_response'
>
>
>
> I find that I can resolve the undefined reference messages by locating each
> of those functions in microhttpd.h, removing the trailing semi colon, and
> adding a { } to it. I figured this was something to do with C code in C++,
> although I now realize the problem is deeper.
I doubt that it is C vs. C++, the microhttpd header takes care of the symbol
mangling. I think the problem is that you are not giving the "-lmicrohttpd"
option to your C++ compiler and it is hence not linking against the library.
> That resolves my errors, I can built the program, it starts, but isn't
> listening on the port like it should be. I then notice that the functions
> in microhttpd.h don't seem to do anything. I look around and notice that in
> the folder /src/daemon/ there are a bunch of .c and .h files that look
> useful, but I have no idea how to use them.
Well, it "solved" your compile errors by you adding essentially an empty
implementation above. Do *not* touch our libmicrohttpd.h (ever, always a bad
idea), and instead LINK against libmicrohttpd. That should help.
Best,
Christian