How to write makefile(nmake) for visual studio build tool cl.exe

2.8k views Asked by At

I want to build a c application with visual-studio build tool cl.exe by invoking nmake similar like make in **NIX systems. I have written a makefile. It cannot find include files and object files for linking. I couldn't find much reference how to link libraries.

CC=cl.exe
INC=-I../include 
LIB=-L../lib 

socket: socket.c
    $(CC) socket.c $(INC) $(LIB) -lssl -lcrypto

output

D:\client>nmake

Microsoft (R) Program Maintenance Utility Version 10.00.30319.01
Copyright (C) Microsoft Corporation.  All rights reserved.

cl.exe socket.c -I../include -L../lib -lssl -lcrypto
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.40219.01 for 80x86
Copyright (C) Microsoft Corporation.  All rights reserved.

cl : Command line warning D9002 : ignoring unknown option '-L../lib'
cl : Command line warning D9002 : ignoring unknown option '-lssl'
cl : Command line warning D9002 : ignoring unknown option '-lcrypto'
socket.c
Microsoft (R) Incremental Linker Version 10.00.40219.01
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:socket.exe
socket.obj
LINK : fatal error LNK1104: cannot open file 'Ws2_32.lib'
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\BIN\cl.exe"' : return code '0x2'
Stop.
1

There are 1 answers

2
user3629249 On

the cl.exe does not use the gcc syntax for libraries and include files.

Here is a (usable but not perfect) example of how to specify the files:

cl main.c freetype.lib gdi32.lib glew.lib jpeg.lib

you might also want to read how to include in cl.exe