User forums > Using Code::Blocks
mixed language (g++/g95) build setup
enalyen:
Hi, I have searched the site and read the following:
http://wiki.codeblocks.org/index.php?title=Installing_Fortran_Compiler
http://www.sci.brooklyn.cuny.edu/~goetz/codeblocks/
but I have not been able to resolve my issue.
I am trying to build a mixed language console application consisting of a main written in C++ (g++,gnu cygwin) and a subroutine written in fortran (g95, g95.org), but I have not been able to setup the project so that C::B compiles each file according to its native language and then links the objects using the g++ loader.
I am using Code::Blocks 10.05 on W2000, with both compilers running under a cygwin environment.
I was able to setup and run projects in either g++ or g95, but not in mixed mode. I have tried to (re)set the compiler selection for the fortran file that appears in the "Project" window pane, under the "Advanced" tab of the properties for the file, to no avail.
You can see from the log that C::B tries to perform the compilation for the fortran source with g++, not g95. How do you setup the project to select a compiler for each individual source file? or perform the compilation according to the known file extensions?
This is the log trace:
-------------- Build: Debug in fort ---------------
g++.exe -mno-cygwin -Wall -fexceptions -g -pg -g -v -IC:/cygwin/usr/X11R6/include -c "C:/Documents and Settings/brandap1/Desktop/C%C++/CB-progs/fort/main.cpp" -o obj/Debug/main.o
Reading specs from /usr/lib/gcc/i686-pc-mingw32/3.4.4/specs
Configured with: /usr/build/package/orig/test.respin/gcc-3.4.4-3/configure --verbose --prefix=/usr --exec-prefix=/usr --sysconfdir=/etc --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --enable-languages=c,ada,c++,d,f77,pascal,java,objc --enable-nls --without-included-gettext --enable-version-specific-runtime-libs --without-x --enable-libgcj --disable-java-awt --with-system-zlib --enable-interpreter --disable-libgcj-debug --enable-threads=posix --enable-java-gc=boehm --disable-win32-registry --enable-sjlj-exceptions --enable-hash-synchronization --enable-libstdcxx-debug
Thread model: posix
gcc version 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)
/usr/lib/gcc/i686-pc-mingw32/3.4.4/cc1plus.exe -quiet -v -IC:/cygwin/usr/X11R6/include
-D__MSVCRT__ -D__MINGW32__ -DWIN32 -D_WIN32 -D__WIN32 -D__WIN32__ -DWINNT -idirafter /usr/lib/gcc/i686-pc-mingw32/3.4.4/../../../../include/w32api
-idirafter /usr/lib/gcc/i686-pc-mingw32/3.4.4/../../../../i686-pc-mingw32/lib/../../include/w32api C:/Documents and Settings/brandap1/Desktop/C%C++/CB-progs/fort/main.cpp -quiet -dumpbase main.cpp
-mno-cygwin -mtune=pentiumpro -auxbase-strip
obj/Debug/main.o -g -g -Wall -version -p
-fexceptions -o /cygdrive/c/DOCUME~1/brandap1/LOCALS~1/Temp/ccs57jU7.s
ignoring nonexistent directory "/usr/local/include/mingw"
ignoring duplicate directory "/usr/include/mingw"
ignoring duplicate directory "/usr/lib/gcc/i686-pc-mingw32/3.4.4/../../../../i686-pc-mingw32/lib/../../include/w32api
"
#include "..." search starts here:
#include <...> search starts here:
C:/cygwin/usr/X11R6/include
/usr/lib/gcc/i686-pc-mingw32/3.4.4/include/c++
/usr/lib/gcc/i686-pc-mingw32/3.4.4/include/c++/i686-pc-mingw32
/usr/lib/gcc/i686-pc-mingw32/3.4.4/include/c++/backward
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include
/usr/lib/gcc/i686-pc-mingw32/3.4.4/../../../../i686-pc-mingw32/include
/usr/lib/gcc/i686-pc-mingw32/3.4.4/../../../../include/w32api
End of search list.
GNU C++ version 3.4.4 (cygming special, gdc 0.12, using dmd 0.125) (i686-pc-cygwin)
compiled by GNU C version 3.4.4 (cygming special, gdc 0.12, using dmd 0.125).
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
/usr/lib/gcc/i686-pc-mingw32/3.4.4/../../../../i686-pc-mingw32/bin/as.exe -o obj/Debug/main.o /cygdrive/c/DOCUME~1/brandap1/LOCALS~1/Temp/ccs57jU7.s
g++.exe -mno-cygwin -Wall -fexceptions -g -pg -g -v -IC:/cygwin/usr/X11R6/include -c "C:/Documents and Settings/brandap1/Desktop/C%C++/CB-progs/fort/fort.f95" -o obj/Debug/fort.o
Reading specs from /usr/lib/gcc/i686-pc-mingw32/3.4.4/specs
Configured with: /usr/build/package/orig/test.respin/gcc-3.4.4-3/configure --verbose --prefix=/usr --exec-prefix=/usr --sysconfdir=/etc --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --enable-languages=c,ada,c++,d,f77,pascal,java,objc --enable-nls --without-included-gettext --enable-version-specific-runtime-libs --without-x --enable-libgcj --disable-java-awt --with-system-zlib --enable-interpreter --disable-libgcj-debug --enable-threads=posix --enable-java-gc=boehm --disable-win32-registry --enable-sjlj-exceptions --enable-hash-synchronization --enable-libstdcxx-debug
Thread model: posix
gcc version 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)
g++: C:/Documents and Settings/brandap1/Desktop/C%C++/CB-progs/fort/fort.f95: linker input file unused because linking not done
g++.exe -LC:/cygwin/X11R6/lib -o bin/Debug/fort.exe obj/Debug/main.o obj/Debug/fort.o -pg -lgmon -v
Reading specs from /usr/lib/gcc/i686-pc-cygwin/3.4.4/specs
Configured with: /usr/build/package/orig/test.respin/gcc-3.4.4-3/configure --verbose --prefix=/usr --exec-prefix=/usr --sysconfdir=/etc --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --enable-languages=c,ada,c++,d,f77,pascal,java,objc --enable-nls --without-included-gettext --enable-version-specific-runtime-libs --without-x --enable-libgcj --disable-java-awt --with-system-zlib --enable-interpreter --disable-libgcj-debug --enable-threads=posix --enable-java-gc=boehm --disable-win32-registry --enable-sjlj-exceptions --enable-hash-synchronization --enable-libstdcxx-debug
Thread model: posix
gcc version 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)
/usr/lib/gcc/i686-pc-cygwin/3.4.4/collect2.exe -Bdynamic
--dll-search-prefix=cyg -o bin/Debug/fort.exe /usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../crt0.o /usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../gcrt0.o -LC:/cygwin/X11R6/lib
-L/usr/lib/gcc/i686-pc-cygwin/3.4.4 -L/usr/lib/gcc/i686-pc-cygwin/3.4.4 -L/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../..
obj/Debug/main.o obj/Debug/fort.o -lgmon -lstdc++ -lgcc -lgmon -lcygwin -luser32 -lkernel32 -ladvapi32 -lshell32 -lgcc
obj/Debug/main.o: In function `main':
C:/Documents and Settings/brandap1/Desktop/C%C++/CB-progs/fort/main.cpp:18: undefined reference to `_fort_main__'
obj/Debug/fort.o: In function `MAIN_':
C:/Documents and Settings/brandap1/Desktop/C%C++/CB-progs/fort/fort.f95:3: undefined reference to `__g95_get_ioparm'
C:/Documents and Settings/brandap1/Desktop/C%C++/CB-progs/fort/fort.f95:3: undefined reference to `__g95_filename'
C:
/Documents and
Settings/brandap1/Desktop/
C%C++/
CB-progs/fort/fort.f95:3: undefined reference to `__g95_line'
C:/Documents and Settings/brandap1/Desktop/C%C++/CB-progs/fort/fort.f95:3: undefined reference to `__g95_ioparm'
C:/Documents and Settings/brandap1/Desktop/C%C++/CB-progs/fort/fort.f95:3: undefined reference to `__g95_ioparm'
C:/Documents and Settings/brandap1/Desktop/C%C++/CB-progs/fort/fort.f95:3: undefined reference to `__g95_ioparm'
C:/Documents and Settings/brandap1/Desktop/C
%C+
+/CB-progs/
fort/fort.f95:3:
undefined reference to
`__g95_st_write'
C
:/Documents and
Settings/brandap1/Desktop/
C%C++/
CB-progs/fort/
fort.f95:3: undefined
reference to `
__g95_transfer_character'
C:/Documents and Settings/brandap1/Desktop/C%C++/CB-progs/fort/fort.f95:3: undefined reference to `__g95_st_write_done'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 3 seconds)
9 errors, 0 warnings
++++++++++++++++++++++++++++++++++++++++++++++++++++++
This is what I would use from the command line:
g95 -g -mno-cygwin -o gfort.o -c fort.f95
g++ -g -mno-cygwin -o gmain.o -c main.cpp
g++ -g -mno-cygwin -o ga.exe gmain.o gfort.o -L/usr/lib/gcc/ -L/lib/ -L/usr/local/lib/gcc-lib/i686-pc-mingw32/4.0.3/ -lf95
and these are the sources:
===================== main.cpp
#include <iostream>
using namespace std;
extern "C" {
void __cdecl fort_main__(int&,double&,double(&)[5],double(&)[2][3]);
}
int main()
{
int i=1;
double d=2.0;
double darr[]={1.,2.,3.,4.,5.};
double ddarr[][3]={{11.,22.,33.},{44.,55.,66.}};
cout << "Hello world!" << endl;
fort_main__(i,d,darr,ddarr);
return 0;
}
===================== fort.f95
subroutine fort_main(inte,dobl,darr,ddarr)
integer inte
double precision dobl
double precision darr(*)
double precision ddarr(3,*)
print*, " ok"
print*, inte, " <-inte"
print*, dobl, " <-dobl"
print*, darr(3), " <-darr(3)"
print*, ddarr(2,2),"<-ddarr(2,2)"
print*, ddarr(3,1),"<-ddarr(3,1)"
return
end
============================
Thanks!
xunxun:
You should link g95 lib, but I only use gfortran, and that should be linked with libgfortran.a...
enalyen:
Just to clarify:
I can generate a build for a project that contains *all C++* sources (using g++), and/or a project that contains *all Fortran* sources (using g95). I can run/debug the built applications.
The problem occurs when I try to build a project that has *both* type of sources. I have not been able to setup the project to use the appropriate compiler for each source.
The closest information I could find to resolve this is in the manual (C::B V1.1, page 5) in chapter 1.9 where it illustrates how to "Include Assembler files". The default compiler for my project is CPP (g++), I can see my fortran source file under the "Project View" in the "Fortran Sources" category. I have right clicked on the fortran source and opened the "Properties" context menu with the intent of overriding the setting for the compiler under the "Advanced Tab" so that the compiler setting is changed to the Fortran compiler for that particular source.
I have tried a number of settings but the fortran source keeps being compiled with the C++ (default) compiler.
Is there a link to more information on how to properly setup the properties for that advanced tab menu (the one that says: "Please don't change anything unless you really know what. You could *really* mess-up Code::Blocks' build system").
If that's not available can anyone volunteer a simple project with some of the more advanced settings that are not documented in the manual?
Thank you.
oBFusCATed:
Why don't you pack your fortran object files in static library and use it while linking the executable?
enalyen:
I would like to debug applications that have mixed sources, my (limited) understanding is that the static library solution would defeat the purpose.
But so are you sayinig that C::B currently does not support mixed language builds?
Navigation
[0] Message Index
[#] Next page
Go to full version