NetBeans IDE Dev (Build 201804200002) "Build Failed" - gcc

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

Related

Unable to link ".so" shared library to main ".c" file while compiling

I am trying to make a shared library for a particular problem I was working on. It has "point_sense.c" as the main file which uses functions defined in "createPolygon.c." The functions are declared in a header file "createPolygon.h."
To compile them, I used a makefile which looks like the following
all:point_sense
createPolygon.o:createPolygon.c
g++ -c -fpic createPolygon.c
libcreatePolygon.so:createPolygon.o
g++ -shared -o libcreatePolygon.so createPolygon.o
point_sense:point_sense.c libcreatePolygon.so
g++ -o point_sense -L~Desktop/Summer_2020_linux/tutorials/cpp_practise point_sense.c -lcreatePolygon
clean:
rm point_sense createPolygon.o libcreatePolygon.so
but when I make the file, it gives an output as
g++ -c -fpic createPolygon.c
g++ -shared -o libcreatePolygon.so createPolygon.o
g++ -o point_sense -L~Desktop/Summer_2020_linux/tutorials/cpp_practise point_sense.c -lcreatePolygon
/usr/bin/ld: cannot find -lcreatePolygon
collect2: error: ld returned 1 exit status
make: *** [makefile:10: point_sense] Error 1
Initially I thought this was some silly mistake, and to check I used
ld -L~/Desktop/Summer_2020_linux/tutorials/cpp_practise -lcreatePolygon -verbose
and after a long output I got (a few unimportant lines in the code are skipped in between)
ld: mode elf_x86_64
attempt to open ~/Desktop/Summer_2020_linux/tutorials/cpp_practise/libcreatePolygon.so failed
attempt to open ~/Desktop/Summer_2020_linux/tutorials/cpp_practise/libcreatePolygon.a failed
attempt to open /usr/local/lib/x86_64-linux-gnu/libcreatePolygon.so failed
attempt to open /usr/local/lib/x86_64-linux-gnu/libcreatePolygon.a failed
.
.
.
ld: cannot find -lcreatePolygon
But when I try to open 'libcreatePolygon.so' directly, I am able to open it.
$ nano ~/Desktop/Summer_2020_linux/tutorials/cpp_practise/libcreatePolygon.so
There are several threads which explain the process of doing this, but I don't see what it is that I am doing wrong. Any help is appreciated.
I am using Ubuntu 20.04.1 LTS and g++ (Ubuntu 9.3.0-10ubuntu2) 9.3.0 .
I tried to reproduce the problem here, and this error message goes away if you put a space between the -L flag and the tilde character.
The reason is: if there is no space between -L and ~, the tilde character cannot be expanded to the home directory.

How to crosscompile all sources from a directory using gcc-linaro (Windows 10)

I'm running into a problem trying to write a Makefile for cross compilation for a Beaglebone. I'm using gcc-linaro 7.5.0 on a Windows 10 machine.
The problem occurs when I try to put all sources from the directory into a variable for later use.
SRCDIR = $(CURDIR)\source
SRCS := $(wildcard $(SRCDIR)\*.cpp
This and this have previously been posted and this solution has been accepted, however, I cannot seem to get it to work. This line #echo $(SRCS) gives me ECHO is off which makes me assume that I'm doing something wrong because $(SRCS) seems to be empty, hence the message(?) (source folder exists and it is not empty)
Then when the linker is called I get a message possibly also indicating that the directory seems to be empty which it is not.
"D:\UserData\User\DEV\gcc-linaro-7.5.0-2019.12-i686-mingw32_arm-linux-gnueabihf\bin\arm-linux-gnueabihf-g++.exe" -o hellobone -marm -O0 -g -I. -ID:\UserData\User\DEV\hellobone\include
arm-linux-gnueabihf-g++.exe: fatal error: no input files
compilation terminated.
make: *** [hellobone] Fehler 1

Excecuting make is creating object file in wrong folder

I am new to ubuntu and hence to make file. I have successfully created make file with folder structure. However, if I add the similar structure, I get an error.
I successfully executed make command and ran application with one main cpp file and two files (list_menu.cpp and list_menu.h ) in sub folder cpp11_and_cpp14_menu
folder structure looks exactly like below where cpp11_and_cpp14.cpp has the main function.
../advancedcppproject/
cpp11_and_cpp14.cpp
Makefile
../advancedcppproject/cpp11_and_cpp14_menu
list_menu.cpp
list_menu.h
../advancedcppproject/multi_threading_example
multi_threading.cpp
multi_threading.h
Make file contents are
cpp11_and_cpp14 : cpp11_and_cpp14.o ./multi_threading_example/multi_threading.o ./cpp11_and_cpp14_menu/list_menu.o
g++ cpp11_and_cpp14.o ./multi_threading_example/multi_threading.o ./cpp11_and_cpp14_menu/list_menu.o -o cpp11_and_cpp14
cpp11_and_cpp14.o : cpp11_and_cpp14.cpp ./cpp11_and_cpp14_menu/list_menu.h ./multi_threading_example/multi_threading.h
g++ -c cpp11_and_cpp14.cpp
./cpp11_and_cpp14_menu/list_menu.0 : ./cpp11_and_cpp14_menu/list_menu.cpp ./cpp11_and_cpp14_menu/list_menu.h
g++ -c ./cpp11_and_cpp14_menu/list_menu.cpp
./multi_threading_example/multi_threading.o : ./multi_threading_example/multi_threading.cpp ./multi_threading_example/multi_threading.h
g++ -c ./multi_threading_example/multi_threading.cpp
After executing make command, it fails with an error message
g++ -c ./multi_threading_example/multi_threading.cpp
g++ cpp11_and_cpp14.o ./multi_threading_example/multi_threading.o ./cpp11_and_cpp14_menu/list_menu.o -o cpp11_and_cpp14
g++: error: ./multi_threading_example/multi_threading.o: No such file or directory
Makefile:6: recipe for target 'cpp11_and_cpp14' failed
make: *** [cpp11_and_cpp14] Error 1
I expect multi_threading.o to be created under folder ../advancedcppproject/multi_threading_example. However multi_threading.o is created under ../advancedcppproject.
Where as list_menu.o is correctly created under ../advancedcppproject/cpp11_and_cpp14_menu.
What is wrong?

Automatically create .OBJDIR subdirectories

OS: FreeBSD 11.0-RELEASE
I have the following directory structure:
/xxx/obj/
/xxx/src/deep.cpp
/xxx/flat.cpp
/xxx/makefile
The content of makefile is as follows:
flat.out: flat.o
deep.out: src/deep.o
I have no problem building flat:
/xxx $ make flat.out
c++ -O2 -pipe -c /xxx/flat.cpp -o flat.o
cc -O2 -pipe flat.o -o flat.out
/xxx $ ls obj
flat.o flat.out
But when I try to build deep it fails:
/xxx $ make deep.out
c++ -O2 -pipe -c /xxx/src/deep.cpp -o src/deep.o
error: unable to open output file 'src/deep.o': 'No such file or directory'
1 error generated.
*** Error code 1
Stop.
make: stopped in /xxx
If I then create /xxx/obj/src manually it succeeds:
/xxx $ mkdir obj/src
/xxx $ make deep.out
c++ -O2 -pipe -c /xxx/src/deep.cpp -o src/deep.o
cc -O2 -pipe src/deep.o -o deep.out
/xxx $ ls obj
deep.out flat.o flat.out src
/xxx $ ls obj/src
deep.o
According to this source bmake (aka bsdmake?) supports automatic creation of out-of-source OBJDIRs, but I cannot figure out how exactly.
How do I configure bmake to create the relevant directories automatically, in the general case?
Automatic creation of out-of-source OBJDIRs is supported but not in the sense you seem to expect it. Creation of out-of-source OBJDIRs can be implemented with bmake(1) directives but is not supported by the bmake(1) program itself. That said,
If you use bmake(1) directives shipped with FreeBSD to build your project, then the creation of OBJDIRs is supported and implemented by the obj target, so that the command make obj will create the OBJDIRs. See the file bsd.obj.mk for further documentation and implementation details. FreeBSD sources contain a lot of examples of programs using these directives to build.
If you use bmake(1) directives shipped as the (portable) bsdowl package, then the creation of OBJDIRs is supported and implemented by the target obj so that the command make obj or the command make preparatives using a more general target will create the OBJDIRs. The example directory contains several C-based examples showing how to prepare your Makefiles to build your project with the bsdowl package.
If you use custom bmake(1) directives, then you will have to implement a target taking care of this creation yourself. The file bsd.obj.mk is definitely a good source to get started with this.
An important point to note, is that bmake(1) determines its actual working directory before processing any targets, which means that it is almost always the right thing to do to execute the target requesting the creation of OBJDIRs on its own. Because of this, the command bmake obj all from your example would fail with the same error message you reported above. The correct invocation would instead be bmake obj && bmake all, since the second bmake(1) process has now the chance to change to the OBJDIR created by the previous run.

\mingw32\bin\ld.exe: cannot find -lC:/msys/1.0/opt/tcl/lib

I am attempting to compile a simulator for Y86 code (http://csapp.cs.cmu.edu/public/sim.tar) on Windows using mingw and msys, the simulator uses Tcl and Tk for a GUI that it has, so I first tried downloading the needed includes and libs for Tcl and Tk to build with, that didn't work, so I downloaded the source and built them in msys (http://wiki.tcl.tk/14828).
The issue I am having is that I keep getting the same error when running the make file,
chrismeyer#MEYER-C /src/sim
$ make
(cd misc; make all)
make[1]: Entering directory /src/sim/misc'
make[1]: Nothing to be done forall'.
make[1]: Leaving directory /src/sim/misc'
(cd pipe; make all GUIMODE=-DHAS_GUI TKLIBS="-l /opt/tcl/lib" TKINC="-I /opt/tcl/include")
make[1]: Entering directory/src/sim/pipe'
Building the pipe-std.hcl version of PIPE
../misc/hcl2c -n pipe-std.hcl < pipe-std.hcl > pipe-std.c
gcc -Wall -O2 -I /opt/tcl/include -I../misc -DHAS_GUI -o psim psim.c pipe-std.c \
../misc/isa.c -l /opt/tcl/lib -lm
c:\minGW\bin..\lib\gcc\mingw32\3.4.5........\mingw32\bin\ld.exe: cannot find -lC:/msys/1.0/opt/tcl/lib
collect2: ld returned 1 exit status
make[1]: * [psim] Error 1
make[1]: Leaving directory `/src/sim/pipe'
Sorry about the formatting of the error, it got messed up a little bit.
The main problem is this line
C:\minGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\mingw32\bin\ld.exe: cannot find -lC:/msys/1.0/opt/tcl/lib
I am unsure why gcc cannot find the lib directory, it exists, I have checked many times.
Any insight into this issue would be very helpful!
Thanks!
After taking a short look at the Makefiles in the sim.tar distro i would say your variables are not setup properly.
Try the following settings in your Makefile:
TKLIB="-L/opt/tcl/lib -ltk -ltcl"
TKINC="-I/opt/tcl/include"
Depending on the exact libs you have you might need to add some version numbers like -ltcl85 or so, but try without first.

Resources