NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

Clean and Build message: BUILD FAILED (exit value 2, total time: 2s)

 
Post new topic   Reply to topic    NetBeans Forums -> C/C++ Users
View previous topic :: View next topic  
Author Message
mrcbsbr



Joined: 17 Jul 2017
Posts: 8
Location: Trujillo Alto, Puerto Rico

PostPosted: Thu Jul 20, 2017 1:12 am    Post subject: Clean and Build message: BUILD FAILED (exit value 2, total time: 2s) Reply with quote

I am having problems with a program in C language when performing a clean and build. I attached an MS Word file with the program and the results of the clean and build.

Additional details:
The process started with creating a new project under category C\C++ project C\C++ application with creating main file under C11. Proceed to create the new file category C, file type C source file. I already uninstalled and reinstalled MingGW and Netbeans. Any help will be appreciated.

Regards,

Marcobis



cleanbuild.txt
 Description:

Download
 Filename:  cleanbuild.txt
 Filesize:  3.19 KB
 Downloaded:  74 Time(s)

Back to top
soldatov



Joined: 05 Nov 2009
Posts: 604

PostPosted: Thu Jul 20, 2017 8:51 am    Post subject: Reply with quote

Compiler can't build 2 independent files with 'main()' functions (it is not a bug it is expected behavior):
Code:

C:\Users\Marcobis\Documents\NetBeansProjects\CppApplication_2/newfile.c:2: multiple definition of `main'^


Why you placed 2 that files into single project?
Back to top
mrcbsbr



Joined: 17 Jul 2017
Posts: 8
Location: Trujillo Alto, Puerto Rico

PostPosted: Thu Jul 20, 2017 1:09 pm    Post subject: Reply with quote

Thank you for your response. What I did was to follow the instructions for creating a new project and a new file to the project (C/C++ application and C source file). When I create a new project and if I uncheck the create main file, the program pass the clean and build but it does not put to screen what is in the printf when the program runs. I can enter the numbers and then the program will start running starting with the printf and I do not have to enter the numbers again and the program will give the appropriate result. If I follow this procedure and I just made a program with a puts function it will put the characters on screen.

If I leave the check mark on create main file during when I create the project and source file, the program will end up with a build failed message, no matter what.

If I go to Tools>Options>C/C++>Project Options and place C:\MinGW\msys\1.0\bin\make.exe in the make options box the program will clean and build but it will give an error if I try to run the program. The error message is C:\Users\Marcobis\Documents\NetbeansProjects\CppApplication_1\dist\Debug\MinGW-Windows\cppapplication_1 does not exist or is not an executable.

I downloaded the Code Blocks IDE and set it up with MinGW and I did not have any problems. I also try Eclipse Oxygen IDE but it did not work. I want to stay with Netbeans because I want to learn Java next.
Back to top
soldatov



Joined: 05 Nov 2009
Posts: 604

PostPosted: Thu Jul 20, 2017 1:48 pm    Post subject: Reply with quote

mrcbsbr wrote:
Thank you for your response. What I did was to follow the instructions for creating a new project and a new file to the project (C/C++ application and C source file). When I create a new project and if I uncheck the create main file, the program pass the clean and build but it does not put to screen what is in the printf when the program runs. I can enter the numbers and then the program will start running starting with the printf and I do not have to enter the numbers again and the program will give the appropriate result. If I follow this procedure and I just made a program with a puts function it will put the characters on screen.

If I leave the check mark on create main file during when I create the project and source file, the program will end up with a build failed message, no matter what.

Is it instruction from netbeans.org? In this case instruction must be updated. You see absolutely expected result. By default IDE compiles all C/C++/Fortran source files to *.o files. On latest step linker converts all *.o files to single executable file. In your case linker see 2 'main' files (files with 'main()'). Therefore linker fails and cppapplication_1.exe file doesn't appear. If you want to build executable file, then 1 of 2 'main' files should be deleted or excluded from build.

mrcbsbr wrote:

If I go to Tools>Options>C/C++>Project Options and place C:\MinGW\msys\1.0\bin\make.exe in the make options box the program will clean and build but it will give a error if I try to run the program. The error message is C:\Users\Marcobis\Documents\NetbeansProjects\CppApplication_1\dist\Debug\MinGW-Windows\cppapplication_1 does not exist or is not an executable.
Back to top
mrcbsbr



Joined: 17 Jul 2017
Posts: 8
Location: Trujillo Alto, Puerto Rico

PostPosted: Thu Jul 20, 2017 2:42 pm    Post subject: Reply with quote

Actually the instructions on the quick start guide for C\C++ just mention to click Next on the initial screen of creating a new project and then click Finish. It implies that everything should be left as default but there is a difference between unchecking and leaving the check mark for create main file. If I leave it checked I get both a source file and a main.c file in the project. If I unchecked the box of create main file then I do not have the main.c file in the project and the project will clean and build and the program will run but the printf instruction will not be executed until I entered the five numbers requested in the program. I do not need to enter the numbers again so it seems that the numbers are scanned (scanf). I attached the results of the clean and build and the run when I uncheck the create main file box when creating a C\C++ project.


uncheck_createmainfile.txt
 Description:

Download
 Filename:  uncheck_createmainfile.txt
 Filesize:  1.15 KB
 Downloaded:  61 Time(s)

Back to top
noyasystem



Joined: 30 Jun 2017
Posts: 0

PostPosted: Tue Jul 25, 2017 6:27 am    Post subject: Reply with quote

Could you provide some screen shots for the settings and actions you are doing during the project setup and creation?
Most probably there is something wrong in your settings and setup.

mrcbsbr wrote:
Thank you for your response. What I did was to follow the instructions for creating a new project and a new file to the project (C/C++ application and C source file). When I create a new project and if I uncheck the create main file, the program pass the clean and build but it does not put to screen what is in the printf when the program runs. I can enter the numbers and then the program will start running starting with the printf and I do not have to enter the numbers again and the program will give the appropriate result. If I follow this procedure and I just made a program with a puts function it will put the characters on screen.

If I leave the check mark on create main file during when I create the project and source file, the program will end up with a build failed message, no matter what.

If I go to Tools>Options>C/C++>Project Options and place C:\MinGW\msys\1.0\bin\make.exe in the make options box the program will clean and build but it will give an error if I try to run the program. The error message is C:\Users\Marcobis\Documents\NetbeansProjects\CppApplication_1\dist\Debug\MinGW-Windows\cppapplication_1 does not exist or is not an طراحی سایت executable.

I downloaded the Code Blocks IDE and set it up with MinGW and I did not have any problems. I also try Eclipse Oxygen IDE but it did not work. I want to stay with Netbeans because I want to learn Java next.
Back to top
mrcbsbr



Joined: 17 Jul 2017
Posts: 8
Location: Trujillo Alto, Puerto Rico

PostPosted: Tue Jul 25, 2017 12:26 pm    Post subject: Reply with quote

Thank you for your response. I attached a file with the screenshots of the process of creating a new project and a new file to the project.


screenshots.pdf
 Description:

Download
 Filename:  screenshots.pdf
 Filesize:  534.46 KB
 Downloaded:  75 Time(s)

Back to top
soldatov



Joined: 05 Nov 2009
Posts: 604

PostPosted: Tue Jul 25, 2017 1:05 pm    Post subject: Reply with quote

And again. Project can contain 1 'main' file only, because C/C++ compiler can't build 2 files with main() together.

Possible solutions:
1) You need to exclude first file from build (context menu on file > Properties > General > Exclude From Build = true)
2) Or use launchers: http://wiki.netbeans.org/NewAndNoteworthyNB82#C.2FC.2B.2B. In this case you can create your "Build" command
Back to top
mrcbsbr



Joined: 17 Jul 2017
Posts: 8
Location: Trujillo Alto, Puerto Rico

PostPosted: Tue Jul 25, 2017 1:29 pm    Post subject: Reply with quote

Thank you for your response. I attached a file with the results of the first solution you provided. The program will clean and build with no problems but it will stall on the run (on the printf, but if you enter the five numbers the program will start on the printf with no need to enter the numbers again (scanf read the nembers already) and the program will give the numbers in the appropiate order. Your first solution gives the same result when I uncheck the create main file box when creating a new project (it eliminates the main.c file from the source folder). I will attempt your second solution as soon as possible.


solution1results.pdf
 Description:

Download
 Filename:  solution1results.pdf
 Filesize:  168.19 KB
 Downloaded:  75 Time(s)

Back to top
soldatov



Joined: 05 Nov 2009
Posts: 604

PostPosted: Tue Jul 25, 2017 2:39 pm    Post subject: Reply with quote

mrcbsbr wrote:
Thank you for your response. I attached a file with the results of the first solution you provided. The program will clean and build with no problems but it will stall on the run (on the printf, but if you enter the five numbers the program will start on the printf with no need to enter the numbers again (scanf read the nembers already) and the program will give the numbers in the appropiate order. Your first solution gives the same result when I uncheck the create main file box when creating a new project (it eliminates the main.c file from the source folder). I will attempt your second solution as soon as possible.

If your uses MSYS or MSYS2 and your application requires some input, real Windows terminal better than internal Output tab. In Project Properties window you need to set Run|Console Type = External Terminal
Back to top
mrcbsbr



Joined: 17 Jul 2017
Posts: 8
Location: Trujillo Alto, Puerto Rico

PostPosted: Tue Jul 25, 2017 3:46 pm    Post subject: Reply with quote

Yes, I am using MSYS. Your third solution about making the run on an external console work both for your first solution about excluding the main.c file and the alternative of unchecking the create main file box during new project creation. Code:: Blocks default is an external console for run and that was what I was using. Now, I can go back to Netbeans. Thanks.

Regards,

Marcobis
Back to top
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> C/C++ Users All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo