4

当我尝试从 makefile 链接时,出现以下错误:

LINK : fatal error LNK1104: cannot open file 'LIBCMT.lib'.

生成文件执行:

C:\Users\snmcdonald\Desktop\winMake2\winMake2>nmake "_DEBUG=" /f win2.mk build

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

        cl /c /ZI /Fo"Debug\\" /Fe"Debug\\" main.c
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.30319.01 for 80x86
Copyright (C) Microsoft Corporation.  All rights reserved.

main.c
        cl /c /ZI /Fo"Debug\\" /Fe"Debug\\" lib.c
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.30319.01 for 80x86
Copyright (C) Microsoft Corporation.  All rights reserved.

lib.c
        lib Debug\lib.obj /out:Debug\lib.lib
Microsoft (R) Library Manager Version 10.00.30319.01
Copyright (C) Microsoft Corporation.  All rights reserved.

        link Debug\main.obj Debug\lib.lib /out:Debug\main.exe
Microsoft (R) Incremental Linker Version 10.00.30319.01
Copyright (C) Microsoft Corporation.  All rights reserved.

main.obj : warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/OPT:ICF' specif
ication
LINK : fatal error LNK1104: cannot open file 'LIBCMT.lib'
NMAKE : fatal error U1077: '"C:\Program Files\Microsoft Visual Studio 10.0\VC\BI
N\link.EXE"' : return code '0x450'
Stop.

但是,如果我重新运行失败的完全相同的行并从控制台链接,我将获得成功的构建。我使用的是完全相同的lib,并且obj是从我的 make 文件中生成的。

控制台执行:

C:\Users\snmcdonald\Desktop\winMake2\winMake2>link Debug\main.obj Debug\lib.lib /o
ut:Debug\main.exe
Microsoft (R) Incremental Linker Version 10.00.30319.01
Copyright (C) Microsoft Corporation.  All rights reserved.

main.obj : warning LNK4075: ignoring '/EDITANDCONTINUE' due to '/OPT:ICF' specif
ication

C:\Users\SHANEM~1\Desktop\winMake2\winMake2>debug\main.exe
print from lib

我已经包含了我的 makefile 以供参考。

生成文件

!ifdef _DEBUG
CC = cl
CFLAGS = /c /ZI
FILES = *.c 
OUT = /Fo"Debug\\" /Fe"Debug\\"
LINKOUT = /out:Debug
DIR = Debug
!else
CC = cl
CFLAGS = /O2
FILES = *.c 
OUT = /Fo"Release\\" /Fe"Release\\"
LINKOUT = /out:Release
DIR = Release
!endif

LIB = lib
LINK = link

RM = del
RMFLAGS = *.ojb *.exe 2>NUL

build: main.exe

clean:
    $(RM) $(RMFLAGS)

rebuild: clean build

main.exe: main.obj lib.lib
    $(LINK) $(DIR)\main.obj $(DIR)\lib.lib $(LINKOUT)\main.exe

lib.lib: lib.obj
    $(LIB) $(DIR)\lib.obj $(LINKOUT)\lib.lib

main.obj: 
    $(CC) $(CFLAGS) $(OUT) main.c

lib.obj:
    $(CC) $(CFLAGS) $(OUT) lib.c

测试

我已经在 Visual C 版本 9 和版本 10 上对此进行了测试。我很困惑为什么它会在我的 makefile 上失败,但在命令行上手动输入时会成功运行。

解决方案:

nmake /E /f win2.mk build

/E - 使用环境路径覆盖宏变量。

4

2 回答 2

5

库=库

这搞砸了 LIB 环境变量。是的,/E 会修复它,但你的下一个真正需要 lib.exe 的项目将会失败。选择另一个名称,win32.mak 使用“imlib”。

于 2010-12-18T19:12:41.220 回答
0

该文件应存在于 ...\Microsoft Visual Studio 8\VC\lib

这可能是环境变量设置的差异。从命令行手动运行时检查环境变量设置是什么。

http://us.generation-nt.com/answer/lnk1104-open-file-libcmt-lib-help-21575202.html

LIB 环境变量应包含各种 lib 目录的路径。您还可以运行 VCVARS32.BAT 文件,它会自动为您设置环境。如果您进行大量命令行构建,我建议创建一个调用上述 VSVARS32.BAT 的快捷方式

于 2010-12-18T07:39:41.363 回答