Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: FEA on February 04, 2021, 02:30:24 am

Title: How does C::B compile C code when you don't actually specifcy its location?
Post by: FEA on February 04, 2021, 02:30:24 am
This is for a project that was originally all Fortran code. However, we recently added some C code.

Under Settings/Compiler/GNU Fortran Compiler (as a dropdown)/Toolchain Executables...the path to gfortran.exe is specified.

This is where it gets confusing. There is no Fortran listed in "Program Files" so I have just been using gfortran.exe for the first 3. This seems to override the label of C, C++, linker for dynamic libs. But what happens when you want to use both C and Fortran? Oddly, enough if I put gfortran.exe in all 3 it works (and seemingly compiles the C code). So maybe the dependency is more on the path than the EXE itself? The path does have a C compiler.
Title: Re: How does C::B compile C code when you don't actually specifcy its location?
Post by: stahta01 on February 04, 2021, 07:45:44 am
Please look at the build log and maybe you can answer the question.

http://wiki.codeblocks.org/index.php/FAQ-Compiling_(errors)#Q:_How_do_I_troubleshoot_a_compiler_problem.3F (http://wiki.codeblocks.org/index.php/FAQ-Compiling_(errors)#Q:_How_do_I_troubleshoot_a_compiler_problem.3F)

Tim S.
Title: Re: How does C::B compile C code when you don't actually specifcy its location?
Post by: FEA on February 04, 2021, 08:35:51 am
Thanks...that does seem to help, but I don't understand it since both seem to use gfortran.exe. How can the C file use fortran.exe?

Here is the line for a FORTAN file:
gfortran.exe -Jobj\Release\ -Wall -O2 -I..\..\A\INCLUDE -c C:\A\Interfaces\LINK5_Interface.f90 -o obj\Release\A\Interfaces\LINK5_Interface.o

Here is the line for a C file:
gfortran.exe -Jobj\Release\ -Wall -O2 -I..\..\A\INCLUDE -c C:\A\SuperLU\c_fortran_dgssv.c -o obj\Release\A\SuperLU\c_fortran_dgssv.o
Title: Re: How does C::B compile C code when you don't actually specifcy its location?
Post by: stahta01 on February 04, 2021, 12:32:48 pm
gcc and g++ are just compiler drivers; they call the real compilers that are likely named cc1plus and cc1.
gfortran likely calls cc1 for "c" code compiling.

Tim S.
 
Title: Re: How does C::B compile C code when you don't actually specifcy its location?
Post by: oBFusCATed on February 04, 2021, 12:59:37 pm
If you want to use the C/C++ compilers to build Fortran/C/C++ projects you'll need to set up separate targets for separate languages. Build all the c/c++ code as a static library and link it with the final fortran executable or do the opposite - fortran code in a lib, c/c++ executable.

This is currently the cleanest way to do it, I think.

Ideally someone could expand the build system to support this case, but it is probably a lot of work and probably it won't happen in the near future.
The final link might be complex to handle automatically correctly. For example if you mix c and c++ you need to use g++ for linking. If you don't do it you'll have linking errors, because c++ requires linking its runtime and the c linker doesn't do it. No idea if fortran has its own runtime and how do you use it with the c/c++ linker wrappers.
Title: Re: How does C::B compile C code when you don't actually specifcy its location?
Post by: benkenobi01 on February 04, 2021, 01:33:14 pm
You should do this with gcc and its Fortran version but not with an IDE like Codeblocks, using an IDE will just messed up everything.
Title: Re: How does C::B compile C code when you don't actually specifcy its location?
Post by: oBFusCATed on February 04, 2021, 02:08:30 pm
benkenobi01: What are you talking about? You're not providing a solution as far as I can see. The IDE is a tool. If the tool can do the job and saves you time you should use it. IDEs are not magick either.
Title: Re: How does C::B compile C code when you don't actually specifcy its location?
Post by: FEA on February 04, 2021, 05:19:09 pm
The thing is that it compiles OK and the resulting EXE passes benchmark testing for known outputs from the EXE. So it must be working even though I don't understand why. It seems stahta01's thought might be correct?
Title: Re: How does C::B compile C code when you don't actually specifcy its location?
Post by: oBFusCATed on February 04, 2021, 05:30:58 pm
Most probably it is. GCC uses the file extension to detect the source language. The answer is in the documentation of gfortran most probably, I doubt you'll find it here.
Title: Re: How does C::B compile C code when you don't actually specifcy its location?
Post by: FEA on February 04, 2021, 06:18:28 pm
Sounds good. I will accept that. I just wanted a few opinions about things. But since there is as a likely reason for this, and everything checks in the end, I am satisfied nothing is "incorrect" at least. Thanks.
Title: Re: How does C::B compile C code when you don't actually specifcy its location?
Post by: oBFusCATed on February 04, 2021, 08:32:47 pm
This is another way to look at it - assume that it works if there are no signs it doesn't :)
Title: Re: How does C::B compile C code when you don't actually specifcy its location?
Post by: benkenobi01 on February 05, 2021, 08:08:41 am
they call the real compilers that are likely named cc1plus and cc1.
Do you know their actual real name ?
Title: Re: How does C::B compile C code when you don't actually specifcy its location?
Post by: stahta01 on February 05, 2021, 01:28:48 pm
they call the real compilers that are likely named cc1plus and cc1.
Do you know their actual real name ?

On my GCC compiler toolchain it is cc1.exe for C and cc1plus.exe for C++.

Tim S.