CodeBlocks not running code - codeblocks

I was trying to run a code in code Blocks but every time i try to build&run it the following message is displayed in the bottom of Program
-------------- Build: Debug in will it work (compiler: GNU GCC Compiler)---------------
g++ -Wall -fexceptions -g -c "/home/TwTOoth/Documents/will it work/main.cpp" -o obj/Debug/main.o
g++ -o "bin/Debug/will it work" obj/Debug/main.o
Output file is bin/Debug/will it work with size 28.28 KB
Process terminated with status 0 (0 minute(s), 0 second(s))
0 error(s), 0 warning(s) (0 minute(s), 0 second(s))
what seems to be the problem here?

According to your Build Log message, your build seems fine here.
If it was not the case, you would have a message like this at the end of the text:
Process terminated with status 1 (0 minutes, 0 seconds)
2 errors, 1 warnings (0 minutes, 0 seconds)
So if your build is fine, maybe this is your "run" which is not fine (or the content done for the output inside your implementation). Have you tried to do a "Build" then a "run" instead of "build & run"?

Related

How to have make fail on some warnings but not others

I have a make file that includes:
%.dat: %.txt
... PREPROCESSING OF TEXT FILE
tidy -o $*.html $<
... FURTHER PROCESSING
tidy produces lots of warnings that I can suppress with the flag --show-warnings false, but despite supressing the warnings, the exit status from tidy still 1 instead of 0, and so make fails part way through the recipe. How can I have make continue in the face of tidy giving exit status 1 while still allowing make to fail if any other recipe gives warnings?
I have looked at these two question (Have make fail if unit tests fail and gcc, make: how to disable fail on warning?) but neither seems to deal with this problem.
AFTER EDIT: In Make: how to continue after a command fails?, the question relates to how one gets make to continue after any non-zero exit status in executing a particular command, whereas in my case, I want an exit status of 2 from tidy indicating errors, to cause make to fail, but I want an exit status of 1 from tidy, indicating warningsto allowmake to continue`.
The simpliest solution:
tidy -o $*.html $< || true
So if tidy's exit code isn't zero the true produces zero exit code.
But check the tidy's exit codes:
Exit Status
0
All input files were processed successfully.
1
There were warnings.
2
There were errors.
Maybe you want skip only the error code 1. In this case:
tidy -o $*.html $< || [ $$? -eq 1 ] && true

NetBeans IDE Dev (Build 201804200002) "Build Failed"

I am trying to learn Fortran using the NetBeans IDE with the basic "Hello World" programming application. However, I keep getting "Build Failed". I don't know why? I have installed the MinGW. Then I configured the PATH in the Environment Variables. Finally, I installed NetBeans. This is what I programmed in NetBeans:
PRINT*, 'Hello World'
END
The following is the error and the history that I get:
cd 'C:\Users\ABCD\Documents\NetBeansProjects\CppApplication_1'
C:\MinGW\msys\1.0\bin\make.exe -f Makefile CONF=Debug
"/C/MinGW/msys/1.0/bin/make.exe" -f nbproject/Makefile-Debug.mk QMAKE=
SUBPROJECTS= .build-conf
make.exe[1]: Entering directory
`/c/Users/ABCD/Documents/NetBeansProjects/CppApplication_1'
"/C/MinGW/msys/1.0/bin/make.exe" -f nbproject/Makefile-Debug.mk
dist/Debug/MinGW-Windows/cppapplication_1.exe
make.exe[2]: Entering directory
`/c/Users/ABCD/Documents/NetBeansProjects/CppApplication_1'
mkdir -p build/Debug/MinGW-Windows
gfortran -c -g -o build/Debug/MinGW-Windows/testfortran.o
testfortran.f90
mkdir -p dist/Debug/MinGW-Windows
g++ -o dist/Debug/MinGW-Windows/cppapplication_1
build/Debug/MinGW-Windows/main.o
build/Debug/MinGW-Windows/testfortran.o
build/Debug/MinGW-Windows/testfortran.o: In function `main':
C:\Users\ABCD\Documents\NetBeansProjects\CppApplication_1/testfortran.f90:2:
multiple definition of `main'
build/Debug/MinGW-Windows/main.o:C:\Users\ABCD\Documents\NetBeansProjects\CppApplication_1/main.cpp:21:
first defined here
build/Debug/MinGW-Windows/testfortran.o: In function `MAIN__':
C:\Users\ABCD\Documents\NetBeansProjects\CppApplication_1/testfortran.f90:1:
undefined reference to `_gfortran_st_write'
C:\Users\ABCD\Documents\NetBeansProjects\CppApplication_1/testfortran.f90:1:
undefined reference to `_gfortran_transfer_character_write'
C:\Users\ABCD\Documents\NetBeansProjects\CppApplication_1/testfortran.f90:1:
undefined reference to `_gfortran_st_write_done'
build/Debug/MinGW-Windows/testfortran.o: In function `main':
C:\Users\ABCD\Documents\NetBeansProjects\CppApplication_1/testfortran.f90:2:
undefined reference to `_gfortran_set_args'
C:\Users\ABCD\Documents\NetBeansProjects\CppApplication_1/testfortran.f90:2:
undefined reference to `_gfortran_set_options'
collect2.exe: error: ld returned 1 exit status
make.exe[2]: *** [dist/Debug/MinGW-Windows/cppapplication_1.exe] Error
1
make.exe[2]: Leaving directory
`/c/Users/ABCD/Documents/NetBeansProjects/CppApplication_1'
make.exe[1]: *** [.build-conf] Error 2
make.exe[1]: Leaving directory
`/c/Users/ABCD/Documents/NetBeansProjects/CppApplication_1'
make.exe": *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 1s)
I am not understanding how do I fix it? I would appreciate any help as I am a beginner to the Fortran/C++ world.
I followed the video tutorial you linked to in your comment, and I got the same build errors. Two unrelated changes are needed to resolve them:
To resolve the multiple definition of 'main' error, see the accepted answer to the Stack Overflow question gfortran multiple definition of main. Just copy and paste the source for the C++ and Fortran examples into your project files.
Rebuild your project and the multiple definition of 'main' error should be gone.
However, that does not fix the undefined reference errors. The solution for that is on the (old) NetBeans web site:
So, in the Linker window we when we add the reference to the Fortran
library by bringing up the Libraries window one will notice an Add
Options button on this page....here is where we put the -lgfortran
option under Other Options. Presto, the C code will compile and
doesn't complain about missing Fortran references.
The specific steps needed to fix the undefined reference errors are:
In the Projects window select your project, right click and select Properties from the context menu to open the Project Properties window.
Select Build > Linker from the Categories list.
On the right side of the Project Properties window click the ... button for Libraries.
In the Debug - Libraries window click the Add Option... button.
In the Select Option window:
Click the Other Option radio button.
Enter -lgfortran in the text field and press OK.
Click OK to close Debug - Libraries window. You should now see the
-lgfortran option displayed in the Project Properties window:
Having made the changes described above the projects builds without errors:
cd 'D:\NB82\CppApplication_5'
C:\msys\1.0\bin\make.exe -f Makefile CONF=Debug clean
"/C/msys/1.0/bin/make.exe" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .clean-conf
make.exe[1]: Entering directory `/d/NB82/CppApplication_5'
rm -f -r build/Debug
rm -f *.mod
make.exe[1]: Leaving directory `/d/NB82/CppApplication_5'
CLEAN SUCCESSFUL (total time: 558ms)
cd 'D:\NB82\CppApplication_5'
C:\msys\1.0\bin\make.exe -f Makefile CONF=Debug
"/C/msys/1.0/bin/make.exe" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make.exe[1]: Entering directory `/d/NB82/CppApplication_5'
"/C/msys/1.0/bin/make.exe" -f nbproject/Makefile-Debug.mk dist/Debug/MinGW-Windows/cppapplication_5.exe
make.exe[2]: Entering directory `/d/NB82/CppApplication_5'
mkdir -p build/Debug/MinGW-Windows
rm -f "build/Debug/MinGW-Windows/main.o.d"
g++ -c -g -MMD -MP -MF "build/Debug/MinGW-Windows/main.o.d" -o build/Debug/MinGW-Windows/main.o main.cpp
mkdir -p build/Debug/MinGW-Windows
gfortran -c -g -Wall -o build/Debug/MinGW-Windows/newfortranFreeFormatFile.o newfortranFreeFormatFile.f90
mkdir -p dist/Debug/MinGW-Windows
g++ -o dist/Debug/MinGW-Windows/cppapplication_5 build/Debug/MinGW-Windows/main.o build/Debug/MinGW-Windows/newfortranFreeFormatFile.o -lgfortran
make.exe[2]: Leaving directory `/d/NB82/CppApplication_5'
make.exe[1]: Leaving directory `/d/NB82/CppApplication_5'
BUILD SUCCESSFUL (total time: 1s)
Running the Fortran project then produces the expected output:
main in C++
FortMain
RUN SUCCESSFUL (total time: 2s)
You have created a C++ project then a fortran file.
Your IDE created a main in c++ for you. I guess it havent in the tutorial you have seen.
If i have seen it right then the answer is simple:
Just right click and delete this main.c and you are good :-)

CodeBlocks will not stop at the breakpoint

I synaptic codeblocks on my PCLinux OS.
In the terminal, "su -"
entered root's password
In the terminal, "codeblocks"
Created a project from the template, "console" -Hello World.
++++++++++++++++++++++++++++++++++++++++
main.cpp:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world!" << endl;
return 0;
}
++++++++++++++++++++++++++++++++++++++
Two targets" Debug and release.
I build debug.
-------------- Build: Debug in consolesimple (compiler: GNU GCC Compiler)---------------
g++ -Wall -fexceptions -Wall -pg -g -I/usr/include/wx-2.8 -c /root/Documents/CodeBlocksSpace/consolesimple/main.cpp -o obj/Debug/main.o
g++ -o bin/Debug/consolesimple obj/Debug/main.o -pg
Output file is bin/Debug/consolesimple with size 20.87 KB
Process terminated with status 0 (0 minute(s), 0 second(s))
0 error(s), 0 warning(s) (0 minute(s), 0 second(s))
I set the breakpoint at cout line.
I press F8, debug start. But the debugger did not stop.
debug window:
Building to ensure sources are up-to-date
Selecting target:
Debug
Adding source dir: /root/Documents/CodeBlocksSpace/consolesimple/
Adding source dir: /root/Documents/CodeBlocksSpace/consolesimple/
Adding file: /root/Documents/CodeBlocksSpace/consolesimple/bin/Debug/consolesimple
Changing directory to: /root/Documents/CodeBlocksSpace/consolesimple/.
Set variable: LD_LIBRARY_PATH=.:
Starting debugger: /root/Documents/CodeBlocksSpace/consolesimple/bin/Debug/consolesimple -nx -fullname -quiet -args /root/Documents/CodeBlocksSpace/consolesimple/bin/Debug/consolesimple
done
Debugger finished with status 0
Can anybody help me why the debugger never stop at the breakpoint?
thanks.

Can't make OpenMP work with CodeBlocks and GFortran

For some reason, I cant make OpenMP work with CodeBlocks and GFortran. I tried another IDE (Geany) and it works properly, but with CodeBlocks it does not. I must say that I included the -fopenmp option in CodeBlocks.
Here is a simple code that I tested.
program test
implicit none
integer i
!$OMP PARALLEL DO DEFAULT(PRIVATE)
Do i=1,10
Write(*,*) i
end do
!$OMP END PARALLEL DO
end program test
And here is the build log:
-------------- Build: Debug in TEST (compiler: GNU Fortran Compiler)---------------
gfortran.exe -Jobj\Debug\ -Wall -g -fopenmp -c "C:\Users\tilter\Dropbox\Public\Code\Nova pasta\TEST\main.f95" -o obj\Debug\main.o
gfortran.exe -o bin\Debug\TEST.exe obj\Debug\main.o
obj\Debug\main.o: In function `test':
C:/Users/tilter/Dropbox/Public/Code/Nova pasta/TEST/main.f95:5: undefined reference to `GOMP_parallel_start'
C:/Users/tilter/Dropbox/Public/Code/Nova pasta/TEST/main.f95:5: undefined reference to `GOMP_parallel_end'
obj\Debug\main.o:C:/Users/tilter/Dropbox/Public/Code/Nova pasta/TEST/main.f95:6: undefined reference to `GOMP_parallel_start'
obj\Debug\main.o:C:/Users/tilter/Dropbox/Public/Code/Nova pasta/TEST/main.f95:6: undefined reference to `GOMP_parallel_end'
obj\Debug\main.o:C:/Users/tilter/Dropbox/Public/Code/Nova pasta/TEST/main.f95:8: undefined reference to `omp_get_num_threads'
obj\Debug\main.o:C:/Users/tilter/Dropbox/Public/Code/Nova pasta/TEST/main.f95:8: undefined reference to `omp_get_thread_num'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 0 seconds)
6 errors, 0 warnings (0 minutes, 0 seconds)
I don't know what I'm missing here...
I just restarted Windows 7 and it fixed the problem.

Can gcc return a value?

How can I know the return value of gcc?
For example, I have one c file, test.c, and I simply run gcc test.c in terminal. It can report if current compile meet some errors, but how can I know the return value of this time compile process of gcc?
Now I know 1 means has error, but 0 will return not only warning but also compile OK, how can I if there is error. If I use -Werror, it may stop compile, I don't want to stop compile
The return variable is in the shell variable $?.
> gcc bla.c
> echo $?
0
Edit: on windows it is in %errorlevel%.

Resources