[英]CLion: build program won't run in cmd
When I try to run my C++ project in Code::Blocks IDE
, it'll run the program in Windows CMD without any problem. 当我尝试在
Code::Blocks IDE
运行我的C ++项目时,它将在Windows CMD中运行该程序而没有任何问题。 If I try to run the program via Explorer it'll also run in CMD without any problem. 如果我尝试通过资源管理器运行该程序,它也将在CMD中运行而没有任何问题。
However, if I try to run the exactly SAME program via CLion
, it'll run fine in CLion
itself ( CLion
has a builtin terminal, while Code::Blocks
uses Windows CMD). 但是,如果我尝试通过
CLion
运行完全相同的程序,它将在CLion
本身上正常运行( CLion
具有内置终端,而Code::Blocks
使用Windows CMD)。 But if I try to run the program via Explorer I get this weird error: 但是,如果我尝试通过资源管理器运行程序,则会收到此奇怪的错误:
If I press OK: 如果按“确定”:
Anyone knows what the problem is? 有人知道是什么问题吗? How do I fix this?
我该如何解决?
More information: Code::Blocks
comes as a package with MinGW
. 更多信息:
Code::Blocks
与MinGW
打包在一起。 With CLion
I had to manually download a Toolchain. 使用
CLion
我必须手动下载工具链。 I downloaded and installed MinGW-w64
, because I didn't know anything else and that's what Code::Blocks also used. 我下载并安装了
MinGW-w64
,因为我什么都不知道,这也是Code :: Blocks所使用的。
The weird part about this is that MinGW-w64 is installed in "Program Files (x86)" and not in "Program Files". 与此有关的怪异部分是MinGW-w64安装在“程序文件(x86)”中,而不是在“程序文件”中。
Add the following to your CMakeLists.txt file in CLion: 将以下内容添加到CLion中的CMakeLists.txt文件中:
set(CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS} "-static")
This will work for gcc, which mingw is based upon. 这将适用于mingw所基于的gcc。 For other linkers, you would have to search for their particular switch for static linking.
对于其他链接器,您将必须搜索其特定开关以进行静态链接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.