Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: gib on July 07, 2017, 10:50:51 pm

Title: Compile a single file
Post by: gib on July 07, 2017, 10:50:51 pm
Is it possible in CB to compile a single file in the list of target files?  This can be done in Visual Studio.
Title: Re: Compile a single file
Post by: oBFusCATed on July 07, 2017, 11:36:55 pm
I'm not sure I understand the question. Can you try to describe it with more details?
Title: Re: Compile a single file
Post by: gib on July 08, 2017, 12:28:34 am
Say I have a project composed of several files.  Instead of building the target completely I want to test compilation only of a single file.  You might question why anyone would want to do this.  I have occasionally had reason to do this using VS, and I'm just wondering if it's possible in CB. 
Title: Re: Compile a single file
Post by: stahta01 on July 08, 2017, 12:47:58 am
Select the file you wish to compile in the Project Tab in the Management Window.

Right Click and choose "Build File"; you might need to do "Clean File" first.

Tim S.
 
Title: Re: Compile a single file
Post by: gib on July 08, 2017, 01:01:55 am
Thanks!  I feel pretty stupid not to have seen that.  I guess I was looking for 'compile', not 'build'.

There seems to be an issue with MinGW Fortran, though, in my CB version at any rate (13.12):

mingw32-gfortran.exe -J   -c D:\trophocell3D-abm\src\fmotion.f90 -o \src\fmotion.o
D:\trophocell3D-abm\src\fmotion.f90:4.4:
use global
    1
Fatal Error: File 'global.mod' opened at (1) is not a GFORTRAN module file

The file I am compiling uses module global, which does exist (obviously) - the target DLL builds OK.  Interestingly it finds global.mod but doesn't recognise it.  This not a problem, in any case.
Title: Re: Compile a single file
Post by: gib on July 08, 2017, 01:33:51 am
The error when I try to build a file that doesn't USE any modules is a strange one:

mingw32-gfortran.exe -J   -c D:\trophocell3D-abm\src\par_zig_mod.f90 -o \src\par_zig_mod.o
D:\trophocell3D-abm\src\par_zig_mod.f90:256.22:
END MODULE par_zig_mod
                      1
Fatal Error: Can't open module file '-c/par_zig_mod.mod0' for writing at (1): No such file or directory

This file defines a module.

<edit> The problem is that '-J' with nothing after it.  When I invoke the compile line at the command prompt there is a warning about "nonexistent include directory '-c'".  If I remove the '-J' it compiles.  This presumably has something to do with how cmake created the make files - this project was made with cmake.  Another reason to create a project in CB. :)
Title: Re: Compile a single file
Post by: gib on July 08, 2017, 02:17:13 am
Just to wrap this up: if the project was created within CB, 'Build file' for this project works exactly as you'd expect.