问题
When I have hashes/pounds/sharps (#
) in my cpp filenames, I get errors similar to
Makefile:22669: warning: overriding recipe for target '.PHONY'
Makefile:22660: warning: ignoring old recipe for target '.PHONY'
Makefile:22678: warning: overriding recipe for target '.PHONY'
Makefile:22669: warning: ignoring old recipe for target '.PHONY'
Makefile:32887: *** missing separator. Stop.
even though the generated Makefile seems to be only 178 lines long. Is there any way to prevent this other than not using the #
character in my file names?
Edit: seimicolons (;
) seem to cause this problem as well
回答1:
"#" is a comment in make. It's almost 100% certain that CMake is not properly escaping the "#" character when it generates the makefile.
As for why you see those error line numbers, CMake generates a large number of makefiles and invokes them recursively. The one you see at the "root" is likely just a top-level makefile that doesn't do very much. You'll have to look in the CMakeFiles subdirectory for other makefiles. If you run "make VERBOSE=1" with CMake-generated files you'll be able to follow the sub-makes that are invoked. Also if you look at the "entering directory" messages make prints you may be able to figure out which Makefile is being talked about.
The short answer is, though, that you won't be able to use special characters like "#", "$", whitespace, ":", etc. in your file names.
回答2:
I was running into a similar issue with CMake generated files containing unescaped # in filenames, resulting in:
====================[ Build | MyAppDebug | Debug ]==========================
/Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake --build /Users/<user>/MyApp/cmake-build-debug --target MyAppDebug -- -j 8
CMakeFiles/MyAppDebug.dir/build.make:4112: *** missing separator. Stop.
make[2]: *** [CMakeFiles/MyAppDebug.dir/all] Error 2
make[1]: *** [CMakeFiles/MyAppDebug.dir/rule] Error 2
make: *** [MyAppDebug] Error 2
For me, this was fixed in CMake version 1.18.0. (on macOSX) So I added this to my CMake file:
cmake_minimum_required(VERSION 3.18)
来源:https://stackoverflow.com/questions/51072400/cmake-hash-in-file-name