3

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.
Wafeeq
  • 869
  • 1
  • 16
  • 34
  • Use the Visual Studio console window, which sets up the environment variables such as the include locations. If you want to use regular console window, use the Visual Studio one, and do a "set" command to see all the settings. For paths with spaces in them, surround them with quotes ("). – rcgldr Aug 25 '17 at 13:45
  • @rcgldr already invoking `nmake` from visual studio console window. As in the error it says `ignoring unknown option '-L../lib'` these are my local include files I have placed in `lib` folder. It doesn't understand probably `-L` – Wafeeq Aug 25 '17 at 13:47
  • @rcgldr putting double quotes makes no difference, same result – Wafeeq Aug 25 '17 at 13:49
  • Use cl /? or cl /help to get the syntax for those commands. You could split up the process using `cl /c` to compile, and 'link' to link objects and libraries. – rcgldr Aug 25 '17 at 13:50
  • 3
    include path : `/I`, library path `/link /LIBPATH:` – BLUEPIXY Aug 25 '17 at 13:50
  • @BLUEPIXY seems working. thanks – Wafeeq Aug 25 '17 at 13:57
  • next time try `cl /?` and `link /?`. – BLUEPIXY Aug 25 '17 at 14:01
  • @BLUEPIXY where does the `/LIBPATH:` come from? `cl /help` has nothing like this. – Wafeeq Aug 28 '17 at 08:14
  • 1
    I already told you. try `link /?` – BLUEPIXY Aug 28 '17 at 11:36

1 Answers1

2

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

user3629249
  • 16,402
  • 1
  • 16
  • 17
  • 1
    I would not want to write list of all libraries with `cl` command on one line. My question is how to write a makefile with more manageable ways. I could have more than 50 include file and many libraries. `cl /help` doesn't show the complete picture as well. like if I want to link then `/link` and where does `/LIBPATH` comes from? – Wafeeq Aug 28 '17 at 08:13
  • you could (should) write the makefile such that it produces the needed dependency file for each of the source files. That dependency file, when produced by the makefile, will have all the library header references. – user3629249 Aug 29 '17 at 15:30