User forums > Using Code::Blocks

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

(1/3) > >>

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:
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.

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.
 

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.

Navigation

[0] Message Index

[#] Next page

Go to full version