【问题标题】:Windows cmake cannot find memset or other standard functionsWindows cmake 找不到 memset 或其他标准函数
【发布时间】:2017-03-31 00:48:54
【问题描述】:

我正在使用 cmake 编译一组包,我经常为此编写自己的 CMakeLists.txt。我必须使用 Visual Studio 9 2008 和 Visual Studio 14 2015 编译它们

对于 VS2015 编译通常可以毫无问题地完成,但是在 VS2008 中我经常遇到 cmake 没有链接到或包含一些标准 msvc 库(或者具体来说是 msvc 运行时库)的问题。结果,如果被模块调用,它就找不到memset()。其中一个模块是 glew,它具有以下输出:

Scanning dependencies of target glew
[  8%] Building C object CMakeFiles/glew.dir/C_/Users/Daniel/OneDrive/src/glew-2.0.0/src/glew.c.obj
glew.c
[ 16%] Building RC object CMakeFiles/glew.dir/C_/Users/Daniel/OneDrive/src/glew-2.0.0/build/glew.rc.res
Microsoft (R) Windows (R) Resource Compiler Version 6.1.7600.16385
Copyright (C) Microsoft Corporation.  All rights reserved.

[ 25%] Linking C shared library bin\glew32.dll
   Creating library lib\glew32.lib and object lib\glew32.exp
glew.c.obj : error LNK2019: unresolved external symbol memset referenced in function glewContextInit
bin\glew32.dll : fatal error LNK1120: 1 unresolved externals
LINK failed. with 1120
NMAKE : fatal error U1077: 'C:\ProgramData\chocolatey\lib\cmake.portable\tools\cmake-3.6.1-win32-x86\bin\cmake.exe' : return code '0xffffffff'
Stop.
NMAKE : fatal error U1077: '"C:\Users\Daniel\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\amd64\nmake.exe"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Users\Daniel\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\amd64\nmake.exe"' : return code '0x2'
Stop.

我知道我必须 include the libcmt.lib or msvcrt.lib (+headers) 到该项目,但我不知道怎么做。我找到了一些线索herehere,但到目前为止还没有一个线索可以引导我。 从命令行调用 cmake 时是否还有一种方法可以做到这一点(因此不必自己编辑或修补 CMakeLists.txt 文件)? 感谢您提供任何见解!

【问题讨论】:

    标签: c windows visual-studio visual-studio-2008 cmake


    【解决方案1】:

    删除链接器 -nodefaultlib 选项;这可以在 IDE GUI 中的 Linker / Input / Ignore All Default Libraries / No 处设置

    【讨论】:

      猜你喜欢
      • 2010-10-05
      • 1970-01-01
      • 2017-09-25
      • 2012-10-24
      • 2021-01-16
      • 2020-11-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多