Unable to compile .f (fortran file) in codeblocks 13.12 - fortran

I am trying to execute give fortran code in Code::Blocks on Windows 8
program main
write (*,*) "hi"
stop
end
The error I am getting is
G:\Study\Programs\bairstow.o:bairstow.f undefined reference to `_gfortran_st_write'
G:\Study\Programs\bairstow.o:bairstow.f undefined reference to `_gfortran_transfer_character_write'
G:\Study\Programs\bairstow.o:bairstow.f undefined reference to `_gfortran_st_write_done'
G:\Study\Programs\bairstow.o:bairstow.f undefined reference to `_gfortran_stop_string'
G:\Study\Programs\bairstow.o:bairstow.f undefined reference to `_gfortran_set_args'
G:\Study\Programs\bairstow.o:bairstow.f undefined reference to `_gfortran_set_options'
=== Build failed: 6 error(s), 0 warning(s) (0 minute(s), 1 second(s)) ===
I copy pasted the .f file in the folder of the compiler itself and executed the command
gfortran.exe hello.f
The output .exe file is successfully generated and executed.
I am not sure if I have setup the compiler properly in C::B. What I might be missing?
UPDATE :
As suggested by janneb, I added the linker library path so as to use libgfortran-3.dll.
The file gets compiled successfully with the following build log :
mingw32-g++.exe -c G:\Study\Programs\bairstow.f -o G:\Study\Programs\bairstow.o
mingw32-g++.exe -o G:\Study\Programs\bairstow.exe G:\Study\Programs\bairstow.o "C:\Program Files (x86)\CodeBlocks\MinGW\bin\libgfortran-3.dll"
Process terminated with status 0 (0 minute(s), 1 second(s))
0 error(s), 0 warning(s) (0 minute(s), 1 second(s))
When I execute the file, after waiting for about 2 minutes, I get the following error:
Have I made any mistake in linking the library file?
Hint : It has messed up with my GNU C Compiler also. Now even after unlinking the libgfortran-3.dll, I can't execute a simple helloWorld.c program.

Open C::B IDE and Go to "Settings" and Select "GNU Fortran Compiler" From Selected Compiler and Clik the button "Set as default" and finally click "Ok"

Based on the error message you're not linking the GFortran runtime library (libgfortran) when compiling via C::B. The gfortran.exe driver program automatically handles this, so most likely you're compiling with gcc.exe, which based on the file extension can invoke the Fortran compiler (f951), but doesn't do the linking stuff that gfortran.exe does.
Anyway, I have never used C::B nor gfortran on Windows, but hopefully the above explanation gives you a hint where to start looking.

In my case I had to do an additional step. Go to Project->Build options-> select the GNU Fortran Compiler as well.

Related

Codeblocks doesn't support glfw3?

I'm learning opengl and wanted to use Codeblocks IDE because visual studio seems too laggy and slow. After starting a console application project i've tried to link GLFW3 library to make this code run:
#include <GLFW/glfw3.h>
#include <thread>
int main()
{
glfwInit();
std::this_thread::sleep_for(std::chrono::seconds(1));
glfwTerminate();
}
I use GNU GCC 32-bit Compiler from MinGW(one that comes with codeblocks installation). I'm pretty certain that i've done everything correctly, i've read through like every article that i was able to find explaining how to setup codeblocks for opengl. I've linked libglfw3.a and libglfw3dll.a and set up correct search directories for compiler and linker but i always get this undefined reference error no matter what:
-------------- Build: Debug in glfw_again_test (compiler: GNU GCC Compiler)---------------
g++.exe -L"C:\Program Files\CodeBlocks\MinGW\lib" -o bin\Debug\glfw_again_test.exe obj\Debug\main.o "C:\Program Files\CodeBlocks\MinGW\lib\libglfw3.a" "C:\Program Files\CodeBlocks\MinGW\lib\libglfw3dll.a" "C:\Program Files\CodeBlocks\MinGW\x86_64-w64-mingw32\lib\libopengl32.a"
obj\Debug\main.o: In function `main':
C:/dev/OpenGL/CodeBlocks/glfw_again_test/main.cpp:6: undefined reference to `glfwInit'
C:/dev/OpenGL/CodeBlocks/glfw_again_test/main.cpp:8: undefined reference to `glfwTerminate'
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 1 second(s))
3 error(s), 0 warning(s) (0 minute(s), 1 second(s))
I have no idea what else i could try to fix this problem.
Apparently i was mistaken and thought that i use 32-bit MinGW compiler but seems like i accidentally installed 64-bit one with codeblocks. After switching to mingw gcc 32-bit compiler and rebuilding(simple build will lead to an error) my project i finally got it to work(not exactly this code snippet but another sample one).

C++ can't compile when I use iostream (Linux, CodeBlocks)

I want to use C++ Code in Java. I know I have to use JNI. And now I want to compile a shared library in C++ on Linux. I using the Code::Blocks 16.01 IDE and the GNU GCC Compiler.
And now I want to compile this very simple code:
#include <iostream>
void sayHello ()
{
std::cout << "Hello from C++" << std::endl;
}
(I know that I also have to include some more to use this library later in java, but this was just my first test, if it compiles)
The Build log is:
g++ -shared obj/Debug/main.o -o bin/Debug/libnativetest.so
/usr/bin/ld: obj/Debug/main.o: Die Umlagerung von
obj/Debug/main.o: error adding symbols: Ungültiger Wert
collect2: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 0 second(s))
1 error(s), 0 warning(s) (0 minute(s), 0 second(s))
The Build messages:
||error: ld returned 1 exit status|
||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
When I just compile the method without#include <iostream> (and sure without cout) it works.
I have tested with another header file like #include <string> and this works.
When I create a project not as a shared library instead a Console Application I can use <iostream>.
I am new to C++ and Code::Blocks therefore if you need some more info please help me where I can find this information.
I do not use Code blocks, so I have no idea how it decided to leave out the fPIC flag. If you try to build it on the command line with
g++ main.cpp -o main.o
The gcc (v5.4 in my case) prompts you to add -fPIC flag, with with the error disappears and the compilation succeeds. fPIC stands for position independent code. i.e., the function addresses (jump addresses) are not hard coded but are left blank. The loader, when it needs the .so, loads it to the memory and then fills the jump addresses dynamically. (-fpic could also work, it is for short jumps, whereas fPIC accommodates also long jumps, i.e., bigger jump ranges at the cost of binary size.)

[error]cannot find -lpthread collect2.exe: error: ld returned 1 exit status [duplicate]

I get a bizzare error after upgrading to MinGW 5.3.0-2(actual version)
I checked everything because It's the 5th time i reinstall it and thought it would help
Code::Blocks outputs this:
mingw32-g++.exe -Wall -fexceptions -g -c C:\Users\Tudor\Documents\C++\test\main.cpp -o obj\Debug\main.o
mingw32-g++.exe -o bin\Debug\test.exe obj\Debug\main.o
c:/mingw/bin/../lib/gcc/mingw32/5.3.0/../../../../mingw32/bin/ld.exe: cannot find -lpthread
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 0 second(s))
2 error(s), 0 warning(s) (0 minute(s), 0 second(s))
Note: if I check the -std=c++11 OR -std=c++14 flags i get output like here: Click me
Is it a problem with the last version of MinGW? If so where can I get the last working version? Or is anything in my computer messed up? I would like to keep this version if its possible to fix it but its getting me crazy
You haven't installed the Posix Threads (pthread) library, so the linker
can't find it. The particular Windows GCC packager that you have chosen doesn't
install it by default.
Start the MinGW Installation Manager and navigate All Packages -> MinGW
-> MinGW Standard Libraries. In the Standard Libraries presented, select
mingw32-pthreads-w32 dev. Then from the menubar select Installation -> Apply Changes
and proceed. Make it look like
Newer Windows GCC packagers, e.g. mingw-w64
or TDM-GCC, will install pthreads by default and
provide 64- as well as 32-bit compilers. mingw-w64 in addition offers more up-to-date
versions of GCC (currently 6.2, which is the latest GCC release).
If you use codeblocks-16.01-nosetup version or the earlier similar version then you need to install MinGW in home directory of C drive (C:\MinGW) and you have to add "C:\MinGW\bin" in the system variable called "Path".
However, I would recommend to use "codeblocks-16.01mingw-setup.exe" version of codeblocks. This has a preloaded MinGW latest version. you can get it from here: https://sourceforge.net/projects/codeblocks/files/Binaries/16.01/Windows/codeblocks-16.01mingw-setup.exe/download

CodeBlocks : [highlight: No such directory found

I have already read the other questions on the site and none of them matched with the issue I had.
I have already tried unistalling and then reinstalling codeblocks.
Please help.
Build Log :
mingw32-g++.exe -Wall -fexceptions -g -c S:\Coding\C++\aloo\main.cpp -o obj\Debug\main.o
mingw32-g++.exe -o bin\Debug\aloo.exe obj\Debug\main.o
[highlight color=”yellow”]-lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32[/highlight] "C:\Program Files (x86)\CodeBlocks\MinGW\lib\libbgi.a"
mingw32-g++.exe: error: [highlight: No such file or directory
mingw32-g++.exe: error: color=”yellow”]-lbgi: No such file or directory
mingw32-g++.exe: error: C:\Program Files (x86)\CodeBlocks\MinGW\lib\libbgi.a: No such file or directory
Process terminated with status 1 (0 minute(s), 4 second(s))
3 error(s), 0 warning(s) (0 minute(s), 4 second(s))
I have successfully solved the problem.
All I did was go to "Compiler Settings" ("Settings" -> "Compiler" -> Global compiler settings), and selected "Reset Defaults".
It solved the problem.
Thanks everyone for answering. :)
Start by turning on full Compiler logging.
This is done by selecting the "Full command line" option Under menu "Settings" -> "Compiler" -> Global compiler settings -> [the compiler you use] -> "Other Setting" tab, "Compiler logging". In 12.11 and newer this is enabled by default.
This option will make Code::Blocks output the exact commands it uses to compile your code.
Things to remember:
Look at the "Build Log" NOT the "Build Message" tab
Do a re-build instead of build in order to get a full build log.
You should review all the commands and their options;
If you have compiled your app before, do a re-build (or clean before build) to see all compiling / linking steps;
If you don't know what an option or a command does please read the documentation for the compiler/linker you're using;
Look for missing commands;
For every source file (.cpp; .c; .d; etc) in your project, you must have at least one command in the log. This command must produce an object file (file extension .o if using gcc/g++ and .obj if using Visual Studio);
Every object file should be linked in the final executable, if not there are undefined symbols errors;
Remember the file extension matters: *.c is compiled as C file, *.cpp is compiled as C++ file.
If you have no luck, you can try to ask in the forum, but read first "How do I report a compilation problem on the forums"
From Code::Blocks FAQ

gdk (gtk3) in codeblocks on windows 7

I have configured gtk3+ (I've changed gtk2+ to gtk3+) in codeblocks 13.2 on windows 7,
and created new gtk+ (exmaple) project. This example projcet was compiled and works properly.
Next I included gdk:
#include <gdk/gdk.h>
But when I added the lines:
gdk_init(&argc, &argv);
GdkScreen *screen = gdk_screen_get_default();`
I got 2 errors:
undefined referrence to 'gdk_init' and
undefined referrence to 'gdk_screen_get_default'
Where is the problem? I'm looking for a concrete solution.
compilation log:
||=== Build: Debug in gtk4test (compiler: GNU GCC Compiler) ===|
C:\myp\gtk4test\main.c||In function 'main':|
C:\myp\gtk4test\main.c|37|warning: 'gtk_vbox_new' is deprecated (declared at C:\gtk\include\gtk-3.0/gtk/deprecated/gtkvbox.h:60): Use 'gtk_box_new' instead [-Wdeprecated-declarations]|
C:\myp\gtk4test\main.c|53|warning: unused variable 'screen' [-Wunused-variable]|
obj\Debug\main.o||In function `main':|
C:\myp\gtk4test\main.c|52|undefined reference to `gdk_init'|
C:\myp\gtk4test\main.c|53|undefined reference to `gdk_screen_get_default'|
||=== Build failed: 2 error(s), 2 warning(s) (0 minute(s), 0 second(s)) ===|
If you have already called gtk_init, then you shouldn't call gdk_init (as gtk_init also calls it). Generally, you should just call the gdk functions.
If you need gdk_init() for some reason, you will have to add
gcc ... `pkg-config --libs --cflags gdk-3.0` ...
to the compilation line. Note that you probably also have to reconfigure your IDE to use gdk3 instead of gdk2.