Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
124 views
in Technique[技术] by (71.8m points)

Implementing a system where my program can build an exe file in c++

How would I implement a builder where my program can produce a .exe output. For example, I want my program to ask the user for their name, and once they input this data, it will generate an exe. Once they open that exe, it will print their name. Please do not not ask why this is needed. I just need help on how I would implement such a task. Would I need an internal compiler? All this will be done in c++.

Things to note: I do not want to output a .cpp then compile it.

question from:https://stackoverflow.com/questions/65853754/implementing-a-system-where-my-program-can-build-an-exe-file-in-c

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Learn the format of executables on the platforms you want to support. Make an executable that matched that and prints that name.

Write that binary file and mark it as executable.

Given how simple your program is, it shouldn't be long. You can futz with how the bytes would work by compiling a program in C++ manually. I advise using printf instead of std cout.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...