0

環境はwindows10(32bit), gcc-5.3.0, cmake-3.4.0, GNUmake-3.81です。

defaultの設定ではVisual Studio付属のnmakeを使ってのbuildになってしまうため、-G "MSYS Makefiles"というオプションを付けてcmakeを行いました。

directory構成は、
sample/
├ .#main.c
└ CMakeLists.txt
で、それぞれのソースコードは末尾に示します。https://m-tmatma.github.io/cmake/cmake-helloworld.htmlから内容は引用し、main.cを.#main.cに変えただけのものです。これをsample内でcmake -G "MSYS Makefiles"とすると、

-- The C compiler identification is GNU 5.3.0
-- The CXX compiler identification is GNU 5.3.0
-- Check for working C compiler: C:/Pragram Files/MinGW/bin/gcc.exe
-- Check for working C compiler: C:/Program Files/MinGW/bin/gcc.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: C:/Program Files/MinGW/bin/g++.exe
-- Check for working CXX compiler: C:/Program Files/MinGW/bin/g++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: C:/somedir/sample

のようにoutputが得られ、成功します(生成されたMakefileは末尾に載せます)。
しかし、ここでmakeを実行すると、

Makefile:126: *** missing separator.  Stop.

というerrorを吐きます。126行目は、

.#main.obj: .#main.c.obj

という行です。

ファイル名に#があるとエラーを吐くというところまでは分かりました。ファイル名を変更せずにこのエラーを解決するにはどうすればよいのでしょうか。

以下ソースコード

.#main.c

#include <stdio.h>

int main()
{
    printf("Hello World\n");
    return 0;
}

CMakeLists.txt

cmake_minimum_required(VERSION 2.6.4)

# define a variable of project name
set( project_name "HelloWorld")

# set the project as the startup project
set_property(DIRECTORY PROPERTY VS_STARTUP_PROJECT ${project_name} )

# define a project name
project (${project_name})

# define a variable SRC with file GLOB
file(GLOB SRC *.c)

# define sources files of an executable
add_executable(${project_name} ${SRC})

Makefile

# CMAKE generated file: DO NOT EDIT!
# Generated by "MSYS Makefiles" Generator, CMake Version 3.4

# Default target executed when no arguments are given to make.
default_target: all

.PHONY : default_target

# Allow only one "make -f Makefile2" at a time, but pass parallelism.
.NOTPARALLEL:


#=============================================================================
# Special targets provided by cmake.

# Disable implicit rules so canonical targets will work.
.SUFFIXES:


# Remove some rules from gmake that .SUFFIXES does not remove.
SUFFIXES =

.SUFFIXES: .hpux_make_needs_suffix_list


# Suppress display of executed commands.
$(VERBOSE).SILENT:


# A target that is always out of date.
cmake_force:

.PHONY : cmake_force

#=============================================================================
# Set environment variables for the build.

# The shell in which to execute make rules.
SHELL = /bin/sh

# The CMake executable.
CMAKE_COMMAND = /C/Program Files/CMake/bin/cmake.exe

# The command to remove a file.
RM = /C/Program Files/CMake/bin/cmake.exe -E remove -f

# Escaping for special characters.
EQUALS = =

# The top-level source directory on which CMake was run.
CMAKE_SOURCE_DIR = /C/somedir/sample

# The top-level build directory on which CMake was run.
CMAKE_BINARY_DIR = /C/somedir/sample

#=============================================================================
# Targets provided globally by CMake.

# Special rule for the target edit_cache
edit_cache:
    @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake cache editor..."
    /c/Program Files/CMake/bin/cmake-gui.exe -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
.PHONY : edit_cache

# Special rule for the target edit_cache
edit_cache/fast: edit_cache

.PHONY : edit_cache/fast

# Special rule for the target rebuild_cache
rebuild_cache:
    @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..."
    /c/Program Files/CMake/bin/cmake.exe -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
.PHONY : rebuild_cache

# Special rule for the target rebuild_cache
rebuild_cache/fast: rebuild_cache

.PHONY : rebuild_cache/fast

# The main all target
all: cmake_check_build_system
    $(CMAKE_COMMAND) -E cmake_progress_start /C/somedir/sample/CMakeFiles /C/somedir/sample/CMakeFiles/progress.marks
    $(MAKE) -f CMakeFiles/Makefile2 all
    $(CMAKE_COMMAND) -E cmake_progress_start /C/somedir/sample/CMakeFiles 0
.PHONY : all

# The main clean target
clean:
    $(MAKE) -f CMakeFiles/Makefile2 clean
.PHONY : clean

# The main clean target
clean/fast: clean

.PHONY : clean/fast

# Prepare targets for installation.
preinstall: all
    $(MAKE) -f CMakeFiles/Makefile2 preinstall
.PHONY : preinstall

# Prepare targets for installation.
preinstall/fast:
    $(MAKE) -f CMakeFiles/Makefile2 preinstall
.PHONY : preinstall/fast

# clear depends
depend:
    $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1
.PHONY : depend

#=============================================================================
# Target rules for targets named HelloWorld

# Build rule for target.
HelloWorld: cmake_check_build_system
    $(MAKE) -f CMakeFiles/Makefile2 HelloWorld
.PHONY : HelloWorld

# fast build rule for target.
HelloWorld/fast:
    $(MAKE) -f CMakeFiles/HelloWorld.dir/build.make CMakeFiles/HelloWorld.dir/build
.PHONY : HelloWorld/fast

.#main.obj: .#main.c.obj

.PHONY : .#main.obj

# target to build an object file
.#main.c.obj:
    $(MAKE) -f CMakeFiles/HelloWorld.dir/build.make "CMakeFiles/HelloWorld.dir/.#main.c.obj"
.PHONY : .#main.c.obj

.#main.i: .#main.c.i

.PHONY : .#main.i

# target to preprocess a source file
.#main.c.i:
    $(MAKE) -f CMakeFiles/HelloWorld.dir/build.make "CMakeFiles/HelloWorld.dir/.#main.c.i"
.PHONY : .#main.c.i

.#main.s: .#main.c.s

.PHONY : .#main.s

# target to generate assembly for a file
.#main.c.s:
    $(MAKE) -f CMakeFiles/HelloWorld.dir/build.make "CMakeFiles/HelloWorld.dir/.#main.c.s"
.PHONY : .#main.c.s

# Help Target
help:
    @echo "The following are some of the valid targets for this Makefile:"
    @echo "... all (the default if no target is provided)"
    @echo "... clean"
    @echo "... depend"
    @echo "... edit_cache"
    @echo "... rebuild_cache"
    @echo "... HelloWorld"
    @echo "... .#main.obj"
    @echo "... .#main.i"
    @echo "... .#main.s"
.PHONY : help



#=============================================================================
# Special targets to cleanup operation of make.

# Special rule to run CMake to check the build system integrity.
# No rule that depends on this can have commands that come from listfiles
# because they might be regenerated.
cmake_check_build_system:
    $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0
.PHONY : cmake_check_build_system

1 件の回答 1

0

ファイル名に#があるとエラーを吐くというところまでは分かりました。ファイル名を変更せずにこのエラーを解決するにはどうすればよいのでしょうか。

makeのマニュアルによると、#をコメントではなく、リテラルとして使用したい場合は、.\#main.cのように、バックスラッシュ(\)でエスケープするとあります。

そのため、Makefile内の.#main.\#mainに置換すれば、該当エラーは解決するはずです。

5
  • cmakeのバグなのですかね…教えてくださり、ありがとうございました。
    – ROCKTAKEY
    2018年8月18日 17:09
  • @ROCKTAKEY さん。エスケープが必要なファイル名がエスケープされないというのはバグといえばバグなのかもしれません。エスケープが必要な特殊なファイル名を使用しないというのも1つの方法だと思います。
    – user29553
    2018年8月19日 9:23
  • # に関する挙動は仕様です。以下に記述があります。cmake.org/cmake/help/v3.12/manual/… 2018年8月19日 10:10
  • @user29553 今回は.#で始まるファイルを使うことを指定されていたため、やむを得なかったのですが、なるべく#を含まないファイル名を利用することにします。回答有り難うございました。
    – ROCKTAKEY
    2018年8月19日 16:11
  • @KiminoriKitahata これはcmakeファイル内に記述された#の話ではないでしょうか(間違っていたらすみません)。今回の場合、CmakeLists.txtではコメントアウト以外での#の使用は行なっていません。#をファイル名に含むファイルを対象にcmakeを行なった際、生成されるMakefile内で、先の「ファイル名に含まれる#」がエスケープされていないためにエラーになる、という話です。
    – ROCKTAKEY
    2018年8月19日 16:18

この質問に回答するには、ログインする必要があります。

求めていた回答ではありませんか? のタグが付いた他の質問を参照する。