Author Topic: How does C::B compile C code when you don't actually specifcy its location?  (Read 2178 times)

Offline FEA

  • Multiple posting newcomer
  • *
  • Posts: 23
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.

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7178
    • My Best Post
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

Tim S.
« Last Edit: February 04, 2021, 07:58:50 am by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline FEA

  • Multiple posting newcomer
  • *
  • Posts: 23
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

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7178
    • My Best Post
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++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13438
    • Travis build status
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!]

Offline benkenobi01

  • Multiple posting newcomer
  • *
  • Posts: 61
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.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13438
    • Travis build status
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!]

Offline FEA

  • Multiple posting newcomer
  • *
  • Posts: 23
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?

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13438
    • Travis build status
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!]

Offline FEA

  • Multiple posting newcomer
  • *
  • Posts: 23
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.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13438
    • Travis build status
Re: How does C::B compile C code when you don't actually specifcy its location?
« Reply #10 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 :)
(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!]

Offline benkenobi01

  • Multiple posting newcomer
  • *
  • Posts: 61
Re: How does C::B compile C code when you don't actually specifcy its location?
« Reply #11 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 ?

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7178
    • My Best Post
Re: How does C::B compile C code when you don't actually specifcy its location?
« Reply #12 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.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org