简体   繁体   English

错误:没有那个文件或目录:编译makefile后'--std=c++11'

[英]Error: no such file or directory: '–std=c++11' after compiling makefile

When I compile using make in the terminal it prints:当我在终端中使用make编译时,它会打印:

g++ -Wall –std=c++11 -c File.cpp
clang: error: no such file or directory: '–std=c++11'
make: *** [Book.o] Error 1

makefile:生成文件:

PROG = studs
CC = g++
OBJS = File.o FileTestDriver.o
CPPFLAGS = -Wall –std=c++11

$(PROG) : $(OBJS)
    $(CC) -o $(PROG) $(OBJS)
File.o : File.h
    $(CC) $(CPPFLAGS) -c File.cpp
FileTestDriver.o :
    $(CC) $(CPPFLAGS) -c FileTestDriver.cpp
clean:
    $(RM) $(PROG) $(OBJS)

FileTestDriver has the main function and File.cpp is just a simple class with some constructors, instance variables and functions. FileTestDriver有 main 函数,而File.cpp只是一个简单的类,带有一些构造函数、实例变量和函数。 I'm not sure where the problem is but I assume it's in the Makefile as I just started using them today.我不确定问题出在哪里,但我认为它在 Makefile 中,因为我今天刚开始使用它们。

When I simply compile g++ -std=c++11 File.cpp I get the error:当我简单地编译g++ -std=c++11 File.cpp我得到错误:

Undefined symbols for architecture x86_64:
  "_main", referenced from:
     implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

But I assume the error is because it has a .h and needs the makefile to be compiled.但我认为错误是因为它有一个.h并且需要编译生成文件。 Anyway, not sure what I'm doing wrong but I appreciate any help.无论如何,不​​确定我做错了什么,但我感谢任何帮助。 Let me know if more info is needed.如果需要更多信息,请告诉我。

Also (maybe this should be a separate question/I need to look harder), but after using the makefile, ./a.out will only ever run the makefile, regardless of the last thing I compiled.另外(也许这应该是一个单独的问题/我需要更仔细地看),但是在使用 makefile 之后, ./a.out只会运行 makefile,而不管我编译的最后一个东西。 Not sure how to change that.不知道如何改变。

If you take a look at your compile line closely, you'll see a very subtle difference between the - before Wall and the before std=c++11 :如果仔细查看编译行您会发现- before Wall before std=c++11之间存在非常细微的差异:

g++ -Wall –std=c++11 -c File.cpp
    ^     ^

Here are those two options, one under the other, captured with Windows Snipping Tool and blown up with Paint.net.这是这两个选项,一个在另一个之下,用 Windows Snipping Tool 捕获并用 Paint.net 炸毁。 You can clearly see that the second "hyphen" is wider:您可以清楚地看到第二个“连字符”更宽:

在此处输入图片说明

And it's wider because it's not a hyphen - the character is actually an en dash (Unicode code point U+2013 ).它更宽,因为它不是连字符 - 该字符实际上是一个en dash (Unicode 代码点U+2013 )。

This problem is often caused by cutting and pasting directly from places like word processors (a) or web pages.这个问题通常是由直接从文字处理器(a)或网页等地方剪切和粘贴引起的。 Because it's not considered a valid lead-in character ( hyphen-minus , or Unicode code point U+002D ), it's simply being treated as a file name, hence the error.因为它不被视为有效的导入字符( hyphen-minus或 Unicode 代码点U+002D ),所以它只是被视为文件名,因此会出现错误。

I suggest you just retype the line (or only the -std=c++11 bit) to ensure it's using the correct character.我建议您重新输入该行(或仅输入-std=c++11位)以确保它使用正确的字符。


(a) Word processors, with their smart text replacement features, will often turn hyphens into en- or em- dashes, or modify your strings or character literals from "pax" into “pax” . (a)文字处理程序具有智能文本替换功能,通常会将连字符转换为加号或破折号,或者将您的字符串或字符文字从"pax"“pax” You can disable this behaviour (smart quotes in MS Word, for example) but it's sometimes quite handy.您可以禁用此行为(例如 MS Word 中的智能引号),但有时它非常方便。

I just tend to avoid using word processors as text editors, or become aware to the possibility that cut'n'pasted code may contain "suspicious" character.我只是倾向于避免使用文字处理器作为文本编辑器,或者意识到剪切和粘贴的代码可能包含“可疑”字符的可能性。 If a piece of text I've gotten from the web or a word processor causes my build system to complain, I examine (and retype manually) the offending section.如果我从网络或文字处理器获得的一段文本导致我的构建系统抱怨,我会检查(并手动重新输入)有问题的部分。

I made a mistake as follows:我犯了以下错误:

# CMakeLists.txt
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std = c++11")

Notice there is NO whitespace between -std and c++11注意-stdc++11之间没有空格

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM