3

我是 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:\Users\david\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)

谢谢,

4

0 回答 0