简体   繁体   English

我们可以在 code:blocks 中执行多个程序吗

[英]Can we execute more than one programs in code:blocks

SO I am writing a program and writing my code in the main.c file of the project I created.But if I want to sample test some code or function I cannot do so.所以我正在编写一个程序并在我创建的项目的 main.c 文件中编写我的代码。但是如果我想对某些代码或功能进行采样测试,我不能这样做。

I tried adding a new file in the project but it automatically executes the main.c file.我尝试在项目中添加一个新文件,但它会自动执行 main.c 文件。

Isn't there a way where I can run my codes in a different place without disturbing the code in the main.c file有没有一种方法可以让我在不同的地方运行我的代码而不干扰 main.c 文件中的代码

Options for doing this:执行此操作的选项:

Run two instances of Code::Blocks:运行 Code::Blocks 的两个实例:

  • From IDE, uncheck Settings -> Environment -> Allow only one running instance在 IDE 中,取消选中Settings -> Environment -> Allow only one running instance
  • ...Or from command line: codeblocks --multiple-instance & ...或从命令行: codeblocks --multiple-instance &

Create tool to allow target to run detached创建工具以允许目标分离运行

  • From IDE: Use Tools -> Configure tools -> User-defined tools to create a new tool, for example call it exe_tester as shown in example image below.在 IDE 中:使用Tools -> Configure tools -> User-defined tools来创建一个新工具,例如将其exe_testerexe_tester ,如下图所示。 (this name is arbitrary) Note : The exe must have already been built. (这个名字是任意的)注意exe必须已经被构建。 Use the ... navigate button to navigate to the actual location of the exe, and select the .exe (eg. it may be in C:\\codeblocks\\test\\test.exe ) This will be the actual executable that will run detached.使用...导航按钮导航到 exe 的实际位置,然后选择.exe (例如,它可能在C:\\codeblocks\\test\\test.exe )这将是将分离运行的实际可执行文件.

  • Note that working directory is optional, I do not normally use it.请注意,工作目录是可选的,我通常不使用它。 But experiment, it may be useful for what you want to do.但是实验一下,它可能对你想做的事情有用。

  • To run the tool, Go back to Tools menu, and you should see exe_tester .要运行该工具,请返回“ Tools菜单,您应该会看到exe_tester Click it and the .exe it is pointing to will launch detached from the IDE:单击它,它指向的.exe将与 IDE分离启动:

在此处输入图片说明

More on Code::Blocks Tools更多关于代码::块工具

Create two different projects, then add all files except the different mains to both projects.创建两个不同的项目,然后将除不同电源之外的所有文件添加到两个项目中。 Example:例子:

Project 1:项目一:

C:\something\abc.h
C:\something\abc.c
C:\something\xyz.h
C:\something\xyz.c
C:\something\release\main.c
C:\something\release\project1 // the actual IDE project file

Project 2:项目2:

C:\something\abc.h
C:\something\abc.c
C:\something\xyz.h
C:\something\xyz.c
C:\something\test\main.c
C:\something\test\project2 // the actual IDE project file

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

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