Author Topic: User template and output filename  (Read 6027 times)

Baz

  • Guest
User template and output filename
« on: May 22, 2006, 02:25:01 pm »
Hello all,
I want the output filename to be the name of the project. I'm using a custom template and have added
Code
<Option output="bin\Release\$(PROJECT_NAME).exe" />
in the template. Unfortunately, the $(PROJECT_NAME) variable picks up the name used in the template itself and not the name of the project.
any ideas?
Many thanks.

Baz

  • Guest
Re: User template and output filename
« Reply #1 on: May 22, 2006, 02:26:47 pm »
Sorry about the bad layout in my post, but I can't edit it.

Offline fili

  • Multiple posting newcomer
  • *
  • Posts: 15
  • Meow
Re: User template and output filename
« Reply #2 on: May 22, 2006, 03:58:06 pm »
I think that this is a bug in the nightly builds. At home I'm using RC2 and $(PROJECT_NAME) works as intended. At work I'm using the 20-may build and $(PROJECT_NAME) gets replaced by the project name as it was when the template was saved.
Have FUN,
FeeL E!

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: User template and output filename
« Reply #3 on: May 22, 2006, 04:32:41 pm »
console.cbp:
<?xml version="1.0"?>
<!DOCTYPE CodeBlocks_project_file>
<CodeBlocks_project_file>
   <FileVersion major="1" minor="1"/>
   <Project>
      <Option title="Console application"/>
      <Option makefile="Makefile"/>
      <Build>
         <Target title="default">
            <Option type="1"/>
            <Option parameters=""/>
            <Option includeInTargetAll="1"/>
            <Option projectCompilerOptionsRelation="3"/>
            <Option projectLinkerOptionsRelation="3"/>
            <Option projectIncludeDirsRelation="3"/>
            <Option projectLibDirsRelation="3"/>
            <Option output="bin\Release\$(PROJECT_NAME).exe" />
            <Compiler>
               <Add option=""/>
            </Compiler>
            <Linker>
               <Add option=""/>
            </Linker>
         </Target>
      </Build>
   </Project>
</CodeBlocks_project_file>


Result:



And the problem is...?
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Baz

  • Guest
Re: User template and output filename
« Reply #4 on: May 22, 2006, 04:50:22 pm »
@Thomas
Clearly no problem at all for you, but for me, the name of the template is used as the .exe file name.

Let's say my template has "<Option title="Monkey/>" If I create a project from the user template (Monkey) and rename the project at the rename dialog to "Tiger", when I compile the project I get Monkey.exe and not Tiger.exe. Incidently, if the template title has a space in it like in your example, then I get a link error. For example, if my template is called Win32 Application, then when I complile the project I will get a link error along the lines of "Error loading Application.exe".

I know this isn't happening in your example, but it really is happening to me, honest, I'm not making it up.

Many thanks.

Offline fili

  • Multiple posting newcomer
  • *
  • Posts: 15
  • Meow
Re: User template and output filename
« Reply #5 on: May 22, 2006, 05:11:27 pm »
1. Create a new console app (using the wizard), modify it's output target, compile, test, save as a project template (mine is 1234). Works fine, outputs 1234.exe.
2. Create a new app (using the 1234 template), check it's output target, compile.
3. Altough the project name is hahaha
4. the compiled file is still 1234.exe instead of hahaha.exe
That's the problem.

(I repeat, I'm using the nightly build. In RC2 works, as I can remember. I'll check when I get home)

[attachment deleted by admin]
Have FUN,
FeeL E!

Baz

  • Guest
Re: User template and output filename
« Reply #6 on: May 22, 2006, 05:39:32 pm »
@fili
That's exactly right.

I've just been experimenting with this and found something strange. I now have 2 .exe files. One with the template name and one with the project name. It seems that if you open Project -> build options, close it, and then re-compile, the proper named exe is created. Anyway, it looks like a bug to me and at least Thomas knows about it now.

Thanks all.

sethjackson

  • Guest
Re: User template and output filename
« Reply #7 on: May 22, 2006, 05:59:28 pm »
Yeah I can confirm it. The problem is that when you save a project as a template, the output filename is hardcoded into the project file. So no matter if you change the project name the output filename is not getting updated..... I really don't have a good understanding of cbProject/how to fix this bug or I would try to fix it myself. If anyone wants to know the problem is in templatemanager.cpp NewProjectFromUserTemplate(). Well actually the best way would probably be to fix SaveUserTemplate() so that the output filename isn't hardcoded.

Offline fili

  • Multiple posting newcomer
  • *
  • Posts: 15
  • Meow
Re: User template and output filename
« Reply #8 on: May 22, 2006, 08:10:30 pm »
I don't think it's something hardcoded. It seems to be a memory leak, because if you restart C::B and create a new project using the same template, everything works. Therefore, I think that something remains in the memory after saving the template.
Have FUN,
FeeL E!