Search code examples
cmakefilelinkerplcsiemens

why linker looks for LIBCMT.lib in x86 directory instead x64?


SETUP

Windows 10

GOAL

I found a library libnodave to communicate through S7-protocol
I'm trying to build examples on x64 architecture through edited makefile

ISSUE

Even though I set directories looking for libraries for x64 (VAR =64), the linker looks for LIBCMT.lib in x86 folder . Why? If i change VAR =86 everything is fine.

crutial part of linking log:
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.30.30705\lib\x86\LIBCMT.lib : warning LNK4272: library machine type 'x86' conflicts with target machine type 'x64'

Makefile:

#
# Makefile to build a Windows Version of LIBNODAVE using MSVC++ from Microsoft.
#
# The directory where the tools are:
VCPATH=C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.30.30705
SDKPATH=C:\Program Files (x86)\Windows Kits\10

VER=64

CC="$(VCPATH)\bin\Hostx$(VER)\x$(VER)\cl"
LL="$(VCPATH)\bin\Hostx$(VER)\x$(VER)\link"

CFLAGS= -I"$(VCPATH)\include" -I"$(SDKPATH)\Include\10.0.20348.0\um" -I"$(SDKPATH)\Include\10.0.20348.0\shared" -I"$(SDKPATH)\Include\10.0.20348.0\ucrt" -c -DBCCWIN -DDAVE_LITTLE_ENDIAN -TC
LLFLAGS= /LIBPATH:"$(VCPATH)\lib\x$(VER)" /LIBPATH:"$(SDKPATH)\Lib\10.0.20348.0\ucrt\x$(VER)" /LIBPATH:"$(SDKPATH)\Lib\10.0.20348.0\um\x$(VER)" /DEF:libnodave.DEF 


PROGRAMS=testISO_TCP.exe testISO_TCPload.exe 

LIBRARIES=libnodave.dll

all: $(LIBRARIES) $(PROGRAMS)



libnodave.dll: nodave.obj setportw.obj openSocketw.obj openS7online.obj 
    $(LL) $(LLFLAGS) /DLL nodave.obj setportw.obj openSocketw.obj openS7online.obj "$(SDKPATH)\Lib\10.0.20348.0\um\x$(VER)\WS2_32.Lib" /OUT:libnodave.dll    
testISO_TCP.exe: nodave.obj openSocketw.obj testISO_TCP.obj
    $(LL) $(LFLAGS) testISO_TCP.obj openSocketw.obj nodave.obj "$(SDKPATH)\Lib\10.0.20348.0\um\x$(VER)\WS2_32.Lib" /OUT:$@
testISO_TCPload.exe: nodave.obj  openSocketw.obj testISO_TCPload.obj 
    $(LL) $(LFLAGS) testISO_TCPload.obj openSocketw.obj nodave.obj "$(SDKPATH)\Lib\10.0.20348.0\um\x$(VER)\WS2_32.Lib" /out:testISO_TCPload.exe

#
# delete all but the sources:
#
clean:  
    del /f /q *.tds *.il? *.obj *.map *.lib *.dll *.exe *.exp
distclean:  
    del /f /q *.tds *.il? *.obj *.map

nodave.obj: nodave.c nodave.h
    $(CC) $(CFLAGS) -DDOEXPORT nodave.c
setportw.obj: setportw.c
    $(CC) $(CFLAGS) -DDOEXPORT setportw.c
openSocketw.obj: openSocketw.c
    $(CC) $(CFLAGS) -DDOEXPORT openSocketw.c
openS7online.obj: openS7online.c openS7online.h 
    $(CC) $(CFLAGS) -DDOEXPORT openS7online.c
s7fake.obj: s7fake.c
    $(CC) $(CFLAGS) -DDOEXPORT s7fake.c

Solution

  • The problem was that i was building it with Visual Studio 2022 Developer Command Prompt version x86 that reference wrong nmake.
    I had to process it with x64 that in my case is located here : "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat"