I'm trying to compile this C++ code, but no luck. Using MinGW and Netbeans 7.4. The code doesn't make sense because I erased everything down to a minimum for failure analysis. The problem seems to be the line "#include ". When it's there, the project builds, but no .exe is created. If it's not there, the project builds and runs just fine.
Any ideas ? Btw, I read those other 'can't include
main.cpp
#include "xmessage.h"
using namespace std;
int main() {
xmessage();
return 0;
}
xmessage.cpp
#include <iostream> // What's wrooong with you, <iostream> !?!?
using namespace std;
void xmessage () {
int i = 1;
}
xmessage.h
#ifndef XMESSAGE_H
#define XMESSAGE_H
void xmessage ();
#endif /* XMESSAGE_H */
Also:
The files are .cpp, that's not it.
And if I remove the iostream file from the include folder
C:\MinGW\lib\gcc\mingw32\4.8.1\include\c++
the build fails. So that's definitely the file that is being used by the compiler.
Netbeans output:
"/C/MinGW/msys/1.0/bin/make.exe" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make.exe[1]: Entering directory `/c/Users/admin/Documents/NetBeansProjects
/project125(HeaderFileMacros) - WIP'
"/C/MinGW/msys/1.0/bin/make.exe" -f nbproject/Makefile-Debug.mk dist/Debug/MinGW-Windows
/project125_headerfilemacros__-_wip.exe
make.exe[2]: Entering directory `/c/Users/admin/Documents/NetBeansProjects
/project125(HeaderFileMacros) - WIP'
mkdir -p dist/Debug/MinGW-Windows
g++ -o dist/Debug/MinGW-Windows/project125_headerfilemacros__-_wip build/Debug/MinGW-Windows
/main.o build/Debug/MinGW-Windows/xmessage.o
make.exe[2]: Leaving directory `/c/Users/admin/Documents/NetBeansProjects
/project125(HeaderFileMacros) - WIP'
make.exe[1]: Leaving directory `/c/Users/admin/Documents/NetBeansProjects
/project125(HeaderFileMacros) - WIP'
BUILD SUCCESSFUL (total time: 4s)
Avast Antivir was in silent mode and it put every new .exe in quarantine without notifying me. That's why the .exe was instantly deleted after its creation.
Related
Let me start by saying that I am a Windows 8 user on a HP laptop.
So I very recently started an online course in c++ with 'c++ institute'. As recommended by them, I downloaded the MinGW/MSYS package, JDK and NetbBeans IDE version 8.0.2.
I followed their installation instructions exactly (including updating the path directory by adding ";C:\MinGW\bin;C:\MinGW\MSYS\1.0\bin")
I am now on chapter 3 of the program and everything was going ok until I tried to compile the following code (see below)
/*
* File: hello.cpp
*
* Created on 19 May 2015, 18:26
*/
#include <cstdlib>
#include <iostream>
#include <stdio.h>
int main(void) {
int exp;
int pow = 1;
for(exp = 0; exp < 16; exp++) {
printf("2 to the power of %d is %d\n",exp,pow);
pow = pow*2;
}
return 0;
}
For some reason when I try to compile and run the program I get the following error messages
"/C/MinGW/MSYS/1.0/bin/make.exe" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make.exe[1]: Entering directory `/c/Users/Philip/Desktop/C++ Course/Hello'
"/C/MinGW/MSYS/1.0/bin/make.exe" -f nbproject/Makefile-Debug.mk dist/Debug/MinGW-Windows/hello.exe
make.exe[2]: Entering directory `/c/Users/Philip/Desktop/C++ Course/Hello'
mkdir -p build/Debug/MinGW-Windows
rm -f "build/Debug/MinGW-Windows/hello.o.d"
g++ -c -g -MMD -MP -MF "build/Debug/MinGW-Windows/hello.o.d" -o build/Debug/MinGW-Windows/hello.o hello.cpp
mkdir -p dist/Debug/MinGW-Windows
g++ -o dist/Debug/MinGW-Windows/hello build/Debug/MinGW-Windows/hello.o
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: cannot open output file dist/Debug/MinGW-Windows/hello.exe: Permission denied
collect2.exe: error: ld returned 1 exit status
make.exe[2]: *** [dist/Debug/MinGW-Windows/hello.exe] Error 1
make.exe[2]: Leaving directory `/c/Users/Philip/Desktop/C++ Course/Hello'
make.exe[1]: *** [.build-conf] Error 2
make.exe[1]: Leaving directory `/c/Users/Philip/Desktop/C++ Course/Hello'
make.exe": *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 4s)
The code was copied and pasted directly from the course files and it seems to make sense to me. So can anybody tell me what I am doing wrong? Thanks in advance.
The relevant error message is
cannot open output file dist/Debug/MinGW-Windows/hello.exe: Permission denied
Which indicates you do not have write permission on the folder it's attempting to create hello.exe in. Make the dist/Debug/MinGW-Windows folder writable, and that error should be resolved.
https://netbeans.org/community/releases/80/cpp-setup-instructions.html#compilers_windows
Try by instructions given over here.
When I build my code in C++ using NetBeans.
"make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory '/cygdrive/c/Users/Alex/Documents/NetBeansProjects/test'
"make" -f nbproject/Makefile-Debug.mk dist/Debug/Cygwin_4.x-Windows/test.exe
make[2]: Entering directory '/cygdrive/c/Users/Alex/Documents/NetBeansProjects/test'
make[2]: 'dist/Debug/Cygwin_4.x-Windows/test.exe' is up to date.
make[2]: Leaving directory '/cygdrive/c/Users/Alex/Documents/NetBeansProjects/test'
make[1]: Leaving directory '/cygdrive/c/Users/Alex/Documents/NetBeansProjects/test'
BUILD SUCCESSFUL (total time: 652ms)
When I run my code in C++ using NetBeans...
Unable to start pty process:
RUN FAILED (exit value -2, total time: 26ms)
My Code
#include <iostream>
using namespace std;
int main(int argc, const char *argv[]) {
cout << "Hello, World!\n";
return 0;
}
Help appreciated!
Worked solution for me :
Netbeans : File-> Project properties -> Run -> Console type -> External Terminal
here's the corresponding Netbeans bug https://netbeans.org/bugzilla/show_bug.cgi?id=234221 People tell that the "use of external terminal" option may help
I've changed the run compiler under project properties - run from c++ (what it says actually) to g++. Plus the "external terminal" it worked.
PROBLEM SOLVED
Go to bottom to see the solution.
Hello everybody i've been googling' looooong time and I didn't find anythinig, so, here we go:
I have this setup:
Compiler: MinGW IDE: Netbeans Library: SDL Language:
C++
Okey, so, i have included this folder: "C:/SDL_1.2.15/include"
And Linked those libraries in this order:
-lmingw32
-lSDL_main
-lSDL
Then if I use a normal program without the #include "SDL/SDL.h" then compiles okeey.
So if i include the SDL header file the IDE gives me greenlight to compile an then, i get this output:
"C:/WinAVR-20090313/utils/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory `C:/Users/pablo/Documents/NetBeansProjects/SDL_Test'
"C:/WinAVR-20090313/utils/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/MinGW-Windows/sdl_test.exe
make[2]: Entering directory `C:/Users/pablo/Documents/NetBeansProjects/SDL_Test'
mkdir -p build/Debug/MinGW-Windows
rm -f build/Debug/MinGW-Windows/main.o.d
g++.exe -c -g -Wall -I/C/MinGW/include -I/C/SDL-1.2.15/include -MMD -MP -MF build/Debug/MinGW-Windows/main.o.d -o build/Debug/MinGW-Windows/main.o main.cpp
make[2]: Leaving directory `C:/Users/pablo/Documents/NetBeansProjects/SDL_Test'
make[1]: Leaving directory `C:/Users/pablo/Documents/NetBeansProjects/SDL_Test'
main.cpp:11:21: error fatal: SDL/SDL.h: No such file or directory
compilaci�n terminada.
make[2]: *** [build/Debug/MinGW-Windows/main.o] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 2s)
So! Here is the source code of my application, it only has a 'main.cpp' file:
/*
* File: main.cpp
* Author: pablo
*
* Created on 1 de septiembre de 2013, 23:20
*/
#include <cstdlib>
#include <windows.h>
#include <SDL/SDL.h>
using namespace std;
/*
*
*/
int main(int argc, char** argv) {
return 0;
}
I've found new issues; When I remove the #include (comment //) then the console throws me this errors instead the 'no such file or directory':
c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/bin/ld.exe: cannot find -lSDLmain
c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/bin/ld.exe: cannot find -lSDL.dll
When I compile without #include using Cygwin compiler, the project builds correctly.
Found another issue:
make[2]: *** No rule to make target `/C/SDL-1.2.15/lib/libSDLmain.a', needed by `dist/Debug/MinGW-Windows/sdl_test.exe'. Stop.
this happens when I add the full path to the SDL libraries instead of -lSDL.dll and -lSDL_main
SOLUTION:
The problem solves coping c:/SDL-1.15/include/SDL/ folder to c:/MinGW/include/ directory, and libraries from lib on c:/SDL-1.15/lib/SDL to MinGW/lib
You have to add the headers separately.
It's not enough to do the include, you have to do multiple things to add a thing like SDL in your project.
I'm trying to make a simple "Hello World!" program in NetBeans IDE 7.3 with MinGW as my C++ compiler.
I'm getting build failures and I'm at a loss as to understanding why.
This is my compiler setup:
Family: MinGW
Base Directory: C:\MinGW
C Compiler: C:\MinGW\bin\gcc.exe
C++ Compiler: C:\MinGW\bin\g++.exe
Assembler: C:\MinGW\bin\as.exe
Make Command: C:\MinGW\msys\1.0\bin\make.exe
Debugger Command: C:\MinGW\bin\gdb.exe
I've made sure to that my environment PATH directs to C:\MinGW\bin and C:\MinGW\msys\1.0\bin.
My code is:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World!" << endl;
return 0;
}
After trying to build the project, I recieve this message from the NetBeans debug output:
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory `/c/NetBeansProjects/HelloWorld'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/MinGW-Windows/helloworld.exe
make[2]: Entering directory `/c/NetBeansProjects/HelloWorld'
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
make[2]: g++: Command not found
make[2]: *** [build/Debug/MinGW-Windows/main.o] Error 127
make[2]: Leaving directory `/c/NetBeansProjects/HelloWorld'
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory `/c/NetBeansProjects/HelloWorld'
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 1s)
I've search various Q&A, but I seem to be doing everything correctly.
Right click on My Computer and select properties. Click Advanced System Settings.System Properties dialog box will open. click Environmental Variables. Edit PATH variable and add C:\MinGW\msys\1.0\bin
Your settings on netbeans shoud be as follows
Base Directory: C:\MinGW\bin
C Compiler: C:\MinGW\bin\gcc.exe
C++ Compiler: C:\MinGW\bin\g++.exe
Fortran Compiler: C:\MinGW\bin\gfortran.exe
Assembler: C:\MinGW\bin\as.exe
Make Command: C:\MinGW\msys\1.0\bin\make.exe
Debbuger Command: C:\MinGW\bin\gdb.exe
Add these to your Environment variables
C:\MinGW\bin and C:\MinGW\msys\1.0\bin
This can happen if you have set the settings on netbeans before/during the time of installing MINGW and setting the environment PATH.
Just restart netbeans
you download mysys form mingw or sourceforge.net after install it, path is C:\Mysys\1.0\bin\make.exe to give the path into make compiler in netbean ide.
I have some problems linking to GLFW in Netbeans, I have followed the instructions here:
http://forums.netbeans.org/topic51143.html
I have installed Cygwin and MinGW on my computer, I had since earlier an installation of Cygwin, which I tried to use to compile a GLFW program, but I got the same error, so I decided to try MinGW, as per the instructions, still the same problem.
Also, for some reason I can't use msys make.exe as make command, even for compiling a C++ hello world, I have to use the one in Cygwin instead. I have set up windows Path variable to include the locations of both the msys bin directories.
"1) What must be installed (dlls, etc)?
glfw.dll
libgcc_s_dw2-1.dll
libstdc++-6.dll"
I am not sure what this means, does installed in this instance mean that System32/SysWOW64 should contain those mentioned .dlls?
My output for this program (using linker properties as specified here :
http://forums.netbeans.org/topic51143.html)
#include <cstdlib>
#include <stdio.h>
#include <GL/glfw.h>
using namespace std;
int main(int argc, char** argv) {
if (!glfwInit())
return -1;
return 0;
}
Yields:
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory /cygdrive/c/Users/sysdba/Documents/NetBeansProjects/GLFW'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/MinGW_QT-Windows/glfw.exe
make[2]: Entering directory/cygdrive/c/Users/sysdba/Documents/NetBeansProjects/GLFW'
mkdir -p build/Debug/MinGW_QT-Windows
rm -f build/Debug/MinGW_QT-Windows/main.o.d
g++.exe -lglfwdll -DGLFW_DLL -c -g -Wall -I../../../Downloads/glfw-2.7.7.bin.WIN64/glfw-2.7.7.bin.WIN64/lib-mingw -MMD -MP -MF build/Debug/MinGW_QT-Windows/main.o.d -o build/Debug/MinGW_QT-Windows/main.o main.cpp
g++: -lglfwdll: linker input file unused because linking not done
mkdir -p dist/Debug/MinGW_QT-Windows
g++.exe -lglfwdll -DGLFW_DLL -o dist/Debug/MinGW_QT-Windows/glfw build/Debug/MinGW_QT-Windows/main.o -L../../../../../MinGW/lib -lglfw -lglu32 -lopengl32 -lglfwdll
nbproject/Makefile-Debug.mk:62: recipe for target dist/Debug/MinGW_QT-Windows/glfw.exe' failed
make[2]: Leaving directory/cygdrive/c/Users/sysdba/Documents/NetBeansProjects/GLFW'
nbproject/Makefile-Debug.mk:59: recipe for target .build-conf' failed
make[1]: Leaving directory/cygdrive/c/Users/sysdba/Documents/NetBeansProjects/GLFW'
nbproject/Makefile-impl.mk:39: recipe for target .build-impl' failed
build/Debug/MinGW_QT-Windows/main.o: In functionmain':
/cygdrive/c/Users/sysdba/Documents/NetBeansProjects/GLFW/main.cpp:20: undefined reference to `_imp_glfwInit#0'
collect2: ld returned 1 exit status
make[2]: * [dist/Debug/MinGW_QT-Windows/glfw.exe] Error 1
Any idea of what the problem could be? Could it be related to the fact that I am not using the msys make.exe as make command?
I fixed my MinGW install, so I could use the make.exe in the MinGW msys, instead of the cygwin mysys, did not help.
Not much of an answer, but it seems to be a problem with GLFW somewhere, could not get it to work. I switched to freeglut, Worked like a charm, without any hassle.