libmicrohttpd icon indicating copy to clipboard operation
libmicrohttpd copied to clipboard

static link with libmicrohttpd issue

Open devsunny opened this issue 10 years ago • 1 comments

Hi Richard,

I am trying to compile and static link with libmicrohttpd. with the following command, I am getting "undefined reference to" error, If I compile without -static flag, it works perfectly. did I do anything wrong? the test.c is just a copy of one of example, I add #include stdlib.h, stdio and string.h.

gcc -static -DHAVE_CONFIG_H -ggdb -std=gnu99 -o test -I/opt/bigdatalab/usrlib/libmicrohttpd/include/ -L /opt/bigdatalab/usrlib/libmicrohttpd/lib -lmicrohttpd test.c -lrt

/tmp/ccaFAFRr.o: In function answer_to_connection': test.c:27: undefined reference toMHD_lookup_connection_value' test.c:31: undefined reference to MHD_create_response_from_buffer' test.c:39: undefined reference toMHD_queue_response' test.c:41: undefined reference to MHD_queue_response' test.c:43: undefined reference toMHD_destroy_response' /tmp/ccaFAFRr.o: In function main': test.c:62: undefined reference toMHD_start_daemon' test.c:69: undefined reference to `MHD_stop_daemon'

devsunny avatar Dec 22 '15 02:12 devsunny

Strange behavior, same thing happen to me, here is how I solve it. undefined reference, frequently refers to a misplacement of arguments in the gcc command.

Same error as you happen to me while having the arguments as: g++ -Wall -static -lmicrohttpd -I ./lib/include/ ./main.cpp -o ./build/main.o

Solve by changing the order to: g++ -Wall -static -I ./lib/include/ ./main.cpp -lmicrohttpd -o ./build/main.o

savethebeesandseeds avatar Nov 19 '22 23:11 savethebeesandseeds