After stumbling across this post looking for similar information, although an old post, I thought I would add what I learnt for others looking for similar information.
Given the following directory structure;
C:\Projects
|
Gimp
|
bin
build
src
(A) - In this example, the C:\Projects directory is the root of my projects, this root folder can be located anywhere you choose and have any name you choose. Each folder within this folder can be any project you want, with any folder name, as an example, project_1, project_2, project_3 etc. As shown, you can see that the project folder for this example is called Gimp.
(B) - Within the project folder, Gimp, I created three folders, a bin folder, a build folder and a src folder.
- bin : A folder for our .exe
- build : A folder for our .obj files
- src : A folder for our script files, .c files (.cpp if using C++), .bat files, etc
(C) Within the src folder I have a C source file named main.c, this file is the entry point to my application. This can be named anything you want, but for this example, main.c is what I use. My main.c file is very simple;
main.c
#include <stdio.h>
int main()
{
printf_s("******************************************************\n");
printf_s("** Gimp v0.0.1 Prototype\n");
printf_s("** All work, no play, makes Johnson Doe a dull boy... \n");
printf_s("******************************************************\n");
return 0;
}
(D) Within the src folder I have a batch script file named build.bat, this file is used to build my project. This can be named anything you want, but for this example, build.bat is what I use. My build.bat file is very simple;
build.bat
@echo off
rem Build .exe using cl
cl /W4 /Fe:..\\bin\\gimp.exe /Fo"..\\build\\" main.c
rem Start gimp.exe
cd ..\bin
gimp.exe
cd ..\src
(E) While inside of the Developer Command Prompt for VS 2022, which is what I'm using for this project, I traverse to the C:\Projects\Gimp\src directory, the home of my build.bat. I then run the command build.bat in the command prompt, which triggers my build.bat script above.
The part you will be most interested in is "cl /W4 /Fe:..\\bin\\gimp.exe /Fo"..\\build\\" main.c".
According to the official documentation, the compiler command-line syntax is;
CL [option...] file... [option | file]... [lib...] [@command-file] [/link link-opt...]
cl - The Compiler Command-Line executable
/W4 - Sets the output warning level
/Fe - Renames the executable file
/Fo - Creates an object file
main.c - My source file/files
As you can see, the /Fe: option which renames the executable file /Fe:..\\bin\\gimp.exe is where I link my .exe file to the bin folder.
The /Fo option which creates the .obj files /Fo"..\\build\\" is where I link my .obj file creation to the build folder.
In closing, we have a Project folder as the root of our projects and we have sub project folders. Within those sub project folders we have created three sub folders, bin, build and src. Using a batch file starting in the src folder we then linked two of the three folders using cl command line option. Hope this helps someone in the future.