2017-08-25 81 views
0

生成文件(NMAKE)我想通過調用nmake類似像make**NIX系統來構建一個c應用與visual-studio構建工具cl.exe。我寫了一個makefile。它找不到include文件和object文件進行鏈接。我無法找到如何鏈接庫的很多參考資料。如何編寫爲Visual Studio構建工具cl.exe時

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

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

輸出

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. 
+0

使用Visual Studio控制檯窗口,設置環境變量,如包含位置。如果您想使用常規控制檯窗口,請使用Visual Studio之一,並執行「set」命令查看所有設置。對於帶有空格的路徑,用引號括起來(「) – rcgldr

+0

@rcgldr已經從visual studio控制檯窗口調用'nmake'。我放在'lib'文件夾中的本地包含文件,可能不明白'-L' –

+0

@rcgldr把雙引號放在一起沒有區別,結果相同 –

回答

1

cl.exe不使用圖書館的GCC語法和包含文件。

下面是如何指定的文件(可以使用,但並不完美)例如:

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

你可能還需要閱讀how to include in cl.exe

+0

我不想用'cl'命令在一行中寫所有庫的列表。我的問題是如何用更易於管理的方式編寫makefile。我可以有超過50個包含文件和許多庫。 'cl/help'也不會顯示完整的圖片。就好像我想鏈接'/ link','/ LIBPATH'從哪裏來? –

+0

您可以(應該)編寫makefile,以便爲每個源文件生成所需的依賴文件。這個依賴文件,當由makefile生成時,將具有所有庫頭引用。 – user3629249

相關問題