How to add -lws2_32 in makefile

Everybody is good!
Recently in the code from Linux to Windows transplant in MinGW, an error has occurred

undefined reference to `select@20'
undefined reference to `__WSAFDIsSet@8'

The search is sure to include<winsock2.h>, and add the -lws2_32. to the linker.

But the existing makefile is the predecessor of writing, learn a skill not Jing, do not know how to modify. Qiujiao you greatly!

We have three Makefile layer calls... I put some of PO most relevant consciousness, if lost, please.!

.SUFFIXES:
CONTIKI_CPU=$(CONTIKI)/platform/omnetpp
CONTIKI_CPU_DIRS = . net

CONTIKI_SOURCEFILES += mtarch.c rtimer-arch.c symtab.c announcement.c watchdog.c contract.c
###CONTIKI_SOURCEFILES += mtarch.c rtimer-arch.c elfloader-stub.c symtab.c announcement.c watchdog.c contract.c

### Compiler definitions
CC = gcc
LD = gcc
AS = as
NM = nm
OBJCOPY = objcopy
STRIP = strip
ifdef WERROR
CFLAGSWERROR=-Werror -pedantic -std=c99 -Werror
endif
### Enable -fPIC to support 64Bit OMNeT++ / INET versions
CFLAGSNO = -Wall -g -I/usr/local/include $(CFLAGSWERROR)###-fPIC
CFLAGS += $(CFLAGSNO) -O
LDFLAGS += -Wl,-Map=contiki-$(TARGET).map, -export-dynamic
### Compilation rules
###-lws2_32

%.so: $(OBJECTDIR)/%.o
$(V) echo "Build .so"
$(LD) -shared -trace -o $@ $^ It is here, need to add -lws2_32 to GCC
The last command line, may I ask how?

ifdef CORE
.PHONY: symbols.c symbols.h
symbols.c symbols.h:
$(V) echo "Build symbol"
$(NM) -C $(CORE) | grep -v @ | grep -v dll_crt0 | awk -f $(CONTIKI)/tools/mknmlist > symbols.c
else
symbols.c symbols.h:
cp ${CONTIKI}/tools/empty-symbols.c symbols.c
cp ${CONTIKI}/tools/empty-symbols.h symbols.h
endif

contiki-$(TARGET).a: ${addprefix $(OBJECTDIR)/,symbols.o}

Started by Sandy at November 11, 2016 - 1:47 PM

Judging from the makefile, the generated dynamic library file, rather than a binary executable file.
So there's no need to add in the makefile -lws2_32, with no.

If is a compilation error, it only need include header file can be.
Link to a so, does not require the ws2_32 Library.

------------------------------
Need to add -lws2_32 should be generated binary in the linked executable files in place, the makefile did not see this behavior.

Posted by Taylor at November 17, 2016 - 1:53 PM

CFLAGS += -lws2_32

Posted by Neil at November 24, 2016 - 1:55 PM

CFLAGS + = -lws2_32 agree with upstairs

Posted by Ingram at November 26, 2016 - 2:41 PM

In the variable LDFLAGS

Posted by Avery at December 01, 2016 - 3:37 PM

Thank you reply, I have include #include < in the code; winsock2.h> and #include <winsock.h>, don't know to still need not to need other?
On the other, when I set CFLAGS = $(CFLAGSNO) -O -lws2_32,
Error display
gcc.exe: -lws2_32: linker input file unused because linking not done
LD hello-world.omnetpp
contiki-omnetpp.a(contiki-main.o): In function `main':
c:/contiki/examples/hello-world/../../platform/omnetpp/./contiki-main.c:84: undefined reference to `select@20'
c:/contiki/examples/hello-world/../../platform/omnetpp/./contiki-main.c:86: undefined reference to `__WSAFDIsSet@8'
collect2: ld returned 1 exit status

Posted by Sandy at December 14, 2016 - 4:09 PM

In addition, for this question, I also found a similar situation and solutions on the Internet,


The basic situation of others is to get this -lws2_32 statement, on the back of all the.O files,
If you just add the variables in CFLAGS, then the output of the command line, -lws2_32 is always in front of all the object files.
I think this may be the problem. .

Continue to ask for advice, thank you

Posted by Sandy at December 24, 2016 - 4:42 PM

Thank you help! The GCC command line produced by manually modify the makefile, I have been identified, is to
The linker stage, the command line with -lws2_32.

The modified command line
gcc -Wl,-Map=contiki-omnetpp.map, -export-dynamic hello-world.co contiki-omnetpp.a -o hello-world.omnetpp -lws2_32

Corresponding to the makefile.
LDFLAGS += -Wl,-Map=contiki-$(TARGET).map, -export-dynamic%.so: $(OBJECTDIR)/%.o
$(V) echo "Build .so"
$(LD) -shared -trace -o $@ $^

So I just want to ask you how to modify the makefile to add this line? Directly in the $(LD) into the -lws2_32 -shared -trace -o seems not $@ $^.!

Answer the questions of the 100 points is still valid!

Posted by Sandy at January 06, 2017 - 5:33 PM