使用Cmake和Visual Studio Express 2010在命令行中构建hello world

时间:2012-08-05 03:56:21

标签: cmake

我是CMake的新手。我正在尝试使用Visual Studio 2010 Express构建一个非常简单的程序(hello world)。在Visual Studio 2010命令提示符中,我运行了命令:

cmake -g "NMake Makefiles" .

这似乎有效。

C:\Users\david\dev\cmake\hello_world>cmake -g "NMake Makefiles" .
-- Building for: Visual Studio 10
-- Check for working C compiler using: Visual Studio 10
-- Check for working C compiler using: Visual Studio 10 -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler using: Visual Studio 10
-- Check for working CXX compiler using: Visual Studio 10 -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/david/dev/cmake/hello_world

接下来,我尝试运行nmake,这会产生以下错误:

C:\用户\大卫\ dev的\ cmake的\程序hello_world> NMAKE

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

NMAKE : fatal error U1064: MAKEFILE not found and no target specified
Stop.

我在项目目录中看不到Makefile,所以我猜这就是为什么它不起作用,或者CMake使用非标准的Makefile名称?我不确定。我已经粘贴了下面项目目录的内容。

C:\Users\david\dev\cmake\hello_world>dir
 Volume in drive C has no label.
 Volume Serial Number is 4000-10E9

 Directory of C:\Users\david\dev\cmake\hello_world

08/05/2012  01:38 PM    <DIR>          .
08/05/2012  01:38 PM    <DIR>          ..
08/05/2012  01:38 PM            28,584 ALL_BUILD.vcxproj
08/05/2012  01:38 PM               735 ALL_BUILD.vcxproj.filters
08/05/2012  01:38 PM            12,871 CMakeCache.txt
08/05/2012  01:38 PM    <DIR>          CMakeFiles
08/05/2012  01:34 PM               151 CMakeLists.txt
08/05/2012  01:38 PM             1,514 cmake_install.cmake
08/05/2012  01:38 PM             3,150 hello_world.sln
08/05/2012  01:38 PM            36,618 hello_world.vcxproj
08/05/2012  01:38 PM               671 hello_world.vcxproj.filters
08/05/2012  01:37 PM             2,213 hello_world.vpj
08/05/2012  01:37 PM               206 hello_world.vpw
08/05/2012  01:37 PM               134 hello_world.vpwhist
08/05/2012  01:37 PM           106,496 hello_world.vtg
08/05/2012  07:14 AM               118 main.cpp
08/05/2012  01:38 PM            23,914 ZERO_CHECK.vcxproj
08/05/2012  01:38 PM               807 ZERO_CHECK.vcxproj.filters
              15 File(s)        218,182 bytes
               3 Dir(s)  134,161,678,336 bytes free

我的计划的来源是:

#include <iostream>

int main(int argc, char* argv[])
{
    std::cout << *argv << std::endl;

    return 0;
}

我的CMakeLists.txt是:

# CMakeLists.txt
# $ cmake -g "NMake Makefiles" .

cmake_minimum_required(VERSION 2.8)
project(hello_world)
add_executable(hello_world main.cpp)

谢谢,

0 个答案:

没有答案