Grumblesaurus
Grumblesaurus

Reputation: 3119

How do I set the icon for a program I compiled manually with cl.exe?

How do I set the icon for an executable when I'm creating the executable at the command prompt with cl.exe?

Upvotes: 1

Views: 1375

Answers (2)

e-malito
e-malito

Reputation: 938

You need to separate the compiling and linking stage for this to work.

Assuming your c file is called main.c, you already have an icon called myicon.ico, and you want to generate the executable program.exe:

  1. Create a .rc file, for instance, program.rc with the following content:
IDI_ICON_1 ICON "myicon.ico"

The IDI_ICON_1 is an arbitrary ID that you can use in your application via a #define statement. But just for the application icon, you don't need to do anything.

  1. Compile your source file(s) to generate objects/lib (will create main.obj):
cl -c main.c
  1. Generate the resource file (will create the file program.res):
rc program.rc
  1. Link your objects with the resource file:
link main.obj program.res -out:program.exe

The program should now appear with the icon.

Upvotes: 3

Sushant
Sushant

Reputation: 124

Use resource hacker to edit icon of an .exe file

Upvotes: 0

Related Questions