fetich
V2EX  ›  问与答

VS2013 编译《C++ Primer》上的代码,提示 cannot open file 'kernel32.lib'

  •  
  •   fetich · Jan 11, 2015 · 5496 views
    This topic created in 4165 days ago, the information mentioned may be changed or developed.

    这是什么原因?

    用VS2012命令行可以编译,VS2013命令行不能编译,用clang也不行。

    是我哪里设置错误了么,请指教。

    15 replies    2015-01-11 18:47:02 +08:00
    fetich
        1
    fetich  
    OP
       Jan 11, 2015
    #include <iostream>

    int main() {
    int currVal = 0, Val = 0;
    if(std::cin >> currVal) {
    int cnt = 1;
    while(std::cin >> Val) {
    if(Val == currVal) ++cnt;
    else {
    std::cout << currVal << " occurs" << cnt << " times " << std::endl;
    cnt = 1;
    currVal = Val;
    }
    }
    std::cout << currVal << " occurs" << cnt << " times " << std::endl;
    }
    return 0;
    }

    代码在此。
    paulw54jrn
        2
    paulw54jrn  
       Jan 11, 2015
    fetich
        3
    fetich  
    OP
       Jan 11, 2015
    @paulw54jrn
    这篇帖子我看过,重装VS很麻烦的,而且不一定解决。至于帖子里提到过的SDK,它的安装路径是 C:\Program Files (x86)\Windows Kits,已经安装过了,应该不是这个原因。

    我来问问,就是看看有人碰到和我一样的问题么,有效的解决方法是什么,上面的代码这么简单,不能编译也是非常郁闷。
    fetich
        4
    fetich  
    OP
       Jan 11, 2015
    逛V的时候,看到初学者还是用编辑器+gcc/llvm,但是上面的代码clang出现了16个错误。。。
    acros
        5
    acros  
       Jan 11, 2015
    自己拿2013试了下没问题··
    x64的系统。
    估计是工程设置不一样?
    fetich
        7
    fetich  
    OP
       Jan 11, 2015
    @acros
    额,那工程设置能详细说一下嘛,另外你使用IDE的么,还是cl命令行?
    @paulw54jrn
    等会儿试试吧。
    dsdshcym
        8
    dsdshcym  
       Jan 11, 2015
    用 clang 没有错误啊
    fetich
        9
    fetich  
    OP
       Jan 11, 2015
    @dsdshcym
    什么系统,编辑器+clang?看来的确是我设置问题了。
    acros
        10
    acros  
       Jan 11, 2015
    @fetich win7 64
    IDE里面直接新建了个win32的console工程编译的
    dsdshcym
        11
    dsdshcym  
       Jan 11, 2015
    @fetich
    OS X。应该是编译器没有设好吧,没用过 VS ,个人猜测。
    ltm
        12
    ltm  
       Jan 11, 2015
    -------------- Build: Debug in test (compiler: GNU GCC Compiler)---------------

    mingw32-g++.exe -Wall -fexceptions -g -c C:\。。。\main.cpp -o obj\Debug\main.o
    mingw32-g++.exe -o bin\Debug\test.exe obj\Debug\main.o
    Output file is bin\Debug\test.exe with size 988.12 KB
    Process terminated with status 0 (0 minute(s), 1 second(s))
    0 error(s), 0 warning(s) (0 minute(s), 1 second(s))


    gcc没问题。 如果只是为了学C++的话,还是不要用VS了,我以前就陷过这个坑(往事不堪回首啊,vs出了问题,最后搞到直接重装系统……),codeblocks或eclipse就很好了。
    yksoft1
        13
    yksoft1  
       Jan 11, 2015
    明显是静态链接CRT的时候要用到Windows的动态库,然后环境变量LIB里没有SDK的路径
    endrollex
        14
    endrollex  
       Jan 11, 2015
    tabris17
        15
    tabris17  
       Jan 11, 2015
    环境变量没设置好吧,为啥不用IDE编译呢
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1051 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 66ms · UTC 18:05 · PVG 02:05 · LAX 11:05 · JFK 14:05
    ♥ Do have faith in what you're doing.