News:

The new Release 25.03 is out! You can download binaries for Windows and many major Linux distros here .

Main Menu

How does C::B compile C code when you don't actually specifcy its location?

Started by FEA, February 04, 2021, 02:30:24 AM

Previous topic - Next topic

FEA

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.

stahta01

C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]

FEA

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

stahta01

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.
C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]

oBFusCATed

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.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

oBFusCATed

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.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

FEA

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?

oBFusCATed

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.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

FEA

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.

oBFusCATed

This is another way to look at it - assume that it works if there are no signs it doesn't :)
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

stahta01

Quote from: benkenobi01 on February 05, 2021, 08:08:41 AM
Quote from: stahta01 on February 04, 2021, 12:32: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.
C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]