使用MinGw标准2011进行基本编译

Basic compilation with MinGw standard 2011

本文关键字:编译 MinGw 标准 2011 使用      更新时间:2023-10-16

程序编译过程中出现意外错误。

(我必须使用2011年标准的std::regex .)

在我的MinGw cmd中,我进入我的程序所在的文件夹,并写入:

c++ -Wall -c -std=c++0x main.cpp

这里一切都很好,但是当我写

c++ -Wall - 0 -std=c++0x main.exe main.o

它告诉我:

g++.exe:错误:main.exe: No such file or directory

为什么?

因为你写开关的顺序不对。-o要求目标文件名在其后面。

这里,你已经告诉GCC将main.exemain.o链接到可执行文件-std=c++0x中,而main.exe甚至还不存在。

g++ -Wall -o -std=c++0x main.exe main.o
#         ^^^^^^^^^^^^^ ????????

相反,告诉它链接main.o到可执行的main.exe,在c++ 0x模式下:

g++ -Wall -std=c++0x -o main.exe main.o
#                    ^^^^^^^^^^^