Author Topic: Custom Makefile: How to build one module.obj from module.cpp ?  (Read 4313 times)

Offline JoJo

  • Single posting newcomer
  • *
  • Posts: 7
Hi, I am new to C::B and am tying to import a project with a custom Makefile.

When I have a source module like "module.cpp", the command to build the respective object file would be to issue "make module.obj". How can I get there?

As far as I can see, Project->Build Commands->Make command support

$make
$makefile
$target
$file

For the "Compile single file" I entered

"$make -f $makefile $file.obj"

But when I hit "Build file" for a source.cpp, C::B issues

g++ [options]  -c source.cpp -o obj/Debug/source.o

but nowhere in my Makefile there is such a thing like "obj/Debug", and the options are different from the ones used with "make source.obj". So C::B is still using its own build scheme even though I used custom Makefile.

If $file the correct command to get the basename (without path or extendion) of a file?

Please help me.
« Last Edit: April 25, 2023, 04:10:59 pm by JoJo »

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7699
    • My Best Post
Re: Custom Makefile: How to build one module.obj from module.cpp ?
« Reply #1 on: April 25, 2023, 06:23:08 pm »
Project -> Properties...

Tab: Project Setting
Is there a Checkmark on "This is an custom makefile"
What did you change the makefile name to?

Tim S.

C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline JoJo

  • Single posting newcomer
  • *
  • Posts: 7
Re: Custom Makefile: How to build one module.obj from module.cpp ?
« Reply #2 on: April 25, 2023, 06:28:07 pm »
> Is there a Checkmark on "This is an custom makefile"

Yes.

> What did you change the makefile name to?

Makefile is named "Makefile", I never changed that.

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7699
    • My Best Post
Re: Custom Makefile: How to build one module.obj from module.cpp ?
« Reply #3 on: April 25, 2023, 06:31:04 pm »
Post the full build log in code tags.
Edit: In your case build file results of the build log would likely be correct.

Tim S.
« Last Edit: April 25, 2023, 06:33:43 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7699
    • My Best Post
Re: Custom Makefile: How to build one module.obj from module.cpp ?
« Reply #4 on: April 25, 2023, 06:36:33 pm »
Is the Makefile and the CB Project file in the same folder?
If not, then I normally create an Makefile in the CB Project folder that calls the other makefile.

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7699
    • My Best Post
Re: Custom Makefile: How to build one module.obj from module.cpp ?
« Reply #5 on: April 25, 2023, 06:40:35 pm »
I just realized I have never used "build file" with an custom makefile it might or might not work correctly.

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline JoJo

  • Single posting newcomer
  • *
  • Posts: 7
Re: Custom Makefile: How to build one module.obj from module.cpp ?
« Reply #6 on: April 25, 2023, 08:37:06 pm »
Is the Makefile and the CB Project file in the same folder?

Yes. The Makefile already existed when I created the CB project file.

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7699
    • My Best Post
Re: Custom Makefile: How to build one module.obj from module.cpp ?
« Reply #7 on: April 26, 2023, 01:39:19 am »
I just visual traced the code and it looks to me that "Build file" does not use the custom makefile.

From compilergcc.cpp line 3133 current SVN
Code
return CompileFileDefault(m_pProject, pf, bt); // compile file using default build system

Edit: Adding the use of  "UseMake" call in compilergcc.cpp would be a partial fix; but, other than adding an error saying not supported I have no idea what to add without a lot more work.

Tim S.
« Last Edit: April 26, 2023, 01:56:18 am by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline JoJo

  • Single posting newcomer
  • *
  • Posts: 7
Re: Custom Makefile: How to build one module.obj from module.cpp ?
« Reply #8 on: April 28, 2023, 03:24:17 pm »
IMO, with a custom Makefile, it's hard or impossible to guess how that works, and it's likely you build wrong assumptions into C::B.

What I was expecting that there is some custom command that could be issued on "build file" etc., where I can provide a string that can be composed from parts like basename of the file, extension of the file, folder where the file is located, etc. C::B would then just issue that command.

Or if you allow to attach command to special keys like F7, where you provide file name, extension, etc.